#include <bits/stdc++.h>
using namespace std;
int X[200001];
int V[200001];
int xi[200001];
long long sums[200001];
int n;
struct cmp {
  bool operator()(int a, int b) { return X[a] < X[b]; }
};
int temp[200001];
long long merge(int s, int e) {
  int l = s, m = (s + e) / 2, r = m + 1, k = l;
  long long res = 0;
  while (l <= m && r <= e) {
    if (V[xi[l]] > V[xi[r]]) {
      int b = r - 1;
      res += (long long)(r - l) * X[xi[r]];
      while (b) {
        res -= sums[b];
        b -= b & -b;
      }
      b = l - 1;
      while (b) {
        res += sums[b];
        b -= b & -b;
      }
      int diff = X[temp[r]] - X[xi[k]];
      b = k;
      while (b <= n) {
        sums[b] += diff;
        b += b & -b;
      }
      diff = X[temp[k]] - X[xi[r]];
      b = r;
      while (b <= n) {
        sums[b] += diff;
        b += b & -b;
      }
      temp[k++] = xi[r++];
    } else {
      temp[k++] = xi[l++];
    }
  }
  while (l <= m) temp[k++] = xi[l++];
  while (r <= e) temp[k++] = xi[r++];
  for (int i = s; i <= e; ++i) {
    xi[i] = temp[i];
  }
  return res;
}
long long mergesort(int s, int e) {
  long long res = 0;
  if (s < e) {
    int m = (s + e) / 2;
    res = mergesort(s, m);
    res += mergesort(m + 1, e);
    res += merge(s, e);
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    xi[i] = i;
    cin >> X[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> V[i];
  }
  sort(xi + 1, xi + n + 1, cmp());
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    int b = i;
    while (b <= n) {
      sums[b] += X[xi[i]];
      b += b & -b;
    }
  }
  for (int i = 1; i <= n; ++i) {
    res += (long long)(i - 1) * X[xi[i]];
    int b = i - 1;
    while (b) {
      res -= sums[b];
      b -= b & -b;
    }
  }
  cout << res - mergesort(1, n);
  return 0;
}
