#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template < typename T >
using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >; // less_equal for keeping duplicates
#define all(x) x.begin(), x.end()
#define pii pair < int, int >
#define pll pair < long long, long long >
#define f first
#define s second
#define mp(x, y) make_pair(x, y)
#define MASK bitset < 16 >

const int MAX = 2e5 + 2, mod = 1e9 + 7, shift = 1000;
map < int, int > v;

struct Node
{
	long long sum = 0;
	int count = 0;

	Node merge(const Node &l, const Node &r)
	{
		sum = l.sum + r.sum;
		count = l.count + r.count;
		return *this;
	}

}node[4 * MAX];

struct segTree
{
	Node query(int p, int s, int e, int qs, int qe)
	{
		if(qs > e || s > qe) return Node();
		else if(qs <= s && e <= qe) return node[p];
		else
		{
			Node ret;
			int mid = (s + e) >> 1;
			const auto left = query(2 * p + 1, s, mid, qs, qe);
			const auto right = query(2 * p + 2, mid + 1, e, qs, qe);
			//cout << s << " " << e << " " << qs << " " << qe << " " << ret.sum << " " << ret.count << "\n";
			return ret.merge(left, right);
		}
	}

	void update(int p, int s, int e, int idx, int val)
	{
		if(idx < s || e < idx) return;
		else if(s == e) node[p].sum += val, node[p].count++;
		else
		{
			int mid = (s + e) >> 1;
			update(2 * p + 1, s, mid, idx, val);
			update(2 * p + 2, mid + 1, e, idx, val);
			node[p].merge(node[2 * p + 1], node[2 * p + 2]);
		}

	}
};

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	long long ans = 0;
	vector < int > v;
	cin >> n;
	pii a[n];

	for(int i = 0; i < n; i++)
		cin >> a[i].f;

	for(int j = 0; j < n; j++)
		cin >> a[j].s, v.push_back(a[j].s);

	sort(a, a + n);
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	segTree tree;

	for(int i = n - 1; i >= 0; i--)
	{
		auto idx = lower_bound(all(v), a[i].s) - v.begin();
		tree.update(0, 0, n - 1, idx, a[i].f);
		auto sum = tree.query(0, 0, n - 1, idx, n - 1);
		//cout << sum.sum << " " << sum.count << "\n";
		ans += (sum.sum - a[i].f * sum.count);
	}

	cout << ans;
	return 0;
}
