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;
char alphz[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
float Euclidean(long long x1, long long x2, long long y1, long long y2) {
  return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
long long GCD(long long a, long long b) { return !b ? a : GCD(b, a % b); }
long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
void PrimeFactor(long long n) {
  while (n % 2 == 0) {
    n /= 2;
  }
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      n /= i;
    }
  }
  if (n > 2) {
  };
}
bool Is_Square(long long x) {
  long long l = 0, r = x;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    if (mid * mid == x) return true;
    if (mid * mid > x)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return false;
}
long long Power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = Power(x, y / 2);
  if (y % 2 == 0)
    return (temp * temp);
  else
    return (x * temp * temp);
}
bool Is_Prime(int x) {
  if (x == 2)
    return 1;
  else if (x % 2 == 0 || x < 2)
    return 0;
  for (int i = 3; i * i <= x; i += 2)
    if (x % i == 0) return 0;
  return 1;
}
bool Is_Palin(string s) {
  int i = 0, j = (int)s.size() - 1;
  while (i < j) {
    if (s[i] != s[j]) return 0;
    i++, j--;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, vector<int>> mp;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    mp[a[i]].push_back(t);
  }
  int sec = 0;
  priority_queue<int> q;
  long long sum = 0;
  long long ans = 0;
  while (true) {
    if (q.size() == 0) {
      auto it = mp.lower_bound(sec);
      if (it == mp.end()) break;
      sec = it->first;
    }
    if (mp.find(sec) != mp.end())
      for (auto &val : mp[sec]) q.push(val), sum += val;
    sum -= q.top();
    q.pop();
    ans += sum;
    sec++;
  }
  cout << ans;
  return 0;
}
