#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
const int bound = 2021;
int sum(int a, int b) {
  int c = a + b;
  if (c >= mod) {
    c -= mod;
  }
  return c;
}
int dif(int a, int b) {
  int c = a - b;
  if (c < 0) {
    c += mod;
  }
  return c;
}
int mlt(int a, int b) {
  long long c = a * 1LL * b;
  return c % mod;
}
int ibit(int n, int i) { return ((n >> i) & 1); }
void outp(vector<vector<int>> &ou) {
  for (int i = 0; i < ou.size(); i++) {
    for (int j = 0; j < ou[i].size(); j++) {
      cout << ou[i][j] << ' ';
    }
    cout << '\n';
  }
}
int bp(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int a = 0;
  if (!(y % 2)) {
    a = bp(x, y / 2);
  }
  return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x) { return bp(x, mod - 2); }
const int maxn = 10000007;
int fact[1000007], ofact[1000007];
void prec() {
  fact[0] = 1;
  ofact[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = mlt(fact[i - 1], i);
  }
  ofact[maxn - 1] = obr(fact[maxn - 1]);
  for (int i = maxn - 2; i > 0; i--) {
    ofact[i] = mlt(ofact[i + 1], i + 1);
  }
}
int c(int a, int b) {
  return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return (x > y) ? gcd(y, x) : gcd(y % x, x);
}
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  int n;
  cin >> n;
  vector<pair<int, int>> inp(n);
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) cin >> y[i];
  for (int i = 0; i < n; i++) inp[i] = make_pair(y[i], x[i]);
  sort(inp.begin(), inp.end());
  reverse(inp.begin(), inp.end());
  set<pair<int, int>> segs;
  long long ans = 0;
  set<pair<int, int>>::iterator iit, it;
  for (int i = 0; i < n; i++) {
    int x = inp[i].second;
    pair<int, int> pra = make_pair(x + 1, -1);
    it = segs.lower_bound(pra);
    pair<int, int> sg = *it;
    pra = make_pair(x + 1, x);
    if (it == segs.end()) {
      pair<int, int> pra1 = make_pair(x, -1);
      iit = segs.lower_bound(pra1);
      if (iit != segs.end()) {
        pair<int, int> sg1 = *iit;
        segs.erase(sg1);
        pra = make_pair(x + 1, sg1.second);
        segs.insert(pra);
      } else {
        segs.insert(pra);
      }
    } else {
      if (sg.second > x) {
        if (sg.second == x + 1) {
          segs.erase(sg);
          pra = make_pair(sg.first, x);
        }
        pair<int, int> hz = make_pair(x, -1);
        it = segs.lower_bound(hz);
        pair<int, int> sg1 = *it;
        if (sg1.first == x) {
          segs.erase(sg1);
          pra = make_pair(pra.first, sg1.second);
        }
        segs.insert(pra);
      } else {
        ans += (long long)inp[i].first * 1LL * (long long)(sg.first - x);
        pra = make_pair(sg.first + 1, sg.second);
        pair<int, int> prr = make_pair(pra.first, pra.first + 1);
        it = segs.lower_bound(prr);
        segs.erase(sg);
        pair<int, int> sg1 = *it;
        if (sg1.second == pra.first) {
          pra = make_pair(sg1.first, pra.second);
          segs.erase(sg1);
        }
        segs.insert(pra);
      }
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  int n;
  cin >> n;
}

### Prompt

Generate a CPP solution to the following problem:

VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.

The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds. 

What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.

Input

The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000).

The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9).

The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5).

Output

Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.

Examples

Input


5
3 7 9 7 8
5 2 5 7 5


Output


6


Input


5
1 2 3 4 5
1 1 1 1 1


Output


0

Note

In the first example, it is possible to find three publications of the second type, which will take 6 seconds.

In the second example, all news categories contain a different number of publications.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
const int bound = 2021;
int sum(int a, int b) {
  int c = a + b;
  if (c >= mod) {
    c -= mod;
  }
  return c;
}
int dif(int a, int b) {
  int c = a - b;
  if (c < 0) {
    c += mod;
  }
  return c;
}
int mlt(int a, int b) {
  long long c = a * 1LL * b;
  return c % mod;
}
int ibit(int n, int i) { return ((n >> i) & 1); }
void outp(vector<vector<int>> &ou) {
  for (int i = 0; i < ou.size(); i++) {
    for (int j = 0; j < ou[i].size(); j++) {
      cout << ou[i][j] << ' ';
    }
    cout << '\n';
  }
}
int bp(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int a = 0;
  if (!(y % 2)) {
    a = bp(x, y / 2);
  }
  return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x) { return bp(x, mod - 2); }
const int maxn = 10000007;
int fact[1000007], ofact[1000007];
void prec() {
  fact[0] = 1;
  ofact[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = mlt(fact[i - 1], i);
  }
  ofact[maxn - 1] = obr(fact[maxn - 1]);
  for (int i = maxn - 2; i > 0; i--) {
    ofact[i] = mlt(ofact[i + 1], i + 1);
  }
}
int c(int a, int b) {
  return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return (x > y) ? gcd(y, x) : gcd(y % x, x);
}
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  int n;
  cin >> n;
  vector<pair<int, int>> inp(n);
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) cin >> y[i];
  for (int i = 0; i < n; i++) inp[i] = make_pair(y[i], x[i]);
  sort(inp.begin(), inp.end());
  reverse(inp.begin(), inp.end());
  set<pair<int, int>> segs;
  long long ans = 0;
  set<pair<int, int>>::iterator iit, it;
  for (int i = 0; i < n; i++) {
    int x = inp[i].second;
    pair<int, int> pra = make_pair(x + 1, -1);
    it = segs.lower_bound(pra);
    pair<int, int> sg = *it;
    pra = make_pair(x + 1, x);
    if (it == segs.end()) {
      pair<int, int> pra1 = make_pair(x, -1);
      iit = segs.lower_bound(pra1);
      if (iit != segs.end()) {
        pair<int, int> sg1 = *iit;
        segs.erase(sg1);
        pra = make_pair(x + 1, sg1.second);
        segs.insert(pra);
      } else {
        segs.insert(pra);
      }
    } else {
      if (sg.second > x) {
        if (sg.second == x + 1) {
          segs.erase(sg);
          pra = make_pair(sg.first, x);
        }
        pair<int, int> hz = make_pair(x, -1);
        it = segs.lower_bound(hz);
        pair<int, int> sg1 = *it;
        if (sg1.first == x) {
          segs.erase(sg1);
          pra = make_pair(pra.first, sg1.second);
        }
        segs.insert(pra);
      } else {
        ans += (long long)inp[i].first * 1LL * (long long)(sg.first - x);
        pra = make_pair(sg.first + 1, sg.second);
        pair<int, int> prr = make_pair(pra.first, pra.first + 1);
        it = segs.lower_bound(prr);
        segs.erase(sg);
        pair<int, int> sg1 = *it;
        if (sg1.second == pra.first) {
          pra = make_pair(sg1.first, pra.second);
          segs.erase(sg1);
        }
        segs.insert(pra);
      }
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  int n;
  cin >> n;
}

```