#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int i,n;
long long ans = 0;
pair<long long,int> place[N];

struct FenwickTree
{
private :
    vector<long long> v;
    int n;

public:
    FenwickTree(int n)
    {
        this->n=n;
        int runner;
        for(runner=0;runner<n;runner++)
            v.push_back(0);
    }

    void add(int index, long long a)
    {
        for(; index<n; index = index | (index+1))
            v[index]+=a;
    }

    long long sum(int r)
    {
        long long cur = 0;
        for(; r>=0; r=(r&(r+1))-1)
            cur+=v[r];
        return cur;
    }

    long long sumRange(int l, int r)
    {
        return sum(r)-sum(l-1);
    }
};

struct trip{
    long long a,b,c;
     bool operator < (trip k)
     {
         if(a < k.a)
            return true;
         else if(a > k.a)
            return false;
         else if(b < k.b)
            return true;
         else if(b > k.b)
            return false;
         else if(c <= k.c)
            return true;
         else
            return false;
     }
};
trip speed[N];

int main()
{
    cin>>n;
    for(i=0; i<n; i++)
    {
        int a;
        cin>>a;
        place[i] = {a,i};
    }
    map<int,int> mp;
    map<int,int> qp;
    for(i=0; i<n; i++)
    {
        int a;
        cin>>a;
        speed[i] = {a,place[i].first,i};
    }
    sort(place,place+n);
    for(i=0; i<n; i++)
        mp.insert({i,place[i].second});
    sort(speed,speed+n);
    for(i=0; i<n; i++)
        qp.insert({speed[i].a,i});
    FenwickTree speedTree(n);
    FenwickTree placeTree(n);
    for(i=0; i<n; i++)
    {
        int node = mp[i];
        int pl = qp[node];
        speedTree.add(pl,place[i].first);
        placeTree.add(pl,1);
        ans += (placeTree.sumRange(0,pl))*place[i].first - speedTree.sumRange(0,pl);
    }
    cout<<ans;
    return 0;
}
