#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
class SegmentTree {
 private:
  int _size = 1;
  T _def;
  std::vector<T> _nodes;
  std::function<T(T, T)> _op;
  std::function<T(T, T)> _update_op;

 public:
  SegmentTree(int size, T default_value, std::function<T(T, T)> op,
              std::function<T(T, T)> update_op)
      : _def(default_value), _op(op), _update_op(update_op) {
    while (_size < size) _size *= 2;
    _nodes = std::vector<T>(2 * _size, default_value);
  }
  SegmentTree(std::vector<T> nodes, T default_value, std::function<T(T, T)> op,
              std::function<T(T, T)> update_op)
      : _def(default_value), _op(op), _update_op(update_op) {
    int real_size = nodes.size();
    while (_size < real_size) _size *= 2;
    _nodes = std::vector<T>(2 * _size, default_value);
    for (int i = 0; i < real_size; ++i) _nodes[i + _size] = nodes[i];
    for (int i = _size - 1; i >= 0; --i)
      _nodes[i] = _op(_nodes[i * 2], _nodes[i * 2 + 1]);
  }
  T find(int l, int r) { return find(l, r, 1, 0, _size); }
  T find(int l, int r, int index, int cover_l, int cover_r) {
    if (cover_r <= l || r <= cover_l) return _def;
    if (l <= cover_l && cover_r <= r) return _nodes[index];
    return _op(find(l, r, index * 2, cover_l, (cover_l + cover_r) >> 1),
               find(l, r, index * 2 + 1, (cover_l + cover_r) >> 1, cover_r));
  }
  void update(int index, T value) {
    index += _size;
    _nodes[index] = _update_op(_nodes[index], value);
    while (index > 0) {
      index >>= 1;
      _nodes[index] = _op(_nodes[index * 2], _nodes[index * 2 + 1]);
    }
  }
};
struct Point {
  ll x, v;
  bool operator<(const Point &other) const { return x < other.x; }
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  int x, v;
  set<int> vs;
  vector<Point> ps;
  for (ll i = 0, iLen = (n); i < iLen; ++i) {
    cin >> x;
    ps.push_back(Point{x, 0});
  }
  for (ll i = 0, iLen = (n); i < iLen; ++i) {
    cin >> v;
    ps[i].v = v;
    vs.insert(v);
  }
  map<int, int> v_comp;
  int i = 0;
  for (auto &v : vs) {
    v_comp[v] = i++;
  }
  int v_size = v_comp.size() + 10;
  auto x_cnt = SegmentTree<ll>(
      v_size, 0, [](ll x, ll y) { return x + y; },
      [](ll x, ll y) { return x + y; });
  auto x_acc = SegmentTree<ll>(
      v_size, 0, [](ll x, ll y) { return x + y; },
      [](ll x, ll y) { return x + y; });
  for (ll i = 0, iLen = (n); i < iLen; ++i) {
    ps[i].v = v_comp[ps[i].v];
    x_cnt.update(ps[i].v, 1);
    x_acc.update(ps[i].v, ps[i].x);
  }
  sort(ps.begin(), ps.end());
  ll ans = 0;
  for (auto &[x, v] : ps) {
    x_cnt.update(v, -1);
    x_acc.update(v, -x);
    ans += x_acc.find(v, v_size) - x_cnt.find(v, v_size) * x;
  }
  cout << ans << endl;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 ll = long long;
using namespace std;
template <class T>
class SegmentTree {
 private:
  int _size = 1;
  T _def;
  std::vector<T> _nodes;
  std::function<T(T, T)> _op;
  std::function<T(T, T)> _update_op;

 public:
  SegmentTree(int size, T default_value, std::function<T(T, T)> op,
              std::function<T(T, T)> update_op)
      : _def(default_value), _op(op), _update_op(update_op) {
    while (_size < size) _size *= 2;
    _nodes = std::vector<T>(2 * _size, default_value);
  }
  SegmentTree(std::vector<T> nodes, T default_value, std::function<T(T, T)> op,
              std::function<T(T, T)> update_op)
      : _def(default_value), _op(op), _update_op(update_op) {
    int real_size = nodes.size();
    while (_size < real_size) _size *= 2;
    _nodes = std::vector<T>(2 * _size, default_value);
    for (int i = 0; i < real_size; ++i) _nodes[i + _size] = nodes[i];
    for (int i = _size - 1; i >= 0; --i)
      _nodes[i] = _op(_nodes[i * 2], _nodes[i * 2 + 1]);
  }
  T find(int l, int r) { return find(l, r, 1, 0, _size); }
  T find(int l, int r, int index, int cover_l, int cover_r) {
    if (cover_r <= l || r <= cover_l) return _def;
    if (l <= cover_l && cover_r <= r) return _nodes[index];
    return _op(find(l, r, index * 2, cover_l, (cover_l + cover_r) >> 1),
               find(l, r, index * 2 + 1, (cover_l + cover_r) >> 1, cover_r));
  }
  void update(int index, T value) {
    index += _size;
    _nodes[index] = _update_op(_nodes[index], value);
    while (index > 0) {
      index >>= 1;
      _nodes[index] = _op(_nodes[index * 2], _nodes[index * 2 + 1]);
    }
  }
};
struct Point {
  ll x, v;
  bool operator<(const Point &other) const { return x < other.x; }
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  int x, v;
  set<int> vs;
  vector<Point> ps;
  for (ll i = 0, iLen = (n); i < iLen; ++i) {
    cin >> x;
    ps.push_back(Point{x, 0});
  }
  for (ll i = 0, iLen = (n); i < iLen; ++i) {
    cin >> v;
    ps[i].v = v;
    vs.insert(v);
  }
  map<int, int> v_comp;
  int i = 0;
  for (auto &v : vs) {
    v_comp[v] = i++;
  }
  int v_size = v_comp.size() + 10;
  auto x_cnt = SegmentTree<ll>(
      v_size, 0, [](ll x, ll y) { return x + y; },
      [](ll x, ll y) { return x + y; });
  auto x_acc = SegmentTree<ll>(
      v_size, 0, [](ll x, ll y) { return x + y; },
      [](ll x, ll y) { return x + y; });
  for (ll i = 0, iLen = (n); i < iLen; ++i) {
    ps[i].v = v_comp[ps[i].v];
    x_cnt.update(ps[i].v, 1);
    x_acc.update(ps[i].v, ps[i].x);
  }
  sort(ps.begin(), ps.end());
  ll ans = 0;
  for (auto &[x, v] : ps) {
    x_cnt.update(v, -1);
    x_acc.update(v, -x);
    ans += x_acc.find(v, v_size) - x_cnt.find(v, v_size) * x;
  }
  cout << ans << endl;
}

```