#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
long long n;
pair<long long, long long> x[N];
long long m;
map<long long, long long> mp;
long long ans;
struct seg {
  long long vals[2 * N];
  long long q(long long l, long long r) {
    long long ret = 0;
    for (l += m, r += m; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ret += vals[l++];
      if (r & 1) ret += vals[--r];
    }
    return ret;
  }
  void inc(long long i, long long v) {
    i += m;
    vals[i] += v;
    while (i > 1) {
      vals[i >> 1] = vals[i] + vals[i ^ 1];
      i >>= 1;
    }
  }
} sm, ct;
bool compSecond(pair<long long, long long>& a, pair<long long, long long>& b) {
  return a.second < b.second;
}
void doMapping() {
  sort(x, x + n, compSecond);
  long long prev = -1;
  for (long long i = 0; i < n; ++i) {
    if (x[i].second != prev) {
      mp[x[i].second] = m;
      m++;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> x[i].first;
  }
  for (long long i = 0; i < n; ++i) {
    cin >> x[i].second;
  }
  doMapping();
  sort(x, x + n);
  for (long long i = 0; i < n; ++i) {
    long long pt = x[i].first;
    long long cur = mp[x[i].second];
    long long cur_sum = sm.q(0, cur + 1), cur_ct = ct.q(0, cur + 1);
    ans += pt * cur_ct - cur_sum;
    sm.inc(cur, pt);
    ct.inc(cur, 1);
  }
  cout << ans << '\n';
  return 0;
}
