#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(T &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  read(x);
  read(args...);
}
template <typename T>
inline void write(T x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
int N;
struct Z {
  int x, v, idx;
} A[200005];
long long bit[200005];
int cbit[200005];
void add(int n, int v) {
  for (; n <= N; n += n & -n) bit[n] += v, cbit[n]++;
}
void get(int s, int e, long long &sum, int &cnt) {
  sum = cnt = 0;
  for (; e; e ^= e & -e) sum += bit[e], cnt += cbit[e];
  for (s--; s; s ^= s & -s) sum -= bit[s], cnt -= cbit[s];
}
int main() {
  read(N);
  for (int i = 1; i <= N; i++) read(A[i].x);
  for (int i = 1; i <= N; i++) read(A[i].v);
  sort(A + 1, A + N + 1, [](const Z &a, const Z &b) { return a.x < b.x; });
  for (int i = 1; i <= N; i++) A[i].idx = i;
  sort(A + 1, A + N + 1, [](const Z &a, const Z &b) { return a.v < b.v; });
  long long ans = 0;
  for (int i = N; i; i--) {
    add(A[i].idx, A[i].x);
    long long sum = 0;
    int cnt = 0;
    get(A[i].idx + 1, N, sum, cnt);
    ans += sum - (long long)A[i].x * cnt;
  }
  write(ans);
  puts("");
}
