#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const int xn = 2e5 + 10;
const int xm = 5e5;
const int SQ = 320;
const int sq = 1e3 + 10;
const long long inf = 1e18 + 10;
long long power(long long a, long long b) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2) % md
                      : power(a * a % md, b / 2) % md));
}
int n;
pair<long long, long long> X[xn];
long long x[xn], v[xn], PS[sq][sq], ans;
vector<pair<long long, int> > vec[sq];
void Get(int l, int r, int ind) {
  for (int i = l; i <= r;) {
    if (i % SQ == 0 && i + SQ - 1 <= r) {
      int L = -1, R = vec[i / SQ].size(), mid;
      while (R - L > 1) {
        mid = (L + R) / 2;
        if (vec[i / SQ][mid].first <= v[ind])
          L = mid;
        else
          R = mid;
      }
      if (L == -1) {
        i += SQ;
        continue;
      }
      long long s = 0;
      s += PS[i / SQ][L];
      s -= x[ind] * (L + 1);
      if (v[ind] >= 0) s = -s;
      ans += s;
      i += SQ;
    } else {
      if (v[i] <= v[ind]) {
        if (v[ind] >= 0)
          ans -= x[i] - x[ind];
        else
          ans -= x[ind] - x[i];
      }
      i++;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) X[i] = {x[i], v[i]};
  sort(X, X + n);
  for (int i = 0; i < n; i++) x[i] = X[i].first, v[i] = X[i].second;
  for (int i = 0; i < n; i++) vec[i / SQ].push_back({v[i], x[i]});
  for (int i = 0; i < n; i++) sort(vec[i].begin(), vec[i].end());
  for (int i = 0; i < sq; i++) {
    long long s = 0;
    for (int j = 0; j < vec[i].size(); j++) {
      s += vec[i][j].second;
      PS[i][j] = s;
    }
  }
  for (int i = 0; i < n; i++) {
    if (v[i] >= 0)
      Get(0, i - 1, i);
    else
      Get(i + 1, n - 1, i);
  }
  cout << ans << '\n';
  return 0;
}
