#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 7;
const long long top = 1e6 + 3;
struct node {
  long long xx, v;
};
long long a[maxn], b[maxn];
long long num[maxn], x[maxn];
vector<long long> v;
node t[maxn];
long long lowerbit(long long x) { return x & (-x); }
long long gets1(long long p) {
  long long ans = 0;
  for (long long i = p; i > 0; i -= lowerbit(i)) ans += x[i];
  return ans;
}
long long gets2(long long p) {
  long long ans = 0;
  for (long long i = p; i > 0; i -= lowerbit(i)) ans += num[i];
  return ans;
}
void update(long long* f, long long p, long long k) {
  for (long long i = p; i < top; i += lowerbit(i)) f[i] += k;
}
bool cmp(const node& a, const node& b) {
  if (a.v != b.v)
    return a.v < b.v;
  else
    return a.xx < b.xx;
}
long long getnum(long long x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;
}
signed main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &t[i].xx), v.push_back(t[i].xx);
  for (long long i = 1; i <= n; i++) scanf("%lld", &t[i].v);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (long long i = 1; i <= n; i++) t[i].xx = getnum(t[i].xx);
  sort(t + 1, t + n + 1, cmp);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    update(num, t[i].xx, 1);
    update(x, t[i].xx, t[i].xx);
    if (i == 1)
      continue;
    else {
      long long _n = gets2(t[i].xx);
      long long res = gets1(t[i].xx);
      ans += _n * t[i].xx - res;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
