#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef map<int,PII>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 
//int root(int x){return x==f[x]?x:f[x]=root(f[x]);}
MII t;
/*void build( int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = t[v*2] + t[v*2+1];
    }
}

int sum(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return sum(v*2, tl, tm, l, min(r, tm))
           + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
}
*/
void update(int v, int tl, int tr, int l, int r, int add,int r1) {
    if (l > r)
        return;
    if (l == tl && r == tr) {
        t[v].FI += add,t[v].SE+=r1;
    } else {
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), add,(int)r1);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, add,(int)r1);
    }
}
PII get(int v, int tl, int tr, int pos) {
    if (tl == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      {PII hp=get(v*2, tl, tm, pos);return {t[v].FI + hp.FI,t[v].SE +hp.SE};}
    else
     {PII hp=get(v*2+1, tm+1, tr, pos);   return {t[v].FI + hp.FI,t[v].SE + hp.SE};}
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
 int n;
 cin>>n;int ans=0;vector<PII>ar(n);
 for(int i=0;i<n;i++)
 {
     cin>>ar[i].FI;
 }
 
 for(int i=0;i<n;i++)
 {
     cin>>ar[i].SE;ar[i].SE+=100000000;
     update(1,0,200000002,ar[i].SE,200000002,ar[i].FI,(int)1);
 }
 sort(all(ar));
 int sum1=0;
 for(int i=0;i<n;i++)
 {    sum1+=ar[i].FI;
     PII x=get(1,0,200000002,ar[i].SE-1);
     //cout<<x.FI<<" "<<x.SE<<" ";
     x.FI=(n*(n+1))/2-sum1-x.FI;x.SE=n-i-1-x.SE;
     //cout<<x.FI-ar[i].FI*x.SE<<endl;
     ans+=max((int)0,x.FI-ar[i].FI*x.SE);
    
     update(1,0,200000002,ar[i].SE,200000002,-ar[i].FI,(int)-1);
 }
 cout<<ans<<endl;
 
}


return 0;
}



