#include<bits/stdc++.h>

/*#include<iostream>
#include<vector>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
*/
//using namespace __gnu_pbds;

#define PB push_back
using namespace std;
#define N 400000;
#define loop(i , x , n) for(ll i = x;i< n;i++)
#define loopr(i , x , n) for(ll i = n;i>=x ;i--)
#define mod 998244353
#define ll long long
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair<long long , long long >(x, y)
#define SIN(x) sin(x * 3.141592653589793238)
#define COS(x) cos(x * 3.141592653589793238)
#define endl "\n"
#define ff first
#define ss second
#define ELGO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc ll tc; cin>>tc; while(tc--)
#define vv(x) vector<x>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof  pop_front
#define endl "\n"
#define umap unordered_map
//#define pq priority_queue
#define ca(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ca1(a,n) for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define svec(x) sort(x.begin(), x.end())
#define rsvec(x) sort(x.begin(), x.end(), greater<ll>())
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
void update( vv(ll)&v, ll ind , ll val  ){
    ind++;
    ll n = v.size();
    while( ind<= n ){
        v[ind]+= val ;
        ind+= ((ind)&(-ind));

    }

}
ll query( vv(ll)&v , ll ind ){
ind++;
ll res = 0;
    while(ind>0){
        res+= v[ind];
        ind-= ((ind)&(-ind));
    }
    return res;
}


void solve() {


 ll n ;
 cin>> n;

 vector<pair<ll, ll>>points(n);
 loop(i, 0, n ) cin>> points[i].ff;
//cout<<"YO"<<endl;
 vv(ll)vel;

 loop(i,0, n ) {
 cin>>points[i].ss;
 vel.pb(points[i].ss);
 }
 sort( all(vel));
 sort( all(points));
 //cout<<"PO"<<endl;
 vel.resize(unique(all(vel)) - vel.begin());  // coordinate compression
loop(i,0, vel.size()) cout<< vel[i]<< " " ;
 vv(ll) no(vel.size()+1, 0) , csum(vel.size()+1, 0);
 //cout<<"PO"<<endl;
 ll ans = 0 ;
 loop(i,0, n ) {
    ll v_new = lower_bound(vel.begin(), vel.end(), points[i].ss) - vel.begin();
    //watch(v_new);
    ans+= -( query(csum,v_new )) + ( points[i].ff * query(no, v_new));
    update(csum, v_new , points[i].ff);
    update(no, v_new, 1);


 }
 //cout<<"FO"<<endl;
 cout<<ans<<endl;


}





int main()
{
    ELGO;
//tc{
solve();
//}




}
