#include <bits/stdc++.h>
long long *pos = new long long[(int)(2e5 + 5)],
          *vel = new long long[(int)(2e5 + 5)];
using namespace std;
vector<int> perm;
long long solve(int le, int ri) {
  if (le == ri) {
    return 0;
  }
  if (le == ri - 1) {
    long long ans = 0;
    if (vel[perm[le]] <= vel[perm[ri]]) ans += (pos[perm[ri]] - pos[perm[le]]);
    return ans;
  }
  int mid = (le + ri) >> 1;
  long long ans = solve(le, mid) + solve(mid + 1, ri);
  vector<int> left(perm.begin() + le, perm.begin() + mid + 1),
      right(perm.begin() + mid + 1, perm.begin() + ri + 1);
  sort(left.begin(), left.end(), [](int a, int b) { return vel[a] < vel[b]; });
  sort(right.begin(), right.end(),
       [](int a, int b) { return vel[a] < vel[b]; });
  vector<long long> lpre;
  long long sum = 0;
  for (int u : left) {
    sum += pos[u];
    lpre.push_back(sum);
  }
  long long a = 0, b = 0, oldb = 0;
  int same = 0;
  while (b < right.size()) {
    if (vel[right[b]] < vel[left[a]])
      b++;
    else {
      while ((a + 1) < left.size() && vel[right[b]] >= vel[left[a + 1]]) a++;
      ans += ((a + 1) * pos[right[b]] - lpre[a]);
      b++;
      if (a + 1 < right.size()) a++;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> pos[i];
  for (int i = 0; i < n; i++) cin >> vel[i];
  for (int i = 0; i < n; i++) perm.push_back(i);
  sort(perm.begin(), perm.end(), [](int a, int b) { return pos[a] < pos[b]; });
  cout << solve(0, n - 1);
}
