#include <bits/stdc++.h>
using namespace std;
int a1[5000005];
void update(int index, int value) {
  while (index > 0) {
    a1[index] += value;
    index -= index & (-index);
  }
}
int query(int index) {
  int sum = 0;
  while (index < 5000005) {
    sum += a1[index];
    index += index & (-index);
  }
  return sum;
}
int main() {
  int N;
  cin >> N;
  long long int ans = 0;
  memset(a1, 0, sizeof a1);
  pair<int, int> a[N];
  long long int cnt[N], pre[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i].first;
  }
  set<int> s1;
  for (int i = 0; i < N; i++) {
    cin >> a[i].second;
    s1.insert(a[i].second);
  }
  int t1 = 0;
  map<int, int> mp;
  for (auto K : s1) {
    t1++;
    mp[K] = t1;
  }
  sort(a, a + N);
  for (int i = 0; i < N; i++) {
    update(mp[a[i].second], 1);
  }
  for (int i = 0; i < N; i++) {
    cnt[i] = query(mp[a[i].second]);
    update(mp[a[i].second], -1);
  }
  memset(a1, 0, sizeof a1);
  for (int i = 0; i < N; i++) {
    update(mp[a[i].second], a[i].first);
  }
  for (int i = 0; i < N; i++) {
    pre[i] = query(mp[a[i].second]);
    update(mp[a[i].second], -1 * a[i].first);
  }
  for (int i = 0; i < N; i++) {
    ans += pre[i] - cnt[i] * a[i].first;
  }
  cout << ans << '\n';
  return 0;
}
