#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> t;
pair<long long, long long> get(long long v, long long l, long long r,
                               long long a, long long b) {
  if (l > b || a > r) {
    return {0, 0};
  }
  if (a <= l && r <= b) {
    return t[v];
  }
  long long m = (l + r) / 2;
  pair<long long, long long> tmp = get(2 * v, l, m, a, b),
                             tmp2 = get(2 * v + 1, m + 1, r, a, b);
  return {tmp.first + tmp2.first, tmp.second + tmp2.second};
}
void update(long long v, long long l, long long r, long long i, long long x) {
  if (l > i || i > r) {
    return;
  }
  if (l == r) {
    t[v] = {t[v].first + x, t[v].second + 1};
    return;
  }
  long long m = (l + r) / 2;
  update(2 * v, l, m, i, x);
  update(2 * v + 1, m + 1, r, i, x);
  t[v].first = t[2 * v].first + t[2 * v + 1].first;
  t[v].second = t[2 * v].second + t[2 * v + 1].second;
}
signed main() {
  long long n;
  cin >> n;
  long long q = 1 << (long long)ceil(log2(n));
  t.resize(2 * q);
  vector<pair<long long, long long>> x(n);
  for (long long i = 0; i < n; ++i) {
    cin >> x[i].first;
  }
  for (long long i = 0; i < n; ++i) {
    cin >> x[i].second;
  }
  sort(x.begin(), x.end());
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) {
    a[i] = x[i].second;
  }
  unordered_map<long long, long long> b;
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  for (long long i = 0; i < a.size(); ++i) {
    b[a[i]] = i;
  }
  vector<long long> c(n);
  for (long long i = 0; i < n; ++i) {
    c[i] = b[x[i].second];
  }
  long long now = 0;
  long long sum = 0, kol = 0;
  for (long long i = 0; i < n; ++i) {
    if (x[i].second < 0) {
      sum += x[i].first;
      ++kol;
      continue;
    }
    if (x[i].second > 0) {
      pair<long long, long long> tmp = get(1, 0, q - 1, 0, c[i]);
      now += tmp.second * x[i].first - tmp.first;
      update(1, 0, q - 1, c[i], x[i].first);
    } else {
      now += kol * x[i].first - sum;
      sum += x[i].first;
      ++kol;
    }
  }
  t.assign(2 * q, {0, 0});
  sum = 0;
  kol = 0;
  for (long long i = n - 1; i >= 0; --i) {
    if (x[i].second > 0) {
      sum += x[i].first;
      ++kol;
      continue;
    }
    if (x[i].second < 0) {
      pair<long long, long long> tmp = get(1, 0, q - 1, c[i], n - 1);
      now += tmp.first - tmp.second * x[i].first;
      update(1, 0, q - 1, c[i], x[i].first);
    } else {
      now += sum - kol * x[i].first;
    }
  }
  long long nowl = 0, koll = 0, nowr = 0, kolr = 0;
  for (long long i = 0; i < n; ++i) {
    if (x[i].second > 0) {
      now += koll * x[i].first - nowl;
      ++kolr;
      nowr += x[i].first;
    } else if (x[i].second < 0) {
      ++koll;
      nowl += x[i].first;
    }
  }
  cout << now;
  return 0;
}

### Prompt

Please formulate 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;
vector<pair<long long, long long>> t;
pair<long long, long long> get(long long v, long long l, long long r,
                               long long a, long long b) {
  if (l > b || a > r) {
    return {0, 0};
  }
  if (a <= l && r <= b) {
    return t[v];
  }
  long long m = (l + r) / 2;
  pair<long long, long long> tmp = get(2 * v, l, m, a, b),
                             tmp2 = get(2 * v + 1, m + 1, r, a, b);
  return {tmp.first + tmp2.first, tmp.second + tmp2.second};
}
void update(long long v, long long l, long long r, long long i, long long x) {
  if (l > i || i > r) {
    return;
  }
  if (l == r) {
    t[v] = {t[v].first + x, t[v].second + 1};
    return;
  }
  long long m = (l + r) / 2;
  update(2 * v, l, m, i, x);
  update(2 * v + 1, m + 1, r, i, x);
  t[v].first = t[2 * v].first + t[2 * v + 1].first;
  t[v].second = t[2 * v].second + t[2 * v + 1].second;
}
signed main() {
  long long n;
  cin >> n;
  long long q = 1 << (long long)ceil(log2(n));
  t.resize(2 * q);
  vector<pair<long long, long long>> x(n);
  for (long long i = 0; i < n; ++i) {
    cin >> x[i].first;
  }
  for (long long i = 0; i < n; ++i) {
    cin >> x[i].second;
  }
  sort(x.begin(), x.end());
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) {
    a[i] = x[i].second;
  }
  unordered_map<long long, long long> b;
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  for (long long i = 0; i < a.size(); ++i) {
    b[a[i]] = i;
  }
  vector<long long> c(n);
  for (long long i = 0; i < n; ++i) {
    c[i] = b[x[i].second];
  }
  long long now = 0;
  long long sum = 0, kol = 0;
  for (long long i = 0; i < n; ++i) {
    if (x[i].second < 0) {
      sum += x[i].first;
      ++kol;
      continue;
    }
    if (x[i].second > 0) {
      pair<long long, long long> tmp = get(1, 0, q - 1, 0, c[i]);
      now += tmp.second * x[i].first - tmp.first;
      update(1, 0, q - 1, c[i], x[i].first);
    } else {
      now += kol * x[i].first - sum;
      sum += x[i].first;
      ++kol;
    }
  }
  t.assign(2 * q, {0, 0});
  sum = 0;
  kol = 0;
  for (long long i = n - 1; i >= 0; --i) {
    if (x[i].second > 0) {
      sum += x[i].first;
      ++kol;
      continue;
    }
    if (x[i].second < 0) {
      pair<long long, long long> tmp = get(1, 0, q - 1, c[i], n - 1);
      now += tmp.first - tmp.second * x[i].first;
      update(1, 0, q - 1, c[i], x[i].first);
    } else {
      now += sum - kol * x[i].first;
    }
  }
  long long nowl = 0, koll = 0, nowr = 0, kolr = 0;
  for (long long i = 0; i < n; ++i) {
    if (x[i].second > 0) {
      now += koll * x[i].first - nowl;
      ++kolr;
      nowr += x[i].first;
    } else if (x[i].second < 0) {
      ++koll;
      nowl += x[i].first;
    }
  }
  cout << now;
  return 0;
}

```