#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long maxn = 500010;
long long T, n, m, p[maxn], v[maxn], mxval = 0, tree[maxn], cnt[maxn], ans = 0;
struct node {
  int pos, val, v;
} a[maxn];
void add(int pos, long long val) {
  pos += n;
  cnt[pos] += 1;
  tree[pos] += val;
  while (pos) {
    pos /= 2;
    cnt[pos] = cnt[pos << 1] + cnt[pos << 1 | 1];
    tree[pos] = tree[pos << 1] + tree[pos << 1 | 1];
  }
}
pair<long long, long long> sum(int l, int r) {
  long long ret = 0, p = 0;
  for (l += n - 1, r += n + 1; l ^ r ^ 1; l /= 2, r /= 2) {
    if (~l & 1) ret += tree[l ^ 1], p += cnt[l ^ 1];
    if (r & 1) ret += tree[r ^ 1], p += cnt[r ^ 1];
  }
  return make_pair(p, ret);
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].pos);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].v);
  sort(a + 1, a + 1 + n, [](node a, node b) { return a.v < b.v; });
  a[1].val = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i].v > a[i - 1].v)
      a[i].val = a[i - 1].val + 1;
    else
      a[i].val = a[i - 1].val;
  }
  mxval = a[n].val;
  sort(a + 1, a + 1 + n, [](node a, node b) { return a.pos < b.pos; });
  memset(tree, 0, sizeof(tree));
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    pair<long long, long long> x = sum(1, a[i].val);
    ans += x.first * a[i].pos - x.second;
    add(a[i].val, a[i].pos);
  }
  memset(tree, 0, sizeof(tree));
  memset(cnt, 0, sizeof(cnt));
  for (int i = n; i >= 1; i--) {
    pair<long long, long long> x = sum(a[i].val, mxval);
    ans += x.second - x.first * a[i].pos;
    add(a[i].val, a[i].pos);
  }
  printf("%lld\n", ans / 2);
}

### Prompt

Your task is to create a CPP solution to the following problem:

There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ⋅ v_i.

Consider two points i and j. Let d(i, j) be the minimum possible distance between these two points over any possible moments of time (even non-integer). It means that if two points i and j coincide at some moment, the value d(i, j) will be 0.

Your task is to calculate the value ∑_{1 ≤ i < j ≤ n} d(i, j) (the sum of minimum distances over all pairs of points).

Input

The first line of the input contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of points.

The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^8), where x_i is the initial coordinate of the i-th point. It is guaranteed that all x_i are distinct.

The third line of the input contains n integers v_1, v_2, ..., v_n (-10^8 ≤ v_i ≤ 10^8), where v_i is the speed of the i-th point.

Output

Print one integer — the value ∑_{1 ≤ i < j ≤ n} d(i, j) (the sum of minimum distances over all pairs of points).

Examples

Input


3
1 3 2
-100 2 3


Output


3


Input


5
2 1 4 3 5
2 2 2 3 4


Output


19


Input


2
2 1
-3 0


Output


0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long maxn = 500010;
long long T, n, m, p[maxn], v[maxn], mxval = 0, tree[maxn], cnt[maxn], ans = 0;
struct node {
  int pos, val, v;
} a[maxn];
void add(int pos, long long val) {
  pos += n;
  cnt[pos] += 1;
  tree[pos] += val;
  while (pos) {
    pos /= 2;
    cnt[pos] = cnt[pos << 1] + cnt[pos << 1 | 1];
    tree[pos] = tree[pos << 1] + tree[pos << 1 | 1];
  }
}
pair<long long, long long> sum(int l, int r) {
  long long ret = 0, p = 0;
  for (l += n - 1, r += n + 1; l ^ r ^ 1; l /= 2, r /= 2) {
    if (~l & 1) ret += tree[l ^ 1], p += cnt[l ^ 1];
    if (r & 1) ret += tree[r ^ 1], p += cnt[r ^ 1];
  }
  return make_pair(p, ret);
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].pos);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].v);
  sort(a + 1, a + 1 + n, [](node a, node b) { return a.v < b.v; });
  a[1].val = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i].v > a[i - 1].v)
      a[i].val = a[i - 1].val + 1;
    else
      a[i].val = a[i - 1].val;
  }
  mxval = a[n].val;
  sort(a + 1, a + 1 + n, [](node a, node b) { return a.pos < b.pos; });
  memset(tree, 0, sizeof(tree));
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    pair<long long, long long> x = sum(1, a[i].val);
    ans += x.first * a[i].pos - x.second;
    add(a[i].val, a[i].pos);
  }
  memset(tree, 0, sizeof(tree));
  memset(cnt, 0, sizeof(cnt));
  for (int i = n; i >= 1; i--) {
    pair<long long, long long> x = sum(a[i].val, mxval);
    ans += x.second - x.first * a[i].pos;
    add(a[i].val, a[i].pos);
  }
  printf("%lld\n", ans / 2);
}

```