#include <bits/stdc++.h>
using namespace std;

long long process1(vector<pair<int,int> >&arr){
    long long sum[arr.size()+5]={};
    long long positiveCount[arr.size()+5]={};

    for(int i=arr.size()-1;i>=0;i--){
        if(arr[i].second>=0){
            positiveCount[i]=1;
            sum[i]=arr[i].first;
        }

        sum[i]+=sum[i+1];
        positiveCount[i]+=positiveCount[i+1];
    }

    long long ret=0;
    for(int i=0;i<arr.size();i++){
        if(arr[i].second<0){
            long long left=(long long)arr[i].first*positiveCount[i];
            long long right=sum[i];

            ret+=right-left;
        }
    }

    return ret;
}


long long query(int idx,map<int,long long>&tree){
    long long ret=0;
    while(idx){
        ret+=tree[idx];
        idx-=idx&(-idx);
    }
    return ret;
}

void update(int idx,int val,map<int,long long>&tree){
    while(idx<=(int)1e8+50){
        tree[idx]+=val;
        idx+=idx&(-idx);
    }
}

long long process2(vector<pair<int,int> >&arr){

    map<int,long long>treeCnt;
    map<int,long long>treeSum;
    

    long long ret=0;
    for(int i=0;i<arr.size();i++){
        long long val=arr[i].first;
        long long height=arr[i].second;

        ret+=val*query(height,treeCnt)-query(height,treeSum);

        update(height,1LL,treeCnt);
        update(height,val,treeSum);
    }
    return ret;
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    int n;
    while(1==scanf("%d",&n)){

        vector<pair<int,int> >arr(n);

        for(int i=0;i<n;i++)scanf("%d",&arr[i].first);
        for(int i=0;i<n;i++)scanf("%d",&arr[i].second);

        sort(arr.begin(),arr.end());

        vector<pair<int,int> >pos,neg;

        for(int i=0;i<n;i++){
            if(arr[i].second<0)neg.push_back({arr[i].first,-arr[i].second});
            else pos.push_back({arr[i].first,arr[i].second+1});
        }

        long long res=0;

        res+=process1(arr);

        res+=process2(pos);
        res+=process2(neg);

        printf("%lld\n",res);

    }

    return 0;
}
