#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[200005];
int sum[1000005], cnt[1000005];
int querysum(int pos) {
  int ret = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    ret += sum[pos];
  }
  return ret;
}
int querycnt(int pos) {
  int ret = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    ret += cnt[pos];
  }
  return ret;
}
void updatesum(int pos, int val) {
  for (; pos < 1000000; pos |= pos + 1) {
    sum[pos] += val;
  }
}
void updatecnt(int pos, int val) {
  for (; pos < 1000000; pos |= pos + 1) {
    cnt[pos] += val;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].first;
  for (int i = 1; i <= n; i++) cin >> a[i].second;
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    v.push_back(a[i].second);
  }
  sort(v.begin(), v.end());
  map<int, int> num;
  for (int i = 0; i < v.size(); i++) {
    num[v[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i].second = num[a[i].second];
  }
  sort(a + 1, a + n + 1);
  memset(sum, 0, sizeof(sum));
  memset(cnt, 0, sizeof(cnt));
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a[i].first * querycnt(a[i].second) - querysum(a[i].second);
    updatesum(a[i].second, a[i].first);
    updatecnt(a[i].second, 1);
  }
  cout << ans << endl;
  return 0;
}
