#include <bits/stdc++.h>
using namespace std;
long long ft[200001];
long long ft1[200001];
long long query(int a) {
  long long res = 0;
  for (; a; a -= a & -a) {
    res += ft[a];
  }
  return res;
}
int query1(int a) {
  int res = 0;
  for (; a; a -= a & -a) {
    res += ft1[a];
  }
  return res;
}
void update1(int a, int addend) {
  for (; a <= 200000; a += a & -a) {
    ft1[a] += addend;
  }
}
void update(int a, int addend) {
  for (; a <= 200000; a += a & -a) {
    ft[a] += addend;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> pt(n);
  map<int, int> ndx;
  for (auto& i : pt) {
    cin >> i.first;
  }
  for (auto& i : pt) {
    cin >> i.second;
    ndx[i.second] = 0;
  }
  int ct = 0;
  for (auto& i : ndx) {
    i.second = ++ct;
  }
  sort(pt.begin(), pt.end());
  for (auto i : pt) {
    int tmp = ndx[i.second];
    update(tmp, i.first);
    update1(tmp, 1);
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    int tmp = ndx[pt[i].second];
    update(tmp, -pt[i].first);
    update1(tmp, -1);
    ans += query(ct) - query(tmp - 1) -
           (query1(ct) - query1(tmp - 1)) * pt[i].first;
  }
  cout << ans << '\n';
}
