#include <bits/stdc++.h>
using namespace std;
int spf[10000001];
long long int fac[200005];
long long int comb[1010][1010];
void combfun();
void sieve(int n);
int expo(int base, int exponent);
long long int power(long long int x, long long int y, long long int p);
long long int modInverse(long long int n, long long int p);
long long int nCrModPFormat(long long int n, long long int r, long long int p);
int lps(string s);
long long int dp[1010];
vector<int> c[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    map<long long int, vector<long long int>> mp;
    for (int i = 0; i < n; i++) {
      mp[a[i]].push_back(b[i]);
    }
    long long int ans = 0;
    long long int sum = 0;
    multiset<long long int> s;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      for (auto j : it->second) {
        s.insert(j);
        sum += j;
      }
      long long int k = 0;
      auto it2 = it;
      it2++;
      while (it2 != mp.end() && s.size() && it->first + k != it2->first) {
        auto itr = s.end();
        itr--;
        sum -= (*itr);
        ans += sum;
        s.erase(itr);
        k++;
      }
    }
    long long int k = 0;
    while (s.size()) {
      auto itr = s.end();
      itr--;
      sum -= (*itr);
      ans += sum;
      s.erase(itr);
      k++;
    }
    cout << ans << endl;
  }
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
  return 0;
}
void combfun() {
  for (int i = 1; i < 1010; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 or i == j) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
        comb[i][j] %= 998244353;
      }
    }
  }
}
int expo(int base, int exponent) {
  long long int ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (ans * base) % 998244353;
    base = (base * base) % 998244353;
    exponent >>= 1;
  }
  return ans % 998244353;
}
void sieve(int n) {
  spf[1] = 1;
  for (int i = 2; i <= n; i++) spf[i] = i;
  for (int i = 4; i <= n; i += 2) spf[i] = 2;
  for (int i = 3; i * i <= n; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= n; j += i) {
        if (spf[j] == j) spf[j] = i;
      }
    }
  }
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int nCrModPFormat(long long int n, long long int r, long long int p) {
  fac[0] = 1;
  for (int i = 1; i < 200005; i++) {
    fac[i] = (fac[i - 1] * i) % 998244353;
  }
  if (r == 0) return 1;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
int lps(string s) {
  int n = s.size();
  int lps[n];
  lps[0] = 0;
  int i = 1;
  int j = 0;
  while (i < n) {
    if (s[i] == s[j]) {
      j++;
      lps[i] = j;
      i++;
    } else {
      if (j) {
        j = lps[j - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
  return min(n / 2, lps[n - 1]);
}

### Prompt

Your challenge is to write 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 spf[10000001];
long long int fac[200005];
long long int comb[1010][1010];
void combfun();
void sieve(int n);
int expo(int base, int exponent);
long long int power(long long int x, long long int y, long long int p);
long long int modInverse(long long int n, long long int p);
long long int nCrModPFormat(long long int n, long long int r, long long int p);
int lps(string s);
long long int dp[1010];
vector<int> c[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    map<long long int, vector<long long int>> mp;
    for (int i = 0; i < n; i++) {
      mp[a[i]].push_back(b[i]);
    }
    long long int ans = 0;
    long long int sum = 0;
    multiset<long long int> s;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      for (auto j : it->second) {
        s.insert(j);
        sum += j;
      }
      long long int k = 0;
      auto it2 = it;
      it2++;
      while (it2 != mp.end() && s.size() && it->first + k != it2->first) {
        auto itr = s.end();
        itr--;
        sum -= (*itr);
        ans += sum;
        s.erase(itr);
        k++;
      }
    }
    long long int k = 0;
    while (s.size()) {
      auto itr = s.end();
      itr--;
      sum -= (*itr);
      ans += sum;
      s.erase(itr);
      k++;
    }
    cout << ans << endl;
  }
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
  return 0;
}
void combfun() {
  for (int i = 1; i < 1010; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 or i == j) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
        comb[i][j] %= 998244353;
      }
    }
  }
}
int expo(int base, int exponent) {
  long long int ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (ans * base) % 998244353;
    base = (base * base) % 998244353;
    exponent >>= 1;
  }
  return ans % 998244353;
}
void sieve(int n) {
  spf[1] = 1;
  for (int i = 2; i <= n; i++) spf[i] = i;
  for (int i = 4; i <= n; i += 2) spf[i] = 2;
  for (int i = 3; i * i <= n; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= n; j += i) {
        if (spf[j] == j) spf[j] = i;
      }
    }
  }
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int nCrModPFormat(long long int n, long long int r, long long int p) {
  fac[0] = 1;
  for (int i = 1; i < 200005; i++) {
    fac[i] = (fac[i - 1] * i) % 998244353;
  }
  if (r == 0) return 1;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
int lps(string s) {
  int n = s.size();
  int lps[n];
  lps[0] = 0;
  int i = 1;
  int j = 0;
  while (i < n) {
    if (s[i] == s[j]) {
      j++;
      lps[i] = j;
      i++;
    } else {
      if (j) {
        j = lps[j - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
  return min(n / 2, lps[n - 1]);
}

```