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.
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long pm(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = ((result % mod) * (x % mod)) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n /= 2;
  }
  return result;
}
long long p(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * x;
    x = x * x;
    n /= 2;
  }
  return result;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ncr(long long n, long long r) {
  long long p = 1, k = 1;
  if (n - r < r) r = n - r;
  if (r != 0) {
    while (r != 0) {
      p *= n;
      k *= r;
      long long temp = gcd(p, k);
      p /= temp;
      k /= temp;
      n--;
      r--;
    }
  } else
    p = 1;
  return p;
}
long long factorial[200000 + 1];
void fact(long long n) {
  factorial[0] = 1;
  factorial[1] = 1;
  for (int i = 2; i < n + 1; i++)
    factorial[i] = (i * factorial[i - 1] % mod) % mod;
}
long long d, coeff1, coeff2;
void euclid(long long a, long long b) {
  if (b == 0) {
    d = a;
    coeff1 = 1;
    coeff2 = 0;
  } else {
    euclid(b, a % b);
    long long temp = coeff1;
    coeff1 = coeff2;
    coeff2 = temp - (a / b) * (coeff2);
  }
}
long long modinv(long long a) {
  euclid(a, mod);
  return (coeff1 % mod + mod) % mod;
}
long long prime[1000001] = {};
void sieve(long long n) {
  prime[0] = 1;
  prime[1] = 1;
  for (long long i = 2; i * i <= n; i++) {
    if (prime[i] == 0) {
      for (long long j = i * i; j <= n; j += i) prime[j] = 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  unordered_map<long long, vector<long long> > wow;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    wow[a[i]].push_back(x);
  }
  sort((a).begin(), (a).end());
  a.erase(unique((a).begin(), (a).end()), a.end());
  priority_queue<long long> temp;
  long long ans = 0;
  long long final = 0;
  for (int i = 0; i < ((long long)(a).size()); i++) {
    if (((long long)(wow[a[i]]).size()) > 1 || !temp.empty()) {
      for (int j = 0; j < ((long long)(wow[a[i]]).size()); j++) {
        ans += wow[a[i]][j];
        temp.push(wow[a[i]][j]);
      }
      ans -= temp.top();
      temp.pop();
      long long cur = a[i];
      while (!temp.empty()) {
        cur++;
        final += ans;
        if (((long long)(wow[cur]).size()))
          break;
        else {
          ans -= temp.top();
          temp.pop();
        }
      }
    }
  }
  cout << final << endl;
  return 0;
}
