#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
void fun() {}
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
const long long N = 2e5 + 107;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fun();
  long long tt = 1;
  while (tt--) {
    long long n;
    cin >> n;
    long long a[n], t[n];
    long long h[N] = {0};
    for (long long i = 0; i < n; i++) cin >> a[i], h[a[i]]++;
    for (long long i = 0; i < n; i++) cin >> t[i];
    vector<pair<long long, long long> > v;
    for (long long i = 0; i < n; i++) v.push_back(make_pair(a[i], t[i]));
    sort(v.begin(), v.end());
    long long sum = 0, ans = 0, curr;
    priority_queue<long long> pq;
    for (long long i = 0; i < n; i++) {
      sum += v[i].second;
      pq.push(v[i].second);
      curr = v[i].first;
      while (not pq.empty() and (i == n - 1 or curr != v[i + 1].first)) {
        sum -= pq.top();
        pq.pop();
        ans += sum;
        curr++;
      }
    }
    cout << ans;
  }
  return 0;
}
