#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n, m;
long long ans = 0;
struct node {
  int l;
  int r;
  long long cnt;
  long long sum;
} tree[400010];
struct no {
  int pos;
  int speed;
} a[200010];
bool cmp(no c, no d) { return c.pos < d.pos; }
void build(int p, int l, int r) {
  tree[p].l = l, tree[p].r = r;
  tree[p].cnt = tree[p].sum = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
}
void update(int p, int po, int v) {
  int l = tree[p].l, r = tree[p].r;
  if (l == r) {
    tree[p].cnt++;
    tree[p].sum += v;
    return;
  }
  int mid = (l + r) >> 1;
  if (po <= mid)
    update(p << 1, po, v);
  else
    update(p << 1 | 1, po, v);
  tree[p].cnt = tree[p << 1].cnt + tree[p << 1 | 1].cnt;
  tree[p].sum = tree[p << 1].sum + tree[p << 1 | 1].sum;
}
int query1(int p, int L, int R) {
  int l = tree[p].l, r = tree[p].r;
  if (l == r || (L <= l && R >= r)) return tree[p].cnt;
  int res = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) res += query1(p << 1, L, R);
  if (R > mid) res += query1(p << 1 | 1, L, R);
  return res;
}
int query2(int p, int L, int R) {
  int l = tree[p].l, r = tree[p].r;
  if (l == r || (L <= l && R >= r)) return tree[p].sum;
  long long res = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) res += query2(p << 1, L, R);
  if (R > mid) res += query2(p << 1 | 1, L, R);
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].pos);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].speed);
    v.push_back(a[i].speed);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 1; i <= n; i++)
    a[i].speed = lower_bound(v.begin(), v.end(), a[i].speed) - v.begin() + 1;
  sort(a + 1, a + n + 1, cmp);
  build(1, 1, v.size());
  for (int i = 1; i <= n; i++) {
    long long sum1 = 0, sum2 = 0;
    sum1 = query1(1, 1, a[i].speed);
    sum2 = query2(1, 1, a[i].speed);
    ans += a[i].pos * (sum1 + 1) - sum2 - a[i].pos;
    update(1, a[i].speed, a[i].pos);
  }
  printf("%lld", ans);
  return 0;
}
