#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstddef>
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <memory>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <utility>
#include <array>
#include <tuple>
#include <initializer_list>
#include <bitset>
#include <type_traits>
#include <climits>
#include <cinttypes>
#include <limits>
#include <cassert>
#include <deque>
#include <queue>
#include <stack>
#include <random>


//#define pb push_back
//#define mp ::std::make_pair
#define forn(i,n)  for (int i = 0, z_n_n_y = (n); i <  z_n_n_y; ++i)
#define all(x)  ::std::begin(x), ::std::end(x)

using vi = std::vector<int>;
using pii = std::pair<int, int>;
using vii = std::vector<pii>;
using ll = long long;
constexpr int MOD = 1'000'000'000 + 7;

int solve();

int main(int argc, char* argv[])
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif //online-judge
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	int tc = 1;
	
//	std::cin >> tc;
	//scanf("%d", &tc);
	
	while (tc--) 
	{
		solve();
	}

	return 0;
}
using std::cin;
using std::endl;
using std::cout;
using std::string;
using std::vector;
constexpr int N = 205000;

struct segment_tree
{
	struct node
	{
		ll sum;
		int cnt;
		
		node() : sum(0), cnt(0) {}
		
		node(ll s, int n) : sum(s), cnt(n) {}

		friend node operator + (node a, node b) {
			return node(a.sum + b.sum, a.cnt + b.cnt);
		}
	};
	static constexpr int H = 1 << 18;
	
	vector<node> v;
	
	segment_tree() : v(H * 2) {}

	void add(int index, int x) {
		node d(x, 1);
		index += H;
		v[index] = v[index] + d;
		while (index > 1) {
			index /= 2;
			v[index] = v[index * 2] + v[index * 2 + 1];
		}
	}

	node get(int l, int r) {
		l += H, r += H;
		node result;
		for (; l < r; l >>= 1, r >>= 1) {
			if (l & 1) result = result + v[l++];
			if (r & 1) result = result + v[--r];
		}
		return result;
	}
};

int solve()
{
	int n;
	scanf("%d", &n);
	
	struct point
	{
		int x;
		int v;
		int ind;
	};
	vector<point> ps(n);
	
	forn(i, n) 
	{
		scanf("%d", &ps[i].x);
	}
	
	forn(i, n) 
	{
		scanf("%d", &ps[i].v);
	}

	std::sort(ps.begin(), ps.end(), [](point a, point b) { return a.x < b.x; } );

	//   x[i]  <  x[j]
	//   v[i]+    -v[j]    
	//  1. v[i]+  v[j]-  --> d(i,j) = 0

	// 2. v[i] +    v[j] +   
	//   2.1   v[i] <= v[j] --> d(i,j) = x[j] - x[i] ,   sum(x[j] - x[i]) = sum(x[j]) - count(x[j])*x[i]
	//   2.2   v[i] > v[j]   --> d(i,j) = 0

	// 3. v[i]-   v[j]+    d(i,j) = x[j] - x[i]
	// 4. v[i]-   v[j]- 
	//   4.1 |v[i]| <= |v[j]| --> d(i,j) = 0
	//   4.2 |v[i]| > |v[j]|  --> d(i,j) = x[j] - x[i]
	vector<int> v_uniq(n);
	forn(i, n)v_uniq[i] = std::abs(ps[i].v);
	std::sort(v_uniq.begin(), v_uniq.end());
	v_uniq.erase(std::unique(v_uniq.begin(), v_uniq.end()), v_uniq.end());
	
	forn(i, n) {
		ps[i].ind = std::lower_bound(v_uniq.begin(), v_uniq.end(), std::abs(ps[i].v)) - v_uniq.begin();
		ps[i].ind += 1;//start with 1.
	}

	
	segment_tree st_pos, st_neg;
	ll sum = 0;
	
	for (int i = n - 1; i >= 0; --i) 
	{
		int v = ps[i].v;
		int v_index = ps[i].ind;

		if (v < 0) {
			st_neg.add(v_index, ps[i].x);
		}
		else {
			st_pos.add(v_index, ps[i].x);
		}

		if (v >= 0) {
			auto d = st_pos.get(v_index, st_pos.H);
			sum += d.sum - ps[i].x * 1LL * d.cnt;
		}
		else {
			auto d = st_pos.v[1];//all
			sum += d.sum - ps[i].x * 1LL * d.cnt;

			d = st_neg.get(1, v_index);// less than v_index
			sum += d.sum - ps[i].x * 1LL * d.cnt;
		}
	}

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