#include <bits/stdc++.h>
using namespace std;
int n;
void update(vector<long long> &b, int ind, int numb) {
  for (int i = ind; i < b.size(); i = ((i + 1) | i)) b[i] += numb;
}
int Sum(vector<long long> &b, int ind) {
  int ans = 0;
  for (int i = ind; i >= 0; i = ((i + 1) & i) - 1) ans += b[i];
  return ans;
}
int sum(vector<long long> &b, int l, int r) {
  return Sum(b, r) - (l > 0 ? Sum(b, l - 1) : 0);
}
bool comp(pair<int, int> c, pair<int, int> d) {
  if (c.second < d.second) return true;
  return false;
}
int main() {
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; ++i) cin >> a[i].first;
  for (int i = 0; i < n; ++i) cin >> a[i].second;
  sort(a.begin(), a.end(), comp);
  int k = 1, temp = -1e9;
  for (int i = 0; i < n; ++i)
    if (temp == a[i].second) {
      a[i].second = k;
    } else {
      a[i].second = ++k;
      temp = a[i].second;
    }
  sort(a.begin(), a.end());
  long long ans = 0;
  vector<long long> sumx(k + 2, 0), sumv(k + 2, 0);
  for (int i = 0; i < n; ++i) {
    int ind = a[i].second;
    ans += Sum(sumv, ind) * 1ll * a[i].first - Sum(sumx, ind);
    update(sumv, ind, 1);
    update(sumx, ind, a[i].first);
  }
  cout << ans;
  return 0;
}
