#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 45;
const int lim = 1e8 + 3;
long long n;
pair<long long, long long> a[N];
long long drvo[15 * N], br[15 * N];
int ls[15 * N], rs[15 * N], tsz = 1, root = 1;
void update(int i, int j, int pos, int val, int &node) {
  if (!node) {
    node = ++tsz;
  }
  if (i == j) {
    drvo[node] += val;
    br[node]++;
    return;
  }
  int mid = i + (j - i) / 2;
  if (pos <= mid) {
    update(i, mid, pos, val, ls[node]);
  } else {
    update(mid + 1, j, pos, val, rs[node]);
  }
  drvo[node] = drvo[ls[node]] + drvo[rs[node]];
  br[node] = br[ls[node]] + br[rs[node]];
}
long long getsum(int i, int j, int l, int r, int node) {
  if (!node || j < l || i > r) {
    return 0;
  }
  if (l <= i && r >= j) {
    return drvo[node];
  }
  int mid = i + (j - i) / 2;
  return getsum(i, mid, l, r, ls[node]) + getsum(mid + 1, j, l, r, rs[node]);
}
long long getcnt(int i, int j, int l, int r, int node) {
  if (!node || j < l || i > r) {
    return 0;
  }
  if (l <= i && r >= j) {
    return br[node];
  }
  int mid = i + (j - i) / 2;
  return getcnt(i, mid, l, r, ls[node]) + getcnt(mid + 1, j, l, r, rs[node]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i].second;
  }
  sort(a + 1, a + n + 1);
  long long sol = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i].second < 0) {
      continue;
    }
    long long s = getsum(0, lim, a[i].second, lim, root),
              cnt = getcnt(0, lim, a[i].second, lim, root);
    sol += s - cnt * a[i].first;
    update(0, lim, a[i].second, a[i].first, root);
  }
  for (int i = 0; i < 15 * N; i++) {
    br[i] = drvo[i] = ls[i] = rs[i] = 0;
    tsz = 1;
  }
  for (long long i = n; i >= 1; i--) {
    if (a[i].second >= 0) {
      continue;
    }
    long long s = getsum(0, lim, -a[i].second, lim, root),
              cnt = getcnt(0, lim, -a[i].second, lim, root);
    sol += s - cnt * a[i].first;
    update(0, lim, -a[i].second, a[i].first, root);
  }
  long long sum = 0, cnt = 0;
  for (long long i = n; i >= 1; i--) {
    if (a[i].second >= 0) {
      cnt++;
      sum += a[i].first;
    } else {
      sol += sum - cnt * a[i].first;
    }
  }
  cout << sol << endl;
}
