#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],b[100005],sum,t=1;
struct node{
long long v,tim;
}c[100005];
bool cmp(node x,node y){
if (x.v==y.v) return x.tim<y.tim;
return x.v>y.v;
}
int main(){
freopen("buy.in","r",stdin);
freopen("buy.out","w",stdout);
scanf("%d",&n);
for (long long i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for (long long i=1;i<=n;i++){
scanf("%d",&b[i]);
c[i].v=b[i];
c[i].tim=i;
}
sort(c+1,c+1+n,cmp);
for (long long i=1;i<=n;i++){
sort(a+1,a+1+c[t].tim);
if (c[t].v-a[1]>=0) sum+=c[t].v-a[1];
a[1]=LONG_LONG_MAX;
t++;
}
printf("%d",sum);
return 0;
}