#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline long long read() {
  char ch = getchar();
  long long p = 1, data = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    data = (data << 3) + (data << 1) + (ch ^ 48);
    ch = getchar();
  }
  return p * data;
}
inline long long lowbit(long long a) { return a & (-a); }
inline long long qpow(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = a * r;
    a = a * a;
    b >>= 1;
  }
  return r;
}
inline long long gcd(long long a, long long b) {
  while (b ^= a ^= b ^= a %= b)
    ;
  return a;
}
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
inline long long inv(long long a, long long p) { return qpow(a, p - 2); }
const int maxn = 2e5 + 5;
struct node {
  long long x, v;
  friend bool operator<(node a, node b) {
    return a.v == b.v ? a.x < b.x : a.v < b.v;
  }
} a[maxn];
multiset<int> mp;
long long sum[maxn];
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) a[i].x = read();
  for (int i = 1; i <= n; i++) a[i].v = read();
  sort(a + 1, a + 1 + n);
  long long ans = 0, pre = a[1].x;
  mp.insert(a[1].x);
  sum[1] = a[1].x;
  multiset<int>::iterator it;
  for (int i = 2; i <= n; i++) {
    sum[i] = a[i].x + sum[i - 1];
    it = lower_bound(mp.begin(), mp.end(), a[i].x);
    long long pos = distance(mp.begin(), it);
    ans += abs(a[i].x * pos - sum[pos]);
    mp.insert(a[i].x);
  }
  printf("%lld", ans);
  return 0;
}
