#include <bits/stdc++.h>
using namespace std;
long long int MOD = 100000007;
long long int MX = 1000000000;
long long int n;
pair<long long int, long long int> a[200200];
map<long long int, long long int> sor;
map<long long int, long long int> val;
long long int fen[400400];
long long int fen1[400200];
void update(long long int pos, long long int val) {
  while (pos <= n) {
    fen[pos] += val;
    pos += pos & (-pos);
  }
}
long long int q(long long int pos) {
  int res = 0;
  while (pos > 0) {
    res += fen[pos];
    pos -= pos & (-pos);
  }
  return res;
}
void update1(long long int pos, long long int val) {
  while (pos <= n) {
    fen1[pos] += val;
    pos += pos & (-pos);
  }
}
long long int q1(long long int pos) {
  int res = 0;
  while (pos > 0) {
    res += fen1[pos];
    pos -= pos & (-pos);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].first;
  for (int i = 1; i <= n; i++) cin >> a[i].second;
  for (int i = n; i >= 1; i--) {
    sor[a[i].second]++;
  }
  map<long long int, long long int>::iterator itr;
  int cnt = 0;
  for (itr = sor.begin(); itr != sor.end(); itr++) {
    cnt++;
    val[itr->first] = cnt;
  }
  for (int i = 1; i <= n; i++) a[i].second = val[a[i].second];
  sort(a + 1, a + n + 1);
  long long int res = 0;
  for (int i = n; i >= 1; i--) {
    long long int sum = q(n) - q(a[i].second - 1);
    long long int sum1 = q1(n) - q1(a[i].second - 1);
    res += sum - sum1 * a[i].first;
    update(a[i].second, a[i].first);
    update1(a[i].second, 1);
  }
  cout << res << endl;
  return 0;
}
