#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 1;
long long int n, compressV[mx];
pair<long long int, long long int> v[mx], x[mx];
long long int sumBIT[mx] = {0}, cntBIT[mx] = {0};
long long int getSum(long long int BIT[], int ind) {
  long long int sum = 0;
  while (ind > 0) {
    sum += BIT[ind];
    ind -= ind & (-ind);
  }
  return sum;
}
void update(int index) {
  int ind = compressV[x[index].second];
  while (ind <= n) {
    sumBIT[ind] += x[index].first;
    cntBIT[ind] += 1;
    ind += ind & (-ind);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int y;
    cin >> y;
    x[i] = {y, i};
  }
  sort(x + 1, x + n + 1);
  int temp[mx];
  for (int i = 1; i <= n; i++) {
    temp[x[i].second] = i;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    v[temp[i]] = {x, i};
  }
  sort(v + 1, v + n + 1);
  int cur = 1;
  for (int i = 1; i <= n; i++) {
    compressV[v[i].second] = i;
    i += 1;
    while (i <= n && v[i].first == v[i - 1].first) {
      compressV[v[i++].second] = cur;
    }
    i -= 1;
    cur += 1;
  }
  long long int ans = 0;
  int temp1[mx];
  for (int i = 1; i <= n; i++) temp1[compressV[x[i].second]] = x[i].second;
  for (int i = n; i > 0; i--) {
    ans += getSum(sumBIT, n) - getSum(sumBIT, compressV[x[i].second] - 1) -
           x[i].first *
               (getSum(cntBIT, n) - getSum(cntBIT, compressV[x[i].second] - 1));
    update(i);
  }
  cout << ans << endl;
  return 0;
}
