#include<bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("buy.in");
ofstream fout("buy.out");
auto mread = [](){
int x;
fin >> x;
return x;
};
const int N = 1e5 + 5;
int n = mread(), a[N], b[N];
signed main(){
for(int i = 1; i <= n; i ++)
a[i] = mread();
for(int i = 1; i <= n; i ++)
b[i] = mread();
priority_queue<int, vector<int>, greater<int> > q;
int ans = 0;
for(int i = 1; i <= n; i ++){
q.push(a[i]);
if(b[i] > q.top()){
int tmp = b[i] - q.top();
q.pop();
ans += tmp;
q.push(b[i]);
}
}
fout << ans;
return 0;
}