#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL)
#define in(T, v) \
	T v;         \
	cin >> v
#define TC      \
	in(int, t); \
	while (t--)
#define forp(T, v, a, b) for (T v = a; v < b; ++v)
#define Forp(T, v, a, b, d) for (T v = a; v < b; v += d)
#define form(T, v, b, a) for (T v = a - 1; v >= b; --v)
#define Form(T, v, b, a, d) for (T v = a - 1; v >= b; v -= d)
#define inarr(A, n, k) forp(int, i, k, n + k) cin >> A[i]
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define vb vector<bool>
#define vvb vector<vb>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define pii pair<int, int>
#define vpi vector<pii>
#define MOD ll(1e9 + 7)
#define unordered_set(T) unordered_set<T, custom_hash>
#define unordered_map(T1, T2) unordered_map<T1, T2, custom_hash>
using namespace std;

struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

template <typename C, typename T = std::decay_t<decltype(*begin(std::declval<C>()))>, typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr>
std::ostream &operator<<(std::ostream &os, const C &container)
{
	bool first = true;
	std::stringstream ss;
	ss << '[';
	for (const auto &x : container)
	{
		if (!first)
		{
			ss << ", ";
		}
		first = false;
		ss << x;
	}
	ss << ']';
	return os << ss.str();
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{
	os << '{' << p.first << ", " << p.second << '}';
	return os;
}
vector<string> vec_splitter(string S)
{
	S += ',';
	vector<string> res;
	while (!S.empty())
	{
		res.push_back(S.substr(0, S.find(',')));
		S = S.substr(S.find(',') + 1);
	}
	return res;
}
void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM)
{
	cerr << "\n";
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T)
{
	if (idx > 0)
		cerr << ", ";
	else
		cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss;
	ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DEBUG
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

ll fpow(ll a, ll x)
{
	if (x <= 1)
		return ll(pow(a, x)) % MOD;
	ll b = fpow(a, x >> 1);
	return (((b * b) % MOD) * ll(pow(a, x & 1))) % MOD;
}

int fpow(int a, int x)
{
	if (x <= 1)
		return int(pow(a, x)) % MOD;
	int b = fpow(a, x >> 1);
	return (((b * b) % MOD) * int(pow(a, x & 1))) % MOD;
}

vi primes;
void sieve(int n)
{
	primes.clear();

	bool A[n + 2] = {false};
	int j;

	for (int i = 3; i < n + 2; i += 2)
	{
		if (!A[i])
		{
			j = 2 * i;
			while (j < n + 2)
			{
				A[j] = true;
				j += i;
			}
		}
	}

	primes.pb(2);
	for (int i = 3; i < n + 2; i += 2)
		if (!A[i])
			primes.pb(i);
}

struct BIT
{
	vector<int> tree;
	int n;
	BIT(vi A)
	{
		int p, sum = 0;
		n = A.size();
		for (int i = 0; i < n; ++i)
		{
			p = (i + 1) & -(i + 1);
			for (int j = i - p + 1; j <= i; ++j)
				sum += A[j];
			tree.pb(sum);
		}
	}
	int sum(int i)
	{
		int S = 0;
		++i;
		while (i)
		{
			S += tree[i - 1];
			i -= i & -i;
		}
		return S;
	}
	void update(int i, int change)
	{
		++i;
		while (i <= n)
		{
			tree[i - 1] += change;
			i += i & -i;
		}
	}
};

struct FSegTree
{
	vi tree;
	function<int(int, int)> F;
	int INF;

	FSegTree(vi A, int inf, function<int(int, int)> lambda)
	{
		tree.resize(4 * A.size());
		F = lambda;
		INF = inf;
		build(A);
	}

	void build(vi &A, int v = 1, int l = 0, int r = -1)
	{
		if (r == -1)
			r = A.size() - 1;
		if (l == r)
			tree[v] = A[l];
		else
		{
			int mid = (l + r) / 2;
			build(A, 2 * v, l, mid);
			build(A, 2 * v + 1, mid + 1, r);
			tree[v] = F(tree[2 * v], tree[2 * v + 1]);
		}
	}

	int query(int l, int r, int v = 1, int tl = 0, int tr = -1)
	{
		if (tr == -1)
			tr = tree.size() / 4 - 1;
		if (l > r)
			return F(INF, INF);
		if (l == tl && r == tr)
			return tree[v];
		int mid = (tl + tr) / 2;
		return F(query(l, min(r, mid), 2 * v, tl, mid), query(max(l, mid + 1), r, 2 * v + 1, mid + 1, tr));
	}

	void update(int pos, int val, int v = 1, int tl = 0, int tr = -1)
	{
		if (tr == -1)
			tr = tree.size() / 4 - 1;
		if (tl == tr)
			tree[v] = val;
		else
		{
			int mid = (tl + tr) / 2;
			if (pos <= mid)
				update(pos, val, 2 * v, tl, mid);
			else
				update(pos, val, 2 * v + 1, mid + 1, tr);
			tree[v] = F(tree[2 * v], tree[2 * v + 1]);
		}
	}
};

int main()
{
	fast;

	in(int, n);
	vpi points(n);
	vi vels(n);
	for (auto &point : points)
		cin >> point.f;
	forp(int, i, 0, n)
	{
		cin >> points[i].s;
		vels[i] = points[i].s;
	}
	sort(all(points));
	sort(all(vels));
	BIT *counts = new BIT(vi(n, 0)), *pos = new BIT(vi(n, 0));
	ll ans = 0;
	for (auto p : points)
	{
		int i = lower_bound(all(vels), p.s) - vels.begin();
		ans += counts->sum(i) * 1ll * p.f - pos->sum(i);
		counts->update(i, 1);
		pos->update(i, p.f);
		debug(p, counts->tree, pos->tree);
	}
	cout << ans;

	return 0;
}
