#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long  segmentTree[1<<20];
int segmentTree2[1<<20];
long long  getSum(int node , int start , int en , int startOfInterval , int endOfInterval){
    if(startOfInterval<=start&&endOfInterval>=en){
        return segmentTree[node];
    }
    if(en<startOfInterval||start>endOfInterval) return 0;
    int mid=(start+en)/2;
    return getSum(node*2,start,mid,startOfInterval,endOfInterval)+getSum(node*2+1,mid+1,en,startOfInterval,endOfInterval);
}
void insert(int node , int start, int en, int index , int value){
    if(en<index||start>index) return ;
    int mid=(start+en)/2;
    segmentTree[node]+=value;
    if(start==en)return;
    insert(node*2,start,mid,index,value);
    insert(node*2+1,mid+1,en,index,value);
}


int getSum2(int node , int start , int en , int startOfInterval , int endOfInterval){
    if(startOfInterval<=start&&endOfInterval>=en){
        return segmentTree2[node];
    }
    if(en<startOfInterval||start>endOfInterval) return 0;
    int mid=(start+en)/2;
    return getSum2(node*2,start,mid,startOfInterval,endOfInterval)+getSum2(node*2+1,mid+1,en,startOfInterval,endOfInterval);
}
void insert2(int node , int start, int en, int index){
    if(en<index||start>index) return ;
    if(start==index&&start==en){
        segmentTree2[node]++;
        return;
    }
    int mid=(start+en)/2;
    if(start==en)return;
    insert2(node*2,start,mid,index);
    insert2(node*2+1,mid+1,en,index);
    segmentTree2[node]=segmentTree2[node*2]+segmentTree2[node*2+1];
}
map<int , int> composedIndex;
int main() {
    int n ;
    cin>>n ;
    priority_queue <int, vector<int>, greater<> > pq;
    pair<int , int>indexAndSpeed[n+2];
    for(int i= 0 ; i < n ; i++){
        cin>>indexAndSpeed[i].first;
    }
    for(int i= 0 ; i < n ; i++){
        cin>>indexAndSpeed[i].second;
        pq.push(indexAndSpeed[i].second);
    }
    int L =INT_MIN;
    int num=1;
    while (pq.size()){
        int op=pq.top();
        pq.pop();
        if(op==L)continue;
        L=op;
        composedIndex.insert(make_pair(op,num++));
    }
    sort(indexAndSpeed,indexAndSpeed+n);
    long long  ans = 0 ;
    for(int i = 0 ; i < n ; i++){
        int num = getSum(1,1,n,1,composedIndex[indexAndSpeed[i].second]);
        int elements=getSum2(1,1,n,1,composedIndex[indexAndSpeed[i].second]);
        ans+=(elements*indexAndSpeed[i].first)-num;
        insert(1,1,n,composedIndex[indexAndSpeed[i].second],indexAndSpeed[i].first);
        insert2(1,1,n,composedIndex[indexAndSpeed[i].second]);
    }
    cout<<ans<<endl;
    return 0;
}