#include <bits/stdc++.h>
using namespace std;
inline int lowbit(int x) { return x & -x; }
const int MAXN = 2e5 + 5;
int f1[MAXN << 2], f2[MAXN << 2];
pair<int, int> a[MAXN];
int lsh[MAXN];
int n;
long long sum(int x, int *arr) {
  long long ret = 0;
  while (x > 0) {
    ret += arr[x];
    x -= lowbit(x);
  }
  return ret;
}
long long add(int x, int d, int *arr) {
  while (x <= n) {
    arr[x] += d;
    x += lowbit(x);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
    lsh[i] = a[i].second;
  }
  sort(lsh, lsh + n);
  for (int i = 0; i < n; i++) {
    a[i].second = lower_bound(lsh, lsh + n, a[i].second) - lsh + 1;
  }
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long tmp1 = sum(a[i].second, f1);
    long long tmp2 = sum(a[i].second, f2);
    ans += tmp1 * a[i].first - tmp2;
    add(a[i].second, 1, f1);
    add(a[i].second, a[i].first, f2);
  }
  cout << ans << endl;
  return 0;
}
