#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n;
pair<long long, long long> p[N];
long long ans, t[N << 2][2];
long long get(long long l, long long r, int type, int v = 1, int tl = 1,
              int tr = N - 100) {
  if (l > r) return 0;
  if (tl == l && tr == r) return t[v][type];
  long long tm = l + r >> 1;
  return get(l, min(tm, r), type, v + v, tl, tm) +
         get(max(tm + 1, l), r, type, v + v + 1, tm + 1, tr);
}
void upd(long long pos, long long val, int type, int v = 1, int tl = 1,
         int tr = N - 100) {
  if (tl == tr)
    t[v][type] += val;
  else {
    long long tm = tl + tr >> 1;
    if (pos <= tm)
      upd(pos, val, type, v + v, tl, tm);
    else
      upd(pos, val, type, v + v + 1, tm + 1, tr);
    t[v][type] = t[v + v][type] + t[v + v + 1][type];
  }
}
void compress() {
  set<long long> st;
  for (int i = 0; i < n; i++) st.insert(p[i].second);
  map<long long, long long> mp;
  long long cur = 1;
  for (long long i : st) mp[i] = cur++;
  for (int i = 0; i < n; i++) p[i].second = mp[p[i].second];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &p[i].first);
  for (int i = 0; i < n; i++) scanf("%lld", &p[i].second);
  compress();
  sort(p, p + n);
  for (int i = 0; i < n; i++) {
    long long x = p[i].first, v = p[i].second;
    long long sum_before = get(1, v, 0), num_before = get(1, v, 1);
    ans += x * num_before - sum_before;
    upd(v, x, 0);
    upd(v, 1, 1);
  }
  printf("%lld", ans - 1);
}
