#include <bits/stdc++.h>
using namespace std;
long long powerm(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long power(long long x, unsigned long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    cout << "Inverse doesn't exist";
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long d[200001];
long long par[200001];
long long tin[200001];
long long tout[200001];
long long t = 0;
long long dp[200001];
long long ans[200001];
struct cmp {
  bool operator()(pair<long long, long long> x, pair<long long, long long> y) {
    return (x.first < y.first || (x.first == y.first && x.second < y.second));
  }
};
int32_t main() {
  long long q = 1;
  long long Q = 1;
  while (q--) {
    long long n;
    cin >> n;
    pair<long long, long long> a[n + 2];
    a[0] = {0, 0};
    for (long long i = 1; i <= n; i++) cin >> a[i].first;
    for (long long i = 1; i <= n; i++) cin >> a[i].second;
    a[n + 1] = {2e9, 0};
    sort(a + 1, a + n + 1);
    priority_queue<long long> q;
    long long s = 0, ans = 0;
    for (long long i = 1; i <= n + 1; i++) {
      long long c = a[i].first - a[i - 1].first;
      while (c && !q.empty()) {
        s -= q.top();
        ans += s;
        q.pop();
        c--;
      }
      q.push(a[i].second);
      s += a[i].second;
    }
    cout << ans;
  }
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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;
long long powerm(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long power(long long x, unsigned long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    cout << "Inverse doesn't exist";
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long d[200001];
long long par[200001];
long long tin[200001];
long long tout[200001];
long long t = 0;
long long dp[200001];
long long ans[200001];
struct cmp {
  bool operator()(pair<long long, long long> x, pair<long long, long long> y) {
    return (x.first < y.first || (x.first == y.first && x.second < y.second));
  }
};
int32_t main() {
  long long q = 1;
  long long Q = 1;
  while (q--) {
    long long n;
    cin >> n;
    pair<long long, long long> a[n + 2];
    a[0] = {0, 0};
    for (long long i = 1; i <= n; i++) cin >> a[i].first;
    for (long long i = 1; i <= n; i++) cin >> a[i].second;
    a[n + 1] = {2e9, 0};
    sort(a + 1, a + n + 1);
    priority_queue<long long> q;
    long long s = 0, ans = 0;
    for (long long i = 1; i <= n + 1; i++) {
      long long c = a[i].first - a[i - 1].first;
      while (c && !q.empty()) {
        s -= q.top();
        ans += s;
        q.pop();
        c--;
      }
      q.push(a[i].second);
      s += a[i].second;
    }
    cout << ans;
  }
}

```