#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const int MAXN = 200005;


struct Node{
    LL x, y;
    int id;
    LL ans;
    bool operator<(const Node& a){
        return x<a.x;
    }
}D[MAXN], t[MAXN];

LL n, T1[MAXN], T2[MAXN];

inline int lowbit(int x){return x&-x;}
inline void add1(int x,LL val){while(x<=n){T1[x]+=1;T2[x]+=val;x+=lowbit(x);}}
inline void add2(int x,LL val){while(x<=n){T1[x]-=1;T2[x]+=val;x+=lowbit(x);}}
inline LL sum1(int x){LL res=0;while(x>0)res+=T1[x],x-=lowbit(x);return res;}
inline LL sum2(int x){LL res=0;while(x>0)res+=T2[x],x-=lowbit(x);return res;}

void CDQ(int l, int r){
    if(l>=r)return;
    //cout<<l<<" "<<r<<endl;
    int mid=l+r>>1;
    CDQ(l,mid);
    CDQ(mid+1,r);

    int t1=l,t2=mid+1;
    int j=l-1;

    while(t1<=mid&&t2<=r){
        if(D[t1].y<=D[t2].y){
            t[++j]=D[t1];
            add1(D[t1].id,D[t1].x);
            ++t1;
        }else{
            t[++j]=D[t2];
            t[j].ans+=sum1(D[t2].id)*D[t2].x-sum2(D[t2].id);
            ++t2;
        }
    }

    while(t1<=mid){
        t[++j]=D[t1];
        add1(D[t1].id,D[t1].x);
        ++t1;
    }

    while(t2<=r){
        t[++j]=D[t2];
        t[j].ans+=sum1(D[t2].id)*D[t2].x-sum2(D[t2].id);
        ++t2;
    }

    for(int i=l;i<=r;++i)D[i]=t[i];
    for(int i=l;i<=mid;++i){
        add2(D[i].id,-D[i].x);
    }
    return;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;++i) cin>>D[i].x;
    for(int i=1;i<=n;++i){
        cin>>D[i].y;
        D[i].ans=0;
    }

    sort(D+1,D+n+1);
    for(int i=1;i<=n;++i)D[i].id=i;

    CDQ(1,n);

    LL res=0;
    for(int i=1;i<=n;++i)res+=D[i].ans;

    cout<<res<<endl;
    return 0;
}


/*
5
2 1 4 3 5
2 2 2 3 4

19
*/
