#include <bits/stdc++.h>
using namespace std;
long long n, a1[202020], a2[202020], od[202020];
pair<int, int> p[202020];
long long ans;
map<int, int> mp;
void gx1(int x, int v) {
  for (int i = x; i < 200200; i += i & -i) {
    a1[i] += v;
  }
}
void gx2(int x, int v) {
  for (int i = x; i < 200200; i += i & -i) {
    a2[i] += v;
  }
}
int gt1(int p) {
  int rt = 0;
  for (int i = p; i > 0; i -= i & -i) {
    rt += a1[i];
  }
  return rt;
}
int gt2(int p) {
  int rt = 0;
  for (int i = p; i > 0; i -= i & -i) {
    rt += a2[i];
  }
  return rt;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first;
  }
  for (int i = 1; i <= n; i++) {
    cin >> p[i].second;
    od[i] = p[i].second;
  }
  sort(od + 1, od + n + 1);
  sort(p + 1, p + n + 1);
  int pp = 1;
  for (int i = 1; i <= n; i++) {
    if (!mp[od[i]]) {
      mp[od[i]] = pp;
      pp++;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += 1ll * p[i].first * gt1(mp[p[i].second]) - 1ll * gt2(mp[p[i].second]);
    gx1(mp[p[i].second], 1);
    gx2(mp[p[i].second], p[i].first);
  }
  cout << ans << endl;
  return 0;
}
