#include <bits/stdc++.h>
using namespace std;
multiset<long long> cost;
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (long long i = 0; i < n; i++) cin >> a[i].first;
  for (long long i = 0; i < n; i++) cin >> a[i].second;
  sort(a.begin(), a.end());
  long long res = 0;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long cur_Ppl = a[i].first;
    while (i < n && cur_Ppl == a[i].first) {
      sum += a[i].second;
      cost.insert(a[i].second);
      i++;
    }
    long long last = *cost.rbegin();
    cost.erase(cost.find(last));
    sum -= last;
    long long sz = (long long)(cost.size());
    if (!sz) {
      i--;
      continue;
    }
    res += sum;
    if (i < n) {
      long long nxtPpl = a[i].first;
      while (sz && ++cur_Ppl < nxtPpl) {
        last = *cost.rbegin();
        cost.erase(cost.find(last));
        sum -= last;
        res += sum;
        sz--;
      }
    } else {
      while (sz) {
        last = *cost.rbegin();
        cost.erase(cost.find(last));
        sum -= last;
        res += sum;
        sz--;
      }
    }
    i--;
  }
  cout << res;
}
