#include <bits/stdc++.h>
using namespace std;
struct Node {
  int l, r;
  int cnt = 0;
  long long sum = 0;
  int left = -1;
  int right = -1;
} NIL;
vector<Node> st;
Node merge(Node x, Node y) {
  Node z;
  z.cnt = x.cnt + y.cnt;
  z.sum = x.sum + y.sum;
  return z;
}
void add(int u, int x, int v) {
  if (not(st[u].l <= v and v <= st[u].r)) return;
  if (st[u].l == v and v == st[u].r) {
    st[u].cnt += 1;
    st[u].sum += x;
    return;
  }
  int m = (st[u].l + st[u].r) >> 1;
  if (st[u].left == -1) {
    Node x;
    x.l = st[u].l, x.r = m;
    st[u].left = int(st.size());
    st.push_back(x);
  }
  if (st[u].right == -1) {
    Node x;
    x.l = m + 1, x.r = st[u].r;
    st[u].right = int(st.size());
    st.push_back(x);
  }
  add(st[u].left, x, v);
  add(st[u].right, x, v);
  Node s = merge(st[st[u].left], st[st[u].right]);
  st[u].sum = s.sum;
  st[u].cnt = s.cnt;
};
Node gteq(int u, int L, int R) {
  if (u == -1 or st[u].r < L or R < st[u].l) return NIL;
  if (L <= st[u].l and st[u].r <= R) return st[u];
  return merge(gteq(st[u].left, L, R), gteq(st[u].right, L, R));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > p(n);
  for (int i = 0; i < n; i++) cin >> p[i].first;
  for (int i = 0; i < n; i++) cin >> p[i].second;
  sort(begin(p), end(p));
  Node root;
  root.l = -1e8;
  root.r = 1e8;
  st.emplace_back(root);
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    Node s = gteq(0, p[i].second, 1e8);
    ans += s.sum - 1LL * s.cnt * p[i].first;
    add(0, p[i].first, p[i].second);
  }
  cout << ans << '\n';
  return (0);
}

### Prompt

Create a solution in CPP for 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;
struct Node {
  int l, r;
  int cnt = 0;
  long long sum = 0;
  int left = -1;
  int right = -1;
} NIL;
vector<Node> st;
Node merge(Node x, Node y) {
  Node z;
  z.cnt = x.cnt + y.cnt;
  z.sum = x.sum + y.sum;
  return z;
}
void add(int u, int x, int v) {
  if (not(st[u].l <= v and v <= st[u].r)) return;
  if (st[u].l == v and v == st[u].r) {
    st[u].cnt += 1;
    st[u].sum += x;
    return;
  }
  int m = (st[u].l + st[u].r) >> 1;
  if (st[u].left == -1) {
    Node x;
    x.l = st[u].l, x.r = m;
    st[u].left = int(st.size());
    st.push_back(x);
  }
  if (st[u].right == -1) {
    Node x;
    x.l = m + 1, x.r = st[u].r;
    st[u].right = int(st.size());
    st.push_back(x);
  }
  add(st[u].left, x, v);
  add(st[u].right, x, v);
  Node s = merge(st[st[u].left], st[st[u].right]);
  st[u].sum = s.sum;
  st[u].cnt = s.cnt;
};
Node gteq(int u, int L, int R) {
  if (u == -1 or st[u].r < L or R < st[u].l) return NIL;
  if (L <= st[u].l and st[u].r <= R) return st[u];
  return merge(gteq(st[u].left, L, R), gteq(st[u].right, L, R));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > p(n);
  for (int i = 0; i < n; i++) cin >> p[i].first;
  for (int i = 0; i < n; i++) cin >> p[i].second;
  sort(begin(p), end(p));
  Node root;
  root.l = -1e8;
  root.r = 1e8;
  st.emplace_back(root);
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    Node s = gteq(0, p[i].second, 1e8);
    ans += s.sum - 1LL * s.cnt * p[i].first;
    add(0, p[i].first, p[i].second);
  }
  cout << ans << '\n';
  return (0);
}

```