///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           M                           100009
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           bug(i)                      cout<<"akhane ami  "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;

pi a[2*M+2];

int  bit[2*M+2][3];
map<int,int>id;
int rol=1;

///set a[idx]+=val;
void update(int idx,int  val,int typ)
{
    while(idx < M){
        bit[idx][typ] += val;
        idx += (idx&-idx);
    }
}
///returns the prefix sum from 0 to idx
int  qry(int idx,int typ)
{
    int  ret = 0;
    while(idx > 0){
        ret += bit[idx][typ];
        idx -= (idx&-idx);
    }
    return ret;
}
vector<int>vec;
 main()
{   fast
    int n;
    cin>>n;
    f(i,1,n)
    {
        cin>>a[i].fi;

    }
     f(i,1,n)
    {
        cin>>a[i].si;
         vec.pb(a[i].si);
    }
    sort(vec.begin(),vec.end());
    int sz=vec.size();
    for(int i=0;i<sz;i++)
    {
        id[vec[i]]=rol++;
    }
   sort(a+1,a+n+1);
   int ses=0LL;
   for(int i=1;i<=n;i++)
   {

       int val=a[i].si;
       int cnt=qry(id[val],0);
       int tmp=cnt*a[i].fi;
       val=qry(id[val],1);
       tmp=tmp-val;
       ses+=tmp;
       //cout<<id[val]<<"v"<<endl;
       update(id[a[i].si],a[i].fi,1LL);
       update(id[a[i].si],1LL,0LL);
       //bug(9)
   }
 cout<<ses<<endl;









































return 0;

}


