#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
// 按照pos属性从左到右排，每次考虑的是速度大的个数，以及他们的坐标总和

#define ll long long int
const ll N = 2e5+5;
struct node{
	ll v,p;
	friend bool operator <(node a,node b){return a.p < b.p;}
};
node a[N];
ll C[N][2],n;
ll getsum(ll x,ll w){
	ll re = 0;
	while(x != 0){
		re += C[x][w];
		x -= x&(-x);
	}
	return re;
}
void insert(ll x,ll y){
	while(x <= n){
		C[x][0] ++ ;
		C[x][1] += y;
		x += x&(-x);
	}
}
set<ll>S;  map<ll,ll>M;  ll mc = 0;
int main(){
	scanf("%d",&n);
	for(ll i=0;i<n;i++) scanf("%lld",&a[i].p);
	for(ll i=0;i<n;i++) {scanf("%lld",&a[i].v);S.insert(a[i].v);}
	for(set<ll>::iterator it=S.begin();it!=S.end();it++) M[*it] = ++mc;
	for(ll i=0;i<n;i++) a[i].v = M[a[i].v];
	sort(a,a+n);
	ll ans = 0;
	for(ll i=0;i<n;i++){
		ll c = getsum(a[i].v,0);
		ll s = getsum(a[i].v,1);
		ans += c*a[i].p - s;
		insert(a[i].v,a[i].p);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ft first
#define sd second
using namespace std;

const int N=2e5+10;
int s[2][N*4];

void u1(int t,int nd,int l,int r,int p,ll v){
    if(r<l || p<l || p>r) return;
    if(l==r){
        s[t][nd]+=v; return;
    }
    int mi=(l+r)/2;
    u1(t,nd*2,l,mi,p,v);
    u1(t,nd*2+1,mi+1,r,p,v);
    s[t][nd]=s[t][nd*2]+s[t][nd*2+1];
}

ll q1(int t,int nd,int l,int r,int ql,int qr){
    if(ql>r || qr<l || l>r) return 0;
    if(ql<=l && qr>=r) return s[t][nd];
    int mi=(l+r)/2;
    return q1(t,nd*2,l,mi,ql,qr)+q1(t,nd*2+1,mi+1,r,ql,qr);
}

int main()
{
    int n; cin>>n; vector<pair<int,int> > v(n); ll b[n];   memset(s,0,sizeof(s));
    for(int i=0;i<n;i++) cin>>v[i].ft;
    for(int i=0;i<n;i++) cin>>v[i].sd,b[i]=v[i].sd;
    sort(v.begin(),v.end()); sort(b,b+n);

    map<ll,int> ds;

    int s=1;
    for(int i=0;i<n;i++){
        if(ds[b[i]]==0) ds[b[i]]=s++;
    }
    ll res=0;
    for(int i=0;i<n;i+=1){
        ll x=v[i].ft, y=v[i].sd,p=ds[v[i].sd];
        res+=q1(0,1,1,N,1,p)*x-q1(1,1,1,N,1,p);
        u1(0,1,1,N,p,1); u1(1,1,1,N,p,x);
    }
    cout<<res;
}


#include <bits/stdc++.h>
#define ll long long
#define ft first
#define sd second
using namespace std;

const int N=2e5+10;
int s[2][N*4];

void u1(int t,int nd,int l,int r,int p,ll v){
    if(r<l || p<l || p>r) return;
    if(l==r){
        s[t][nd]+=v; return;
    }
    int mi=(l+r)/2;
    u1(t,nd*2,l,mi,p,v);
    u1(t,nd*2+1,mi+1,r,p,v);
    s[t][nd]=s[t][nd*2]+s[t][nd*2+1];
}

ll q1(int t,int nd,int l,int r,int ql,int qr){
    if(ql>r || qr<l || l>r) return 0;
    if(ql<=l && qr>=r) return s[t][nd];
    int mi=(l+r)/2;
    return q1(t,nd*2,l,mi,ql,qr)+q1(t,nd*2+1,mi+1,r,ql,qr);
}

int main()
{
    int n; cin>>n; vector<pair<int,int> > v(n); ll b[n];   memset(s,0,sizeof(s));
    for(int i=0;i<n;i++) cin>>v[i].ft;
    for(int i=0;i<n;i++) cin>>v[i].sd,b[i]=v[i].sd;
    sort(v.begin(),v.end()); sort(b,b+n);

    map<ll,int> ds;

    int s=1,mx=0;
    for(int i=0;i<n;i++){
        if(ds[b[i]]==0) ds[b[i]]=s++,mx++;
    }
    ll res=0;
    for(int i=0;i<n;i+=1){
        ll x=v[i].ft, y=v[i].sd,p=ds[v[i].sd];
        res+=q1(0,1,1,mx,1,p)*x-q1(1,1,1,mx,1,p);
        u1(0,1,1,mx,p,1); u1(1,1,1,mx,p,x);
    }
    cout<<res;
}


#include <bits/stdc++.h>
#define ll long long
#define ft first
#define sd second
using namespace std;

const int N=2e5+10;
int s[2][(N+3)*4];

void u1(int t,int nd,int l,int r,int p,ll v){
    if(r<l || p<l || p>r) return;
    if(l==r){
        s[t][nd]+=v; return;
    }
    int mi=(l+r)/2;
    u1(t,nd*2,l,mi,p,v);
    u1(t,nd*2+1,mi+1,r,p,v);
    s[t][nd]=s[t][nd*2]+s[t][nd*2+1];
}

ll q1(int t,int nd,int l,int r,int ql,int qr){
    if(ql>r || qr<l || l>r) return 0;
    if(ql<=l && qr>=r) return s[t][nd];
    int mi=(l+r)/2;
    return q1(t,nd*2,l,mi,ql,qr)+q1(t,nd*2+1,mi+1,r,ql,qr);
}

int main()
{
    int n; cin>>n; vector<pair<int,int> > v(n); ll b[n];   memset(s,0,sizeof(s));
    for(int i=0;i<n;i++) cin>>v[i].ft;
    for(int i=0;i<n;i++) cin>>v[i].sd,b[i]=v[i].sd;
    sort(v.begin(),v.end()); sort(b,b+n);

    map<ll,int> ds;

    int s=1;
    for(int i=0;i<n;i++){
        if(ds[b[i]]==0) ds[b[i]]=s++;
    }
    ll res=0;
    for(int i=0;i<n;i+=1){
        ll x=v[i].ft, y=v[i].sd,p=ds[v[i].sd];
        res+=q1(0,1,1,N,1,p)*x-q1(1,1,1,N,1,p);
        u1(0,1,1,N,p,1); u1(1,1,1,N,p,x);
    }
    cout<<res;
}


#include <bits/stdc++.h>
#define ll long long
#define ft first
#define sd second
using namespace std;

const int N=2e5+10;
ll s[2][N*4];

void u1(int t,int nd,int l,int r,int p,ll v){
    if(r<l || p<l || p>r) return;
    if(l==r){
        s[t][nd]+=v; return;
    }
    int mi=(l+r)/2;
    u1(t,nd*2,l,mi,p,v);
    u1(t,nd*2+1,mi+1,r,p,v);
    s[t][nd]=s[t][nd*2]+s[t][nd*2+1];
}

ll q1(int t,int nd,int l,int r,int ql,int qr){
    if(ql>r || qr<l || l>r) return 0;
    if(ql<=l && qr>=r) return s[t][nd];
    int mi=(l+r)/2;
    return q1(t,nd*2,l,mi,ql,qr)+q1(t,nd*2+1,mi+1,r,ql,qr);
}

int main()
{
    int n; cin>>n; vector<pair<ll,ll> > v(n); ll b[n];   memset(s,0,sizeof(s));
    for(int i=0;i<n;i++) cin>>v[i].ft;
    for(int i=0;i<n;i++) cin>>v[i].sd,b[i]=v[i].sd;
    sort(v.begin(),v.end()); sort(b,b+n);

    map<ll,int> ds;

    int s=1,mx=0;
    for(int i=0;i<n;i++){
        if(ds[b[i]]==0) ds[b[i]]=s++,mx++;
    }
    ll res=0;
    for(int i=0;i<n;i+=1){
        ll x=v[i].ft, y=v[i].sd,p=ds[v[i].sd];
        res+=q1(0,1,1,mx,1,p)*x-q1(1,1,1,mx,1,p);
        u1(0,1,1,mx,p,1); u1(1,1,1,mx,p,x);
    }
    cout<<res;
}


#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

using INT = long long;
using pii = pair<int, int>;
#define NN 200010
int n, pos[NN], speed[NN], tot[NN];
pii p[NN];
int cnt, sz;
INT B[NN];

void add(int u, int val) {
	for (; u<=sz; u+=u&-u) B[u]+=val, tot[u]++;
}

INT calc(int u) {
	INT ans = 0;
	for (; u; u-=u&-u) ans+=B[u], cnt+=tot[u];
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &pos[i]);
	for (int i=1; i<=n; i++) scanf("%d", &speed[i]);
	for (int i=1; i<=n; i++) p[i]=pii(pos[i], speed[i]);
	sort(p+1, p+n+1);

	vector<int> res;
	for (int i=1; i<=n; i++) res.push_back(speed[i]);
	sort(res.begin(), res.end());
	res.resize(unique(res.begin(), res.end())-res.begin());
	sz = res.size();

	INT ans = 0;
	for (int i=1; i<=n; i++) {
		int x=p[i].x, v=p[i].y;
		cnt=0;
		INT sum = 0;
		sum+=calc(upper_bound(res.begin(), res.end(),  v) - res.begin());
		add(upper_bound(res.begin(), res.end(), v)-res.begin(), x);
		ans+=1LL*x*cnt - sum;
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define inf 1e9
#define NN 200100
using namespace std;

typedef pair<int, int> pii;
typedef long long INT;
int pos[NN], v[NN];
int id[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &pos[i]);
	for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
	INT ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){

			if(pos[j] >= pos[i] && v[j] >= v[i]) ans += abs(pos[i] - pos[j]);
			if(pos[j] <= pos[i] && v[j] <= v[i]) ans += abs(pos[i] - pos[j]);

		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define inf 1e9
#define NN 200100
using namespace std;

typedef long long INT;
int b[NN];
INT B[NN];

void update1(int u){
	for(; u < NN; u += (u & -u)) b[u]++;
}

void update2(int u, int m){
	for(; u < NN; u += (u & -u)) B[u] += m;
}

int calc1(int u){
	int ans = 0;
	for(; u; u -= (u & -u)) ans += b[u];
	return ans;
}

INT calc2(int u){
	INT ans = 0;
	for(; u; u -=(u & -u)) ans += B[u];
	return ans;
}
typedef pair<int, int> pii;
pii p[NN];
int v[NN], vv[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &p[i].x);
	for(int i = 1; i <= n; i++) scanf("%d", &v[i]), vv[i] = v[i];
	sort(vv + 1 , vv + n + 1);
	for(int i = 1; i <= n; i++) p[i].y = lower_bound(vv + 1, vv + n + 1, v[i]) - vv;

	sort(p + 1, p + n + 1);
	INT ans = 0;
	for(int i = 1; i <= n; i++){
		int t = calc1(p[i].y);
		INT T = calc2(p[i].y);
		ans += t * p[i].x - T;
		update1(p[i].y);
		update2(p[i].y, p[i].x);
	}

	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long INT;
typedef pair<int,int> pii;

const int NN=200010;
const int inf=0x3f3f3f3f;

INT b[NN],B[NN],tmp[NN],v[NN];
pii p[NN];

void update(int u,int val,int f){
	if(f==1)for(;u<NN;u+=u&-u)b[u]+=val;
	else for(;u<NN;u+=u&-u)B[u]+=val;
}

INT calc(int u,int f){
	INT ans=0;
	if(f==1)for(;u;u^=u&-u)ans+=b[u];
	else for(;u;u^=u&-u)ans+=B[u];
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&p[i].x);
	for(int i=1;i<=n;i++)scanf("%I64d",&v[i]),tmp[i]=v[i];

	sort(tmp+1,tmp+n+1);
	for(int i=1;i<=n;i++){
		p[i].y=lower_bound(tmp+1,tmp+n+1,v[i])-tmp;
	}
	sort(p+1,p+n+1);

	INT ans=0;
	for(int i=1;i<=n;i++){
		INT k=calc(p[i].y,1);
		INT K=calc(p[i].y,2);
		ans+=1LL*k*p[i].x-K;
		update(p[i].y,1,1);
		update(p[i].y,p[i].x,2);
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>

#define NN 200100

using namespace std;

typedef long long INT;
typedef pair<int,int>pii;

pii p[NN];
int x[NN],t[NN],v[NN],vv[NN],B[NN];
INT b[NN];

void add(int id,int m){
	for(;id<NN;id+=id&-id)b[id]+=m;
}

void update(int id){
	for(;id<NN;id+=id&-id)B[id]++;
}

INT calc1(int u){
	INT ans=0;
	if(u==0)return 0;
	for(;u;u-=u&-u)ans+=b[u];
	return ans;
}

int calc2(int u){
	int ans=0;
	if(u==0)return 0;
	for(;u;u-=u&-u)ans+=B[u];
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i];
		p[i]=pii(x[i],i);
	}
	for(int i=1;i<=n;i++)cin>>t[i];
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++){
		x[i]=p[i].first;
		v[i]=t[p[i].second];
	}
	for(int i=1;i<=n;i++)vv[i]=v[i];
	sort(vv+1,vv+n+1);
	for(int i=1;i<=n;i++){
		v[i]=upper_bound(vv+1,vv+n+1,v[i])-vv-1;
	}

	INT ans=0;
	for(int i=n;i>=1;i--){
		int p=calc2(NN-1)-calc2(v[i]-1);
		INT t=calc1(NN-1)-calc1(v[i]-1);
		ans+=(t-1LL*x[i]*p);
		update(v[i]);
		add(v[i],x[i]);
	}
	cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define NN 200100
using namespace std;

typedef long long INT;
int b[NN];
INT B[NN];

void update1(int u){
	for(; u < NN; u += (u & -u)) b[u]++;
}

void update2(int u, int m){
	for(; u < NN; u += (u & -u)) B[u] += m;
}

int calc1(int u){
	int ans = 0;
	for(; u; u -= (u & -u)) ans += b[u];
	return ans;
}

INT calc2(int u){
	INT ans = 0;
	for(; u; u -=(u & -u)) ans += B[u];
	return ans;
}
typedef pair<int, int> pii;
pii p[NN];
int v[NN], vv[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &p[i].x);
	for(int i = 1; i <= n; i++) scanf("%d", &v[i]), vv[i] = v[i];
	sort(vv + 1 , vv + n + 1);
	for(int i = 1; i <= n; i++) p[i].y = lower_bound(vv + 1, vv + n + 1, v[i]) - vv;

	sort(p + 1, p + n + 1);
	INT ans = 0;
	for(int i = 1; i <= n; i++){
		int t = calc1(p[i].y);
		INT T = calc2(p[i].y);
		ans += (INT)t * p[i].x - T;
		update1(p[i].y);
		update2(p[i].y, p[i].x);
	}

	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[200005];
int velo[200005];
int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i=0;i<n;++i) cin >> arr[i];
	for(int i=0;i<n;++i) cin >> velo[i];
	long long ans = 0;
	for(int i=0;i<n-1;++i) {
		for(int j=i;j<n;++j) {
			if(arr[i] < arr[j]) {
				if(velo[i] <= velo[j]) ans += abs(arr[i]-arr[j]);
			}
			else {
				if(velo[i] >= velo[j]) ans += abs(arr[i]-arr[j]);
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int N;
long long get(vector<long long> &tree, int pos) {
	long long ret = 0;
	while(pos) {
		ret += tree[pos];
		pos -= (pos & -pos);
	}
	return ret;
}

void update(vector<long long> &tree, int pos, int diff) {
	while(pos < tree.size()) {
		tree[pos] += diff;
		pos += (pos & -pos);
	}
}

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	cin >> N;
	vector<pair<long long,long long>> p(N);
	for(int i=0;i<N;++i) cin >> p[i].first;
	for(int i=0;i<N;++i) cin >> p[i].second;
	sort(p.begin(), p.end());
	vector<int> v;
	for(int i=0;i<N;++i) v.push_back(p[i].second);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<long long> cnt(v.size()+1), sum(v.size()+1);
	long long ans = 0;
	for(int i=0;i<N;++i) {
		int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
		++pos;
		ans += 1LL * (get(cnt,pos) * p[i].first - get(sum,pos));
		update(cnt,pos,1);
		update(sum,pos,p[i].first);
	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int N;
long long get(vector<int> &tree, int pos) {
	long long ret = 0;
	while(pos) {
		ret += tree[pos];
		pos -= (pos & -pos);
	}
	return ret;
}

void update(vector<int> &tree, int pos, int diff) {
	while(pos < tree.size()) {
		tree[pos] += diff;
		pos += (pos & -pos);
	}
}

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	cin >> N;
	vector<pair<long long,long long>> p(N);
	for(int i=0;i<N;++i) cin >> p[i].first;
	for(int i=0;i<N;++i) cin >> p[i].second;
	sort(p.begin(), p.end());
	vector<int> v;
	for(int i=0;i<N;++i) v.push_back(p[i].second);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<int> cnt(v.size()+1), sum(v.size()+1);
	long long ans = 0;
	for(int i=0;i<N;++i) {
		int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
		++pos;
		ans += 1LL * (get(cnt,pos) * p[i].first - get(sum,pos));
		update(cnt,pos,1);
		update(sum,pos,p[i].first);
	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int N;

int get(vector<int> &tree, int pos) {
	int ret = 0;
	while(pos) {
		ret += tree[pos];
		pos -= (pos & -pos);
	}
	return ret;
}

void update(vector<int> &tree, int pos, int diff) {
	while(pos < tree.size()) {
		tree[pos] += diff;
		pos += (pos & -pos);
	}
}

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	cin >> N;
	vector<pair<int,int>> p(N);
	for(int i=0;i<N;++i) cin >> p[i].first;
	for(int i=0;i<N;++i) cin >> p[i].second;
	sort(p.begin(), p.end());
	vector<int> v;
	for(int i=0;i<N;++i) v.push_back(p[i].second);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<int> cnt(v.size()+1), sum(v.size()+1);
	int ans = 0;
	for(int i=0;i<N;++i) {
		int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
		++pos;
		ans += (get(cnt,pos) * p[i].first - get(sum,pos));
		update(cnt,pos,1);
		update(sum,pos,p[i].first);
	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int N;

int get(vector<int> &tree, int pos) {
	int ret = 0;
	while(pos) {
		ret += tree[pos];
		pos -= (pos & -pos);
	}
	return ret;
}

void update(vector<int> &tree, int pos, int diff) {
	while(pos < tree.size()) {
		tree[pos] += diff;
		pos += (pos & -pos);
	}
}

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	cin >> N;
	vector<pair<int,int>> p(N);
	for(int i=0;i<N;++i) cin >> p[i].first;
	for(int i=0;i<N;++i) cin >> p[i].second;
	sort(p.begin(), p.end());
	vector<int> v;
	for(int i=0;i<N;++i) v.push_back(p[i].second);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<int> cnt(v.size()+1), sum(v.size()+1);
	long long ans = 0;
	for(int i=0;i<N;++i) {
		int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
		++pos;
		ans += (get(cnt,pos) * p[i].first - get(sum,pos));
		update(cnt,pos,1);
		update(sum,pos,p[i].first);
	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int N;
int get(vector<int> &tree, int pos) {
	int ret = 0;
	while(pos) {
		ret += tree[pos];
		pos -= (pos & -pos);
	}
	return ret;
}

void update(vector<int> &tree, int pos, int diff) {
	while(pos < tree.size()) {
		tree[pos] += diff;
		pos += (pos & -pos);
	}
}

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	cin >> N;
	vector<pair<int,int>> p(N);
	for(int i=0;i<N;++i) cin >> p[i].first;
	for(int i=0;i<N;++i) cin >> p[i].second;
	sort(p.begin(), p.end());
	vector<int> v;
	for(int i=0;i<N;++i) v.push_back(p[i].second);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<int> cnt(v.size()+1), sum(v.size()+1);
	long long ans = 0;
	for(int i=0;i<N;++i) {
		int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
		++pos;
		ans += 1LL * (get(cnt,pos) * p[i].first - get(sum,pos));
		update(cnt,pos,1);
		update(sum,pos,p[i].first);
	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int N;
long long get(vector<int> &tree, int pos) {
	long long ret = 0;
	while(pos) {
		ret += tree[pos];
		pos -= (pos & -pos);
	}
	return ret;
}

void update(vector<int> &tree, int pos, int diff) {
	while(pos < tree.size()) {
		tree[pos] += diff;
		pos += (pos & -pos);
	}
}

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	cin >> N;
	vector<pair<int,int>> p(N);
	for(int i=0;i<N;++i) cin >> p[i].first;
	for(int i=0;i<N;++i) cin >> p[i].second;
	sort(p.begin(), p.end());
	vector<int> v;
	for(int i=0;i<N;++i) v.push_back(p[i].second);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	vector<int> cnt(v.size()+1), sum(v.size()+1);
	long long ans = 0;
	for(int i=0;i<N;++i) {
		int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
		++pos;
		ans += 1LL * (get(cnt,pos) * p[i].first - get(sum,pos));
		update(cnt,pos,1);
		update(sum,pos,p[i].first);
	}
	cout << ans << '\n';
	return 0;
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll n;
V(pp) vect;
V(ll) speed;
ll val[2][200005];
ll fetch(ll flag,ll id)
{	ll ans=0;
	for(;id>=0;id=(id&(id+1))-1)
		ans+=val[flag][id];
	return ans;
}
void update(ll flag,ll id,ll cost)
{	for(;id<speed.size();id=(id|(id+1)))
		val[flag][id]+=cost;
}
int main()
{	vasu2907;
	cin>>n;
	ll a,b;
	vect.resize(n);
	F(i,n)
	{	cin>>a;
		vect[i].fr=a;
	}
	F(i,n)
	{	cin>>a;
		vect[i].sc=a;
		speed.pb(a);
	}
	sort(vect.begin(),vect.end());
	sort(speed.begin(),speed.end());
	speed.resize(unique(speed.begin(),speed.end())-speed.begin());
//	cout<<"Speed Size="<<speed.size()<<endl;
//	out(speed,speed.size());
	ll ans=0;
	for(ll i=0;i<n;i++)
	{	ll tx=lb(speed,vect[i].sc);
		ans+=fetch(0,tx)*vect[i].fr - fetch(1,tx);
		update(0,tx,1);
		update(1,tx,vect[i].fr);
	}
	cout<<ans<<endl;

}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005];
ll countLarger[200005];
void countLargerRight(V(pp) A,ll len)
{   set<int> s;
    for (int i = len - 1; i >= 0; i--) {
        s.insert(A[i].sc);
        auto it = s.upper_bound(A[i].sc);
        countLarger[i] = s.size() - distance(s.begin(), it);
    }
}
bool comp(pp a,pp b)
{	if(a.fr==b.fr)	return 1;
	return a.fr<b.fr;
}
int main()
{	vasu2907;
	ll n;
	cin>>n;
	ll ar[n];
	in(ar,n);
	ll av[n];
	V(ll) l,r;
	in(av,n);
	V(pp) low,high;
	F(i,n)
	{	if(av[i]<=0)
			l.pb(ar[i]),low.pb({ar[i],abs(av[i])});
		else
			r.pb(ar[i]),high.pb({ar[i],av[i]});
	}
	ll ans=0,sz=r.size();
	if(r.size()>0)
	{	dp[sz-1]=r[sz-1];
		for(ll i=sz-2;i>=0;i--)
			dp[i]=dp[i+1]+r[i];
		for(ll i=0;i<l.size();i++)
		{	ll tx=ub(r,l[i]);
			if(tx==r.size())	continue;
			ll p=r.size() - tx;
			ans+=dp[tx]-p*(l[i]);
		}
	}
//	cout<<ans<<endl;
	sort(low.begin(),low.end(),comp);
	sort(high.begin(),high.end(),comp);
	ll p=0;
	for(ll i=0;i<low.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(low[j].sc>=low[i].sc)	p+=abs(low[i].fr-low[j].fr);
		}
		for(ll j=i+1;j<low.size();j++)
		{	if(low[j].sc<=low[i].sc)	p+=abs(low[i].fr-low[j].fr);
		}
	}
	ans+=p/2;
//	cout<<"Low="<<ans<<endl;
	p=0;
//	F(i,high.size())
//		cout<<high[i].fr<<" "<<high[i].sc<<endl;
	for(ll i=0;i<high.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(high[j].sc<=high[i].sc)	p+=abs(high[j].fr-high[i].fr);
		}
		for(ll j=i+1;j<high.size();j++)
		{	if(high[j].sc>=high[i].sc)	p+=abs(high[j].fr-high[i].fr);
		}
	}
	ans+=p/2;
	cout<<ans<<endl;
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005];
ll countLarger[200005];
void countLargerRight(V(pp) A,ll len)
{   set<int> s;
    for (int i = len - 1; i >= 0; i--) {
        s.insert(A[i].sc);
        auto it = s.upper_bound(A[i].sc);
        countLarger[i] = s.size() - distance(s.begin(), it);
    }
}
bool comp(pp a,pp b)
{	if(a.fr==b.fr)	return 1;
	return a.fr<b.fr;
}
int main()
{	vasu2907;
	ll n;
	cin>>n;
	ll ar[n];
	in(ar,n);
	ll av[n];
	V(ll) l,r;
	in(av,n);
	V(pp) low,high;
	F(i,n)
	{	if(av[i]<=0)
			l.pb(ar[i]),low.pb({ar[i],abs(av[i])});
		else
			r.pb(ar[i]),high.pb({ar[i],av[i]});
	}
	ll ans=0,sz=r.size();
	if(r.size()>0)
	{	dp[sz-1]=r[sz-1];
		for(ll i=sz-2;i>=0;i--)
			dp[i]=dp[i+1]+r[i];
		for(ll i=0;i<l.size();i++)
		{	ll tx=ub(r,l[i]);
			if(tx==r.size())	continue;
			ll p=r.size() - tx;
			ans+=dp[tx]-p*(l[i]);
		}
	}
//	cout<<ans<<endl;
	sort(low.begin(),low.end(),comp);
	sort(high.begin(),high.end(),comp);
	ll p=0;
	for(ll i=0;i<low.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(low[j].sc>=low[i].sc)	ans+=abs(low[i].fr-low[j].fr);
		}
//		for(ll j=i+1;j<low.size();j++)
//		{	if(low[j].sc<=low[i].sc)	p+=abs(low[i].fr-low[j].fr);
//		}
	}
	ans+=p/2;
//	cout<<"Low="<<ans<<endl;
	p=0;
//	F(i,high.size())
//		cout<<high[i].fr<<" "<<high[i].sc<<endl;
	for(ll i=0;i<high.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(high[j].sc<=high[i].sc)	ans+=abs(high[j].fr-high[i].fr);
		}
//		for(ll j=i+1;j<high.size();j++)
//		{	if(high[j].sc>=high[i].sc)	p+=abs(high[j].fr-high[i].fr);
//		}
	}
	cout<<ans<<endl;
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005];
ll countLarger[200005];
void countLargerRight(V(pp) A,ll len)
{   set<int> s;
    for (int i = len - 1; i >= 0; i--) {
        s.insert(A[i].sc);
        auto it = s.upper_bound(A[i].sc);
        countLarger[i] = s.size() - distance(s.begin(), it);
    }
}
bool comp(pp a,pp b)
{	if(a.fr==b.fr)	return 1;
	return a.fr<b.fr;
}
int main()
{	vasu2907;
	ll n;
	cin>>n;
	ll ar[n];
	in(ar,n);
	ll av[n];
	V(ll) l,r;
	in(av,n);
	V(pp) low,high;
	F(i,n)
	{	if(av[i]<0)
			l.pb(ar[i]),low.pb({ar[i],abs(av[i])});
		else if(av[i]>0)
			r.pb(ar[i]),high.pb({ar[i],av[i]});
		else
			l.pb(ar[i]),low.pb({ar[i],abs(av[i])}),high.pb({ar[i],av[i]});
	}
	ll ans=0,sz=r.size();
	if(r.size()>0)
	{	dp[sz-1]=r[sz-1];
		for(ll i=sz-2;i>=0;i--)
			dp[i]=dp[i+1]+r[i];
		for(ll i=0;i<l.size();i++)
		{	ll tx=ub(r,l[i]);
			if(tx==r.size())	continue;
			ll p=r.size() - tx;
			ans+=dp[tx]-p*(l[i]);
		}
	}
//	cout<<ans<<endl;
	sort(low.begin(),low.end(),comp);
	sort(high.begin(),high.end(),comp);
	ll p=0;
	for(ll i=0;i<low.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(low[j].sc>=low[i].sc)	ans+=abs(low[i].fr-low[j].fr);
		}
//		for(ll j=i+1;j<low.size();j++)
//		{	if(low[j].sc<=low[i].sc)	p+=abs(low[i].fr-low[j].fr);
//		}
	}
	ans+=p/2;
//	cout<<"Low="<<ans<<endl;
	p=0;
//	F(i,high.size())
//		cout<<high[i].fr<<" "<<high[i].sc<<endl;
	for(ll i=0;i<high.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(high[j].sc<=high[i].sc)	ans+=abs(high[j].fr-high[i].fr);
		}
//		for(ll j=i+1;j<high.size();j++)
//		{	if(high[j].sc>=high[i].sc)	p+=abs(high[j].fr-high[i].fr);
//		}
	}
	cout<<ans<<endl;
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005];
ll countLarger[200005];
void countLargerRight(V(pp) A,ll len)
{   set<int> s;
    for (int i = len - 1; i >= 0; i--) {
        s.insert(A[i].sc);
        auto it = s.upper_bound(A[i].sc);
        countLarger[i] = s.size() - distance(s.begin(), it);
    }
}
bool comp(pp a,pp b)
{	if(a.fr==b.fr)	return 1;
	return a.fr<b.fr;
}
int main()
{	vasu2907;
	ll n;
	cin>>n;
	ll ar[n];
	in(ar,n);
	ll av[n];
	V(ll) l,r;
	in(av,n);
	V(pp) low,high;
	F(i,n)
	{	if(av[i]<0)
			l.pb(ar[i]),low.pb({ar[i],abs(av[i])});
		else if(av[i]>0)
			r.pb(ar[i]),high.pb({ar[i],av[i]});
		else
			l.pb(ar[i]),low.pb({ar[i],abs(av[i])}),high.pb({ar[i],av[i]});
	}
	ll ans=0,sz=r.size();
	if(r.size()>0)
	{	dp[sz-1]=r[sz-1];
		for(ll i=sz-2;i>=0;i--)
			dp[i]=dp[i+1]+r[i];
		for(ll i=0;i<l.size();i++)
		{	ll tx=ub(r,l[i]);
			if(tx==r.size())	continue;
			ll p=r.size() - tx;
			ans+=dp[tx]-p*(l[i]);
		}
	}
//	cout<<ans<<endl;
	sort(low.begin(),low.end(),comp);
	sort(high.begin(),high.end(),comp);
	ll p=0;
	for(ll i=0;i<low.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(low[j].sc>=low[i].sc)	ans+=abs(low[i].fr-low[j].fr);
		}
//		for(ll j=i+1;j<low.size();j++)
//		{	if(low[j].sc<=low[i].sc)	p+=abs(low[i].fr-low[j].fr);
//		}
	}
	ans+=p/2;
//	cout<<"Low="<<ans<<endl;
	p=0;
//	F(i,high.size())
//		cout<<high[i].fr<<" "<<high[i].sc<<endl;
	for(ll i=0;i<high.size();i++)
	{	for(ll j=0;j<i;j++)
		{	if(high[j].sc==0 && high[i].sc==0)	continue;
			if(high[j].sc<=high[i].sc)	ans+=abs(high[j].fr-high[i].fr);
		}
//		for(ll j=i+1;j<high.size();j++)
//		{	if(high[j].sc>=high[i].sc)	p+=abs(high[j].fr-high[i].fr);
//		}
	}
	cout<<ans<<endl;
}


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], ll l, ll r, ll treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    struct tacka
    {
        ll x;
        ll v;
    };

    bool komp(tacka t1, tacka t2)
    {
        return t1.x < t2.x;
    }

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        ll brojac = 0;
        vcomp.push_back(0);

        set<ll> skup;

        for(int i = 0; i < n; i++)
        {
            skup.insert(v[i]);
        }

        for(int i = 0; i < n; i++)
        {
            vcomp[i] = distance(skup.begin(), skup.lower_bound(v[i]));
        }

        double dummy[pom+1];

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

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x = x[i];
           t[i].v = vcomp[i];
        }

        sort(t, t+n, komp);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, t[i].v)*t[i].x-sumaDist.getIntervalSum(0, t[i].v);

            sumaDist.addTo(t[i].v, t[i].x);
            brojTacaka.addTo(t[i].v, 1);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    int counter = 0;

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value = 0;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], ll l, ll r, ll treeIndex)
        {
            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], ll n) //ima n elemenata, ne n-1
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    class Tacka
    {
        public:
            ll x;
            ll v;
    };

    bool komp(Tacka t1, Tacka t2)
    {
        return t1.x < t2.x;
    }

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

        int n;
        cin >> n;

        double x[n];
        double v[n];

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x[i] = pom;
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v[i] = pom;
        }

        double vpom[n] ;

        for(int i = 0; i < n; i++)
        {
           vpom[i]=v[i];
        }

        sort(vpom, vpom+n);

        ll brojac = 0;

        map<ll, ll> vcomp;

        vcomp.insert(make_pair(vpom[0], 0));

        for(int i = 1; i < n; i++)
        {
            if(vpom[i]==vpom[i-1])
            {
                vcomp.insert(make_pair(vpom[i], brojac));
            }
            else
            {
                brojac++;
                vcomp.insert(make_pair(vpom[i], brojac));
            }
        }

        double comp[n];

        for(int i = 0; i < n; i++)
        {
            comp[i] = vcomp.find(v[i])->second;
        }

        /*cout << "comp: " << endl;
       for(int i = 0; i < n; i++)
        {
            cout << comp[i] << " ";
        }
        cout << endl;*/

        ll res = 0;

        double pom[n];
         for(int i = 0; i < n; i++)
        {
           pom[i]=0;
        }

        Tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x=x[i];
           t[i].v=comp[i];
        }

        sort(t, t+n, komp);

        /*cout << "x: ";
        for(int i = 0; i < n; i++)
        {
           cout << t[i].x << " ";
        }
        cout << endl;

        cout << "v: ";
        for(int i = 0; i < n; i++)
        {
           cout << t[i].v << " ";
        }
        cout << endl;*/

        SegmentTree brojTacaka = SegmentTree(pom, n);
        SegmentTree distSum = SegmentTree(pom, n);

        for(int i = 0; i < n; i++)
        {
            ll bt = brojTacaka.getIntervalSum(0, t[i].v);
            ll dist = distSum.getIntervalSum(0, t[i].v);

            //cout << "i=" << i << "  bt=" << bt << " dist=" << dist << endl;

            res += t[i].x * bt - dist;

            brojTacaka.addTo(t[i].v, 1);
            distSum.addTo(t[i].v, x[i]);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], int l, int r, int treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    struct tacka
    {
        ll x;
        ll v;
    };

    bool komp(tacka t1, tacka t2)
{
    return t1.x < t2.x;
}

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        double dummy[pom+1];

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

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x = x[i];
           t[i].v = vcomp[i];
        }

        sort(t, t+n, komp);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, vcomp[i-1])*x[i]-sumaDist.getIntervalSum(0, vcomp[i-1]);

            sumaDist.addTo(vcomp[i], x[i]);
            brojTacaka.addTo(vcomp[i], 1);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 8e5; // velicina arraya za segmentno stablo

    int counter = 0;

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    template<class T> class SegmentTreeNode
    {
        public:
            T value;
            T min;
            T max;
    };

    template<class T> class SegmentTree
    {
        public:
            int size;
            SegmentTreeNode<T> nodes[N];

        int getLeftChild(int i)
        {
            return 2*i+1;
        }

        int getRightChild(int i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], ll l, ll r, ll treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    class Tacka
    {
        public:
            ll x;
            ll v;
    };

    bool komp(Tacka t1, Tacka t2)
    {
        return t1.x < t2.x;
    }

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

        int n;
        cin >> n;

        double x[n];
        double v[n];

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x[i] = pom;
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v[i] = pom;
        }

        double vpom[n] ;

        for(int i = 0; i < n; i++)
        {
           vpom[i]=v[i];
        }

        sort(vpom, vpom+n);

        ll brojac = 0;

        map<ll, ll> vcomp;

        vcomp.insert(make_pair(vpom[0], 0));

        for(int i = 1; i < n; i++)
        {
            if(vpom[i]==vpom[i-1])
            {
                vcomp.insert(make_pair(vpom[i], brojac));
            }
            else
            {
                brojac++;
                vcomp.insert(make_pair(vpom[i], brojac));
            }
        }

        double comp[n];

        for(int i = 0; i < n; i++)
        {
            comp[i] = vcomp.find(v[i])->second;
        }

        /*cout << "comp: " << endl;
       for(int i = 0; i < n; i++)
        {
            cout << comp[i] << " ";
        }
        cout << endl;*/

        ll res = 0;

        double pom[n+1];
         for(int i = 0; i < n; i++)
        {
           pom[i]=0;
        }

        Tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x=x[i];
           t[i].v=comp[i];
        }

        sort(t, t+n, komp);

        /*cout << "x: ";
        for(int i = 0; i < n; i++)
        {
           cout << t[i].x << " ";
        }
        cout << endl;

        cout << "v: ";
        for(int i = 0; i < n; i++)
        {
           cout << t[i].v << " ";
        }
        cout << endl;*/

        SegmentTree<ll> brojTacaka = SegmentTree<ll>(pom, n);
        SegmentTree<ll> distSum = SegmentTree<ll>(pom, n);

        for(int i = 0; i < n; i++)
        {
            ll bt = brojTacaka.getIntervalSum(0, t[i].v);
            ll dist = distSum.getIntervalSum(0, t[i].v);

           // cout << "i=" << i << "  bt=" << bt << " dist=" << dist << " total: " << t[i].x * bt - dist <<  endl;

            res += t[i].x * bt - dist;

            brojTacaka.addTo(t[i].v, 1);
            distSum.addTo(t[i].v, t[i].x);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], ll l, ll r, ll treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    struct tacka
    {
        ll x;
        ll v;
    };

    bool komp(tacka t1, tacka t2)
{
    return t1.x < t2.x;
}

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        double dummy[pom+1];

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

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x = x[i];
           t[i].v = vcomp[i];
        }

        sort(t, t+n, komp);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, t[i].v)*t[i].x-sumaDist.getIntervalSum(0, t[i].v);

            sumaDist.addTo(t[i].v, t[i].x);
            brojTacaka.addTo(t[i].v, 1);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], int l, int r, int treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        sort(v.begin(),v.end());

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        cout << "vcomp:" ;
            for(int i = 0; i < n; i++)
        {
           cout << vcomp[i] << " ";
        }

        cout << endl;

        double dummy[pom+1];

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

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, vcomp[i])*x[i]-sumaDist.getIntervalSum(0, vcomp[i]);

            sumaDist.addTo(vcomp[i], x[i]);
            brojTacaka.addTo(vcomp[i], 1);
        }

        cout << res << endl;

        return 0;
    }