#include <bits/stdc++.h>
using namespace std;
template <class T>
struct fen {
  vector<T> fenwick;
  long long size;
  fen(long long sz) {
    size = sz;
    fenwick.resize(size);
    for (long long i = 0; i < size; i++) fenwick[i] = 0;
  }
  fen(vector<T> arr) {
    size = arr.size();
    fenwick.resize(size);
    for (long long i = 0; i < size; i++) fenwick[i](0);
    for (long long i = 0; i < size; i++) update(i, arr[i]);
  }
  void add(long long index, T add) {
    for (long long k = index; k < size; k |= (~k & -~k)) {
      fenwick[k] = fenwick[k] + add;
    }
  }
  void update(long long index, T nval) {
    add(index, nval - rangeQuery(index, index));
  }
  T query(long long to) {
    if (to < 0) return 0;
    T sum = 0;
    for (long long curr = to + 1; curr > 0; curr ^= (curr & -curr)) {
      sum = sum + fenwick[curr - 1];
    }
    return sum;
  }
  T rangeQuery(long long from, long long to) {
    if (from > to) return 0;
    if (!from) return query(to);
    return query(to) - query(from - 1);
  }
  void prll() {
    for (long long i = 0; i < size; i++) cout << query(i) << " ";
    cout << endl;
  }
};
const long long sz = 2e5 + 5;
long long n;
pair<long long, long long> xv[sz];
vector<int> tmp;
map<int, int> rkspeed;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> xv[i].first;
  for (long long i = 0; i < n; i++) cin >> xv[i].second;
  sort(xv, xv + n);
  for (long long i = 0; i < n; i++) tmp.push_back(xv[i].second);
  sort(tmp.begin(), tmp.end());
  vector<int> t2{tmp[0]};
  for (long long i = 1; i < n; i++) {
    if (tmp[i] != t2.back()) t2.push_back(tmp[i]);
  }
  for (long long i = 0; i < t2.size(); i++) rkspeed[t2[i]] = i;
  fen<int> fcnt(n);
  fen<long long> sums(n);
  long long tot = 0;
  for (long long i = 0; i < n; i++) {
    int mrk = rkspeed[xv[i].second];
    long long bamt = fcnt.query(mrk);
    tot += bamt * xv[i].first - sums.query(mrk);
    fcnt.add(mrk, 1);
    sums.add(mrk, xv[i].first);
  }
  cout << tot;
  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;
template <class T>
struct fen {
  vector<T> fenwick;
  long long size;
  fen(long long sz) {
    size = sz;
    fenwick.resize(size);
    for (long long i = 0; i < size; i++) fenwick[i] = 0;
  }
  fen(vector<T> arr) {
    size = arr.size();
    fenwick.resize(size);
    for (long long i = 0; i < size; i++) fenwick[i](0);
    for (long long i = 0; i < size; i++) update(i, arr[i]);
  }
  void add(long long index, T add) {
    for (long long k = index; k < size; k |= (~k & -~k)) {
      fenwick[k] = fenwick[k] + add;
    }
  }
  void update(long long index, T nval) {
    add(index, nval - rangeQuery(index, index));
  }
  T query(long long to) {
    if (to < 0) return 0;
    T sum = 0;
    for (long long curr = to + 1; curr > 0; curr ^= (curr & -curr)) {
      sum = sum + fenwick[curr - 1];
    }
    return sum;
  }
  T rangeQuery(long long from, long long to) {
    if (from > to) return 0;
    if (!from) return query(to);
    return query(to) - query(from - 1);
  }
  void prll() {
    for (long long i = 0; i < size; i++) cout << query(i) << " ";
    cout << endl;
  }
};
const long long sz = 2e5 + 5;
long long n;
pair<long long, long long> xv[sz];
vector<int> tmp;
map<int, int> rkspeed;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> xv[i].first;
  for (long long i = 0; i < n; i++) cin >> xv[i].second;
  sort(xv, xv + n);
  for (long long i = 0; i < n; i++) tmp.push_back(xv[i].second);
  sort(tmp.begin(), tmp.end());
  vector<int> t2{tmp[0]};
  for (long long i = 1; i < n; i++) {
    if (tmp[i] != t2.back()) t2.push_back(tmp[i]);
  }
  for (long long i = 0; i < t2.size(); i++) rkspeed[t2[i]] = i;
  fen<int> fcnt(n);
  fen<long long> sums(n);
  long long tot = 0;
  for (long long i = 0; i < n; i++) {
    int mrk = rkspeed[xv[i].second];
    long long bamt = fcnt.query(mrk);
    tot += bamt * xv[i].first - sums.query(mrk);
    fcnt.add(mrk, 1);
    sums.add(mrk, xv[i].first);
  }
  cout << tot;
  return 0;
}

```