#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long oo = 1e18 + 7;
const int BASE = 10000;
void solve() {
  int n;
  cin >> n;
  vector<int> x(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  vector<int> pos(n + 1);
  iota(1 + (pos).begin(), (pos).end(), 1);
  sort(1 + (pos).begin(), (pos).end(),
       [&](int a, int b) { return x[a] < x[b]; });
  vector<int> val = v;
  sort(1 + (val).begin(), (val).end());
  val.resize(unique((val).begin(), (val).end()) - val.begin());
  map<int, int> Pos;
  for (int i = 1; i < val.size(); i++) {
    Pos[val[i]] = i;
  }
  vector<pair<long long, long long> > BIT(val.size());
  auto update = [&](int pos, int _val) {
    for (int i = pos; i < BIT.size(); i += i & -i) {
      BIT[i].first += 1LL * _val;
      BIT[i].second++;
    }
  };
  auto get = [&](int pos) {
    long long res = 0, cnt = 0;
    for (int i = pos; i; i -= i & -i) {
      res += BIT[i].first;
      cnt += BIT[i].second;
    }
    pair<long long, long long> t = {res, cnt};
    return t;
  };
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    pair<long long, long long> cur = get(Pos[v[pos[i]]]);
    res += x[pos[i]] * cur.second - cur.first;
    update(Pos[v[pos[i]]], x[pos[i]]);
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  solve();
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\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;
const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long oo = 1e18 + 7;
const int BASE = 10000;
void solve() {
  int n;
  cin >> n;
  vector<int> x(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  vector<int> pos(n + 1);
  iota(1 + (pos).begin(), (pos).end(), 1);
  sort(1 + (pos).begin(), (pos).end(),
       [&](int a, int b) { return x[a] < x[b]; });
  vector<int> val = v;
  sort(1 + (val).begin(), (val).end());
  val.resize(unique((val).begin(), (val).end()) - val.begin());
  map<int, int> Pos;
  for (int i = 1; i < val.size(); i++) {
    Pos[val[i]] = i;
  }
  vector<pair<long long, long long> > BIT(val.size());
  auto update = [&](int pos, int _val) {
    for (int i = pos; i < BIT.size(); i += i & -i) {
      BIT[i].first += 1LL * _val;
      BIT[i].second++;
    }
  };
  auto get = [&](int pos) {
    long long res = 0, cnt = 0;
    for (int i = pos; i; i -= i & -i) {
      res += BIT[i].first;
      cnt += BIT[i].second;
    }
    pair<long long, long long> t = {res, cnt};
    return t;
  };
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    pair<long long, long long> cur = get(Pos[v[pos[i]]]);
    res += x[pos[i]] * cur.second - cur.first;
    update(Pos[v[pos[i]]], x[pos[i]]);
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  solve();
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}

```