#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.x == b.x ? a.v < b.v : a.x < b.x;
  }
} a[maxn];
long long num[maxn << 2], sum[maxn << 2], ans, mx[maxn << 2];
void pushup(int rt) {
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  num[rt] = num[rt << 1] + num[rt << 1 | 1];
  mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
}
void modify(int l, int r, int rt, int pos, long long v, long long w) {
  if (l == r) {
    num[rt] += 1;
    sum[rt] += v;
    mx[rt] = w;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    modify(l, mid, rt << 1, pos, v, w);
  else
    modify(mid + 1, r, rt << 1 | 1, pos, v, w);
  pushup(rt);
}
long long query(int l, int r, int rt, long long v, long long w) {
  if (l == r) {
    if (mx[rt] <= v)
      return abs(sum[rt] - num[rt] * w);
    else
      return 0;
  }
  int mid = l + r >> 1;
  long long ret = 0;
  ret += query(l, mid, rt << 1, v, w);
  ret += query(mid + 1, r, rt << 1 | 1, v, w);
  return ret;
}
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);
  for (int i = 1; i <= n; i++) {
    ans += query(1, i, 1, a[i].v, a[i].x);
    modify(1, n, 1, i, a[i].x, a[i].v);
  }
  printf("%lld", ans);
  return 0;
}
