#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
const long long mod = 1e9 + 7;
const long long maxd = 4e5 + 10;
struct node {
  long long x, speed, id, z;
} a[maxd];
bool cmp(const node a, const node b) { return a.z < b.z; }
bool cmp1(const node a, const node b) { return a.x < b.x; }
long long t1[maxd], t2[maxd];
void add(long long *t, long long p, long long v) {
  for (; p < maxd; p += (p & (-p))) t[p] += v;
}
long long get(long long *t, long long p) {
  long long sum = 0;
  for (; p; p -= (p & (-p))) sum += t[p];
  return sum;
}
int main() {
  long long n;
  scanf("%lld", &n);
  for (register long long i = 1; i <= n; i++) scanf("%lld", &a[i].x);
  for (register long long i = 1; i <= n; i++) scanf("%lld", &a[i].speed);
  sort(a + 1, a + 1 + n, cmp1);
  for (register long long i = 1; i <= n; i++) a[i].id = i;
  for (register long long i = 1; i <= n; i++)
    a[i].z = 1000000 * a[i].speed + a[i].x;
  sort(a + 1, a + 1 + n, cmp);
  long long ans = 0ll;
  for (register long long i = 1; i <= n; i++) {
    long long num = get(t1, a[i].id);
    long long sum = get(t2, a[i].id);
    ans += num * a[i].x;
    ans -= sum;
    add(t1, a[i].id, 1);
    add(t2, a[i].id, a[i].x);
  }
  printf("%lld\n", ans);
  return 0;
}
