#include <bits/stdc++.h>
using namespace std;
struct newdata {
  long long x, v, label;
};
int n;
long long tree1[200001];
long long tree2[200001];
newdata a[200001];
bool cmp1(newdata i, newdata j) { return i.x < j.x; }
bool cmp2(newdata i, newdata j) { return i.v < j.v; }
long long lowbit(long long x) { return x & (-x); }
long long count1(long long x) {
  long long sum = 0;
  while (x > 0) {
    sum += tree1[x];
    x -= lowbit(x);
  }
  return sum;
}
long long count2(long long x) {
  long long sum = 0;
  while (x > 0) {
    sum += tree2[x];
    x -= lowbit(x);
  }
  return sum;
}
void add1(long long x, long long v) {
  while (x <= n) {
    tree1[x] += v;
    x += lowbit(x);
  }
}
void add2(long long x, long long v) {
  while (x <= n) {
    tree2[x] += v;
    x += lowbit(x);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i].x);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i].v);
  sort(a + 1, a + n + 1, cmp1);
  int tot = 1;
  a[1].label = 1;
  for (int i = 2; i <= n; i++)
    if (a[i].x != a[i - 1].x)
      a[i].label = ++tot;
    else
      a[i].label = tot;
  sort(a + 1, a + n + 1, cmp2);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += count1(a[i].label - 1) * a[i].x - count2(a[i].label - 1);
    add1(a[i].label, 1);
    add2(a[i].label, a[i].x);
  }
  printf("%I64d", ans);
  return 0;
}
