#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace __gnu_pbds;
#define ordered_set tree<pair<long,long>, null_type,less<pair<long,long>>, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order(k): It returns to an iterator to the kth element (counting from zero) in the set
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
#define pb push_back
#define f first
#define s second
#define F(i,a,b) for(i=a;i<b;i++)
#define nl   "\n"
#define sp   " " 
#define all(c) (c).begin(),(c).end()
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long double ld;
typedef long long   ll;
typedef vector<ll>  vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
#define rev(i,b,a) for(int i=b;i>=a;i--)
#define iota  cout<<-1<<nl
#define cty  cout<<"YES"<<nl
#define ctn   cout<<"NO"<<nl
#define lmax  LLONG_MAX
#define lmin  LLONG_MIN
#define csp(x) cout<<(x)<<" "
#define c1(x)  cout<<(x)<<nl
#define c2(x,y) cout<<(x)<<" "<<(y)<<nl
#define c3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<nl
#define c4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<nl
#define c5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<nl
#define c6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<nl
#define c(x) cout<<(x)
#define sz(v) (v).size()
#define deci(n) fixed<<setprecision(n)
const int mod=1e9+7;
const double pi=3.14159265358979323846264338327950288419716939937510582097494459230;
// priority_queue<t>
auto zzz= clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void time_taken()
{
#ifdef local
    cout << endl;
    cout << "Time Taken: " << (double)(clock() - zzz) / CLOCKS_PER_SEC << endl;
#endif
    return;
}
 
ll poww(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a);
		a=(a*a);
		b>>=1;
	}
	return res;
}
 ll madd(ll a, ll b, ll m = mod)
{
    a%=m;
    b%=m;
    a += b;
    if (a >= m)
        a -= m;
    return a;
}
 
 ll mmul(ll a, ll b, ll m = mod)
{
    return ((a % m) * (b % m)) % m;
}
ll modI(ll a, ll m=mod)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
ll powm(ll a, ll b,ll m=mod) {
	ll res=1;
    	while(b) {
		if(b&1)
			res=(res*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return res;
}
//*******************************************************************************************************************************************//
void solve()
{ ll i,j,x=0,y,ans=0,n,m,d,cnt=0,z,c=2;
cin>>n;
 vpll v(n);
 F(i,0,n)
     cin>>v[i].f;
 F(i,0,n)cin>>v[i].s;
 sort(all(v));
 ordered_set s;
 for(i=n-1;i>=0;i--)
 {
     d=s.order_of_key(make_pair(v[i].s,(ll)-1));
     d=s.size()-d;
     ans+=-1*(v[i].f)*d;
     s.insert(make_pair(v[i].s,v[i].f));
     
 }
 s.clear();
 F(i,0,n)
 {
     d=s.order_of_key(make_pair(v[i].s,lmax));
  
     ans+=(v[i].f)*d;
     s.insert(make_pair(v[i].s,v[i].f));

 }
 c1(ans);
 
 
};
int main()
{fast;
    int t;
t=1;
//cin >>t;
 while(t--)
     solve();
}
