#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long long __gcd(long long a, long long b) {
  while (a != 0) {
    long long __t = b % a;
    b = a;
    a = __t;
  }
  return b;
}
struct Tree {
  unsigned N;
  vector<int> t;
  Tree(unsigned N) : N(N), t(N) {}
  long long sum(long long r) {
    long long result = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
    return result;
  }
  void inc(long long i, long long delta) {
    for (; i < N; i = (i | (i + 1))) t[i] += delta;
  }
  int sum(long long l, long long r) { return sum(r) - sum(l - 1); }
  void clear() { fill(t.begin(), t.end(), 0); }
};
int main() {
  cin.tie();
  cout.tie();
  cerr.tie();
  ios_base::sync_with_stdio(false);
  unsigned N;
  cin >> N;
  vector<pair<int, int> > p(N);
  for (unsigned i = 0; i < N; i++) cin >> p[i].first;
  map<int, int> rv;
  for (unsigned i = 0; i < N; i++) {
    cin >> p[i].second;
    rv[p[i].second] = 0;
  }
  unsigned K = 0;
  for (auto& v : rv) v.second = ++K;
  for (auto& v : p) v.second = rv[v.second];
  Tree cnt(K + 1);
  Tree sum(K + 1);
  sort(p.begin(), p.end());
  unsigned ans = 0;
  for (unsigned i = 0, su = 0; i < N; i++) {
    unsigned c = cnt.sum(0, p[i].second);
    unsigned s = sum.sum(0, p[i].second);
    ans += c * p[i].first - s;
    cnt.inc(p[i].second, 1);
    sum.inc(p[i].second, p[i].first);
  }
  cout << ans;
  return 0;
}
