/* Code by Saborit */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast") 
#define MX 200005
#define INF (1<<30)
#define EPS 1e-9
#define MOD 1000000007
#define mid (x+xend)/2
#define izq nod*2
#define der nod*2+1
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define unique(X) (X).resize(unique(all(X)) - (X).begin())
#ifdef LOCAL 
	#include "debug.h"
#endif
using namespace std;
using namespace __gnu_pbds;
typedef long long int64;
typedef unsigned long long unt64;

struct pt{
	int x, v, id;
	
	bool operator < (const pt& p)const{
		return x < p.x;
	}
};

int N, n, m;
int A[MX], B[MX];
pt P[MX];
vector<int> values;
int64 sol;

struct segment_tree{
	pair<int64, int> T[4*MX];
	
	pair<int64, int> update(int a, int64 b, int x=1, int xend=m, int nod=1){
		if( a<=x && xend<=a )
			return T[nod] = {T[nod].fr + b, T[nod].sc + 1};	
		if( a < x || xend < a )
			return T[nod];
		
		auto aa = update(a, b, x, mid, izq);
		auto bb = update(a, b, mid+1, xend, der);
		
		return T[nod] = {aa.fr + bb.fr, aa.sc + bb.sc};
	}
	
	pair<int64, int> query(int a, int b, int x=1, int xend=m, int nod=1){
		if( a<=x && xend<=b )
			return T[nod];
		if( b < x || xend < a )
			return {0ll, 0};
			
		auto aa = query(a, b, x, mid, izq);
		auto bb = query(a, b, mid+1, xend, der);
		
		return {aa.fr + bb.fr, aa.sc + bb.sc};
	}
};

int main(void){
    //~ freopen("a.in", "r", stdin);
    //~ freopen("a.out", "w", stdout);
    
	scanf("%d", &N);
	for(int i=1; i<=N; i++){
		scanf("%d", &A[i]);
		values.pb(A[i]);	
	}
	
	sort(all(values));
	unique(values);
	
	n = values.size();
	
	for(int i=1; i<=N; i++)
		P[i].x = lower_bound(all(values), A[i]) - values.begin() + 1;
	
	values.clear();
	for(int i=1; i<=N; i++){
		scanf("%d", &B[i]);
		values.pb(B[i]);	
	}
	
	sort(all(values));
	unique(values);
	
	m = values.size();
	
	for(int i=1; i<=N; i++)
		P[i].v = lower_bound(all(values), B[i]) - values.begin() + 1;
	
	for(int i=1; i<=N; i++)
		P[i].id = i;
		
	sort(P+1, P+N+1);
	
	segment_tree ST;
	
	//~ db() << n << " " << m; 
	
	for(int i=N; i > 0; i--){
		auto q = ST.query(P[i].v, m);
		
		//~ db() << imie(i) << " " << q.fr << " " << q.sc;
		
		sol += q.fr - A[ P[i].id ] * q.sc;
		
		ST.update(P[i].v, A[ P[i].id ]);
	}
	
	printf("%lld\n", sol);
	
   return 0;
}
