#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#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 int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i,n,v[N],bit[N],val=1,ans=0;
vpii x;

void update(int idx,int val)
{
    while(idx<=n)
    {
        bit[idx]+=val;
        idx+=idx&-idx;
    }
}
 
int query(int idx)
{
    int ans=0;
    while(idx>0)
    {
        ans+=bit[idx];
        idx-=idx&-idx;
    }
    return ans;
}
 
int rsum(int l,int r)
{
    return query(r)-query(l-1);
}

void solve()
{
    cin>>n;
    vi compress;
    for(i=1;i<=n;++i)
    {
        int a;
        cin>>a;
        x.pb({a,i});
    }
    sort(all(x));
    for(i=1;i<=n;++i)
    {
        cin>>v[i];
        compress.pb(v[i]);
    }
    sort(all(compress));
    map<int,int> mp;
    mp[compress[0]]=1;
    for(i=1;i<n;++i)
    {
        if(compress[i]!=compress[i-1])
            val++;
        mp[compress[i]]=val;
    }
    oset s;
    for(i=n-1;i>=0;--i)
    {
        int idx=x[i].s;
        int sum=rsum(mp[v[idx]],n);
        int bigger=n-1-i-s.order_of_key(mp[v[idx]]);
        ans+=sum-bigger*x[i].f;
        s.insert(mp[v[idx]]);
        update(mp[v[idx]],x[i].f);
    }
    cout<<ans;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}