//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

////cout<<*X.find_by_order(1)<<endl;
////cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//int,
//null_type,
//less< int >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
//LL X[4]={0,0,-1,1};
//LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 3e5+70;

int X[mx],V[mx];
vii arr;

struct node{
    LL cnt=0,sum=0;
    node(){}
    node(LL x,LL y){cnt=x,sum=0;}
};
node tree[4*mx];
void build(int idx,int b,int e){
    cnd = node(0,0);
    if(b!=e){
        build(lnd);build(rnd);
    }
}

int glob = 0;
inline void update(int idx,int b,int e,int pos,LL v){
//    if(glob>20)return;
//    glob++;
//    cout<<idx<<" "<<b<<" "<<e<<" "<<pos<<" "<<v<<endl;
    if(b==e && b==pos){
        cnd.cnt++;
        cnd.sum += v;
        return;
    }
    int mid = (b+e)>>1;
    if( pos<=mid )update(lnd,pos,v);
    else update(rnd,pos,v);
    cnd.cnt = lc.cnt+rc.cnt;
    cnd.sum = lc.sum+rc.sum;
}
inline pll query(int idx,int b,int e,int l,int r){
    if(l>e || r<b)return pll(0,0);
    if(l<=b && r>=e)return pll(cnd.sum,cnd.cnt);
    pll a = query(lnd,l,r);
    pll bb = query(rnd,l,r);
    a.first+=bb.first;
    a.second+=bb.second;
    return a;
}


vll pos,neg;
bool cmp(pll x,pll y){
    return x.first > x.first;
}
inline LL calc(vector<pll> &points,bool rev=0){

    if(points.size() < 2)return 0;

    map<LL,LL> mp;
    vl ar;
    for(pll x:points)ar.pb(x.second);
    sort(ALL(ar));
    LL cnt = 0;
    for(LL x:ar)if( mp.find(x)==mp.end() ){
        mp[x] = ++cnt;
    }
    if(!rev)sort(ALL(points));
    else sort(ALL(points),cmp);
    int N = cnt+1;
    build(1,1,N);
    LL tot = 0;

    for(pll x:points){
        LL v = x.second;
        LL id = mp[v];
        LL s = x.first;
        pll res = query(1,1,N,1,id);
        LL cur = abs(x.first*res.second - res.first);
        tot += cur;
        update(1,1,N,id,x.first);
    }

    return tot;
}


int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t,n,m;

    si(n);
    FOR(i,n)si(X[i]);
    FOR(i,n)si(V[i]);
    FOR(i,n)arr.pb( pii(X[i],V[i]) );

    sort(ALL(arr));
    LL inv = 0;
    LL sum = 0;
    LL cnt = 0;
    for(int i=n-1;i>=0;i--){
        if( arr[i].S<0 ){
            LL cur = sum - cnt*arr[i].F;
            inv += cur;
        }
        else{
            cnt++;
            sum += arr[i].F;
        }
    }

    for(pii x:arr){
        if( x.S < 0 )neg.pb(pll( x.F,-x.S ));
        else pos.pb(pll( x.F,x.S ));
    }

    LL ans = calc(pos);
    LL ans2 = calc(neg,1);

    LL res = ans+ans2+inv;
    pf("%lld\n",res);

    return 0;
}
