#include <bits/stdc++.h>
using namespace std;
const long long mx = 105;
const long long mod = 1000000007;
const long long maxn = 1e17;
vector<long long> v1;
vector<long long> v2;
long long get(long long x, long long vt) {
  long long i, j, k;
  long long res = 0;
  for (i = x; i > 0; i -= (i & -i)) {
    if (vt == 1) {
      res += v1[i];
    } else {
      res += v2[i];
    }
  }
  return res;
}
void upd(long long x, long long vt, long long val) {
  long long i, j, k;
  long long si = (vt == 1 ? (int)v1.size() : (int)v2.size());
  for (i = x; i < si; i += (i & -i)) {
    if (vt == 1) {
      v1[i] += val;
    } else {
      v2[i] += val;
    }
  }
}
void solve() {
  long long n, i, j, k;
  cin >> n;
  long long x[n + 1], v[n + 1];
  vector<pair<long long, long long>> v4;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (i = 1; i <= n; i++) {
    v4.push_back({x[i], v[i]});
  }
  sort(v4.begin(), v4.end());
  for (i = 1; i <= n; i++) {
    x[i] = v4[i - 1].first;
    v[i] = v4[i - 1].second;
  }
  vector<long long> disx;
  for (i = 1; i <= n; i++) {
    disx.push_back(v[i]);
  }
  sort(disx.begin(), disx.end());
  disx.resize(unique(disx.begin(), disx.end()) - disx.begin());
  v1.resize(disx.size() + 1);
  v2.resize(disx.size() + 1);
  long long res = 0;
  for (i = 1; i <= n; i++) {
    long long pos = lower_bound(disx.begin(), disx.end(), v[i]) - disx.begin();
    res += get(pos + 1, 1) * x[i] - get(pos + 1, 2);
    upd(pos + 1, 1, 1);
    upd(pos + 1, 2, x[i]);
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}

### 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 long long mx = 105;
const long long mod = 1000000007;
const long long maxn = 1e17;
vector<long long> v1;
vector<long long> v2;
long long get(long long x, long long vt) {
  long long i, j, k;
  long long res = 0;
  for (i = x; i > 0; i -= (i & -i)) {
    if (vt == 1) {
      res += v1[i];
    } else {
      res += v2[i];
    }
  }
  return res;
}
void upd(long long x, long long vt, long long val) {
  long long i, j, k;
  long long si = (vt == 1 ? (int)v1.size() : (int)v2.size());
  for (i = x; i < si; i += (i & -i)) {
    if (vt == 1) {
      v1[i] += val;
    } else {
      v2[i] += val;
    }
  }
}
void solve() {
  long long n, i, j, k;
  cin >> n;
  long long x[n + 1], v[n + 1];
  vector<pair<long long, long long>> v4;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (i = 1; i <= n; i++) {
    v4.push_back({x[i], v[i]});
  }
  sort(v4.begin(), v4.end());
  for (i = 1; i <= n; i++) {
    x[i] = v4[i - 1].first;
    v[i] = v4[i - 1].second;
  }
  vector<long long> disx;
  for (i = 1; i <= n; i++) {
    disx.push_back(v[i]);
  }
  sort(disx.begin(), disx.end());
  disx.resize(unique(disx.begin(), disx.end()) - disx.begin());
  v1.resize(disx.size() + 1);
  v2.resize(disx.size() + 1);
  long long res = 0;
  for (i = 1; i <= n; i++) {
    long long pos = lower_bound(disx.begin(), disx.end(), v[i]) - disx.begin();
    res += get(pos + 1, 1) * x[i] - get(pos + 1, 2);
    upd(pos + 1, 1, 1);
    upd(pos + 1, 2, x[i]);
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}

```