#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end() /* a + all(x) - b */
#define makeUnique(vec) std::sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin())

#define in(name, type) type name; std::cin >> name
#define gin(var) std::cin >> var

#define LOG_vec(vec, sep) for (int fl = 0; fl < vec.size(); fl++) { std::cout << vec[fl] << sep; } std::cout << "\n"
#define LOG(x, sep) std::cout << x << sep
#define LOG(x) std::cout << x << "\n";

#define ll long long

int iin() { in(r, int); return r; }

struct Random {
	int lower, upper;
	Random() : lower(0), upper(10) { }
	Random(int l, int u) : lower(0), upper(10) { lower = l; upper = u; }
	void set(int l, int u) { lower = l; upper = u; }
	int get() { return rand() % upper + lower; }
} random;
int getRand() { return random.get(); }

void compile();

const bool isT = false;
#define imp LOG(NULL)

int main() {
	if (isT) {
		in(t, int);
		for (int i = 0; i < t; i++) { compile(); }
		return 0;
	}
	compile();
	return 0;
}

class Solution {

public:

	void run() {
		input();
		std::sort(all(x));
		std::sort(all(p));
		int r = 0;
		std::map <int, int> m;
		for (int i = 0; i < n; i++) { r += x[i] * (2 * i + 1 - n); m[x[i]] = i; }
		for (int i = 0; i < n; i++) { r -= p[i].x * (m[p[i].x] - i); }
		LOG(r);
	}

private:
	
	struct Point {
		int x, v;
		Point(int X, int V) { x = X; v = V; }
		bool operator<(const Point& a) const { if (v == a.v) { return x < a.x; } return v < a.v; }
	};

	int n;
	std::vector <int> x, v;
	std::vector <Point> p;
	void input() {
		gin(n);
		x.resize(n); v.resize(n);
		std::generate(all(x), iin);
		std::generate(all(v), iin);
		for (int i = 0; i < n; i++) { Point cp(x[i], v[i]); p.push_back(cp); }
	}

};

void compile() { Solution sol; sol.run(); }