//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// #define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(8e5) + 999;
#define int long long int

vector<pii>x,y;
int n;

int t[N];


void build(int a[], 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 pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = t[v*2] + t[v*2+1];
    }
}



int32_t main(){
    IOS;
    
    cin>>n;
    x.resize(n);
    
    vector<int> v;
    int a[n]={0};
    memset(a,0,sizeof a);

    for(int i=0;i<n;i++)
    	cin>>x[i].ff;
    for(int i=0;i<n;i++)
    	cin>>x[i].ss;
    
    sort(x.begin(),x.end());

    for(int i=0;i<n;i++){
    	y.pb({x[i].ss,x[i].ff});
    	v.pb(x[i].ss);
    }

    sort(y.begin(),y.end());
	for(int i=0;i<n;i++){
		v[i]=y[i].ff;    
		cout<<y[i].ff<<" "<<y[i].ss<<endl;
	}
    
    map<pair<int,int>,int> mp;

    for(int i=0;i<n;i++){
    	mp[y[i]]=i;
    }

    for(int i=0;i<n;i++) a[i]=y[i].ss;

    build(a,1,0,n-1);

    

	ordered_set<int> ost;
    int ans = 0;
    
    for(int i=0;i<n-1;i++)
    {	
    	
    	int index = mp[{x[i].ss,x[i].ff}];
		update(1, 0, n-1, index, 0);
    	int num = ost.order_of_key(x[i].ss);
    	// cout<<"num is "<<num<<endl;
    	int up = lower_bound(v.begin(),v.end(),x[i].ss)-v.begin();
    	// cerr<<"up is "<<up<<endl;
    	int sp = sum(1,0,n-1,up,n-1);
    	ans=ans+(sp-(n-up-1-(ost.size()-num))*x[i].ff);
    	// cout<<"sp is "<<sp<<endl;
    	// cout<<"sum is "<<ans<<endl;
    	ost.insert(x[i].ss);

    }
    // cout<<endl<<"adf ";
    cout<<ans<<endl;
    return 0;
}