#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (pair<int, int>& x : a) cin >> x.first;
  for (pair<int, int>& x : a) cin >> x.second;
  sort(a.begin(), a.end());
  priority_queue<int> pq;
  int idx = 0;
  long long tot = 0, ans = 0;
  while (idx < n) {
    int nxt = a[idx].first;
    tot += a[idx].second;
    pq.push(a[idx].second);
    idx++;
    while (!pq.empty()) {
      while (idx < n && a[idx].first == nxt) {
        tot += a[idx].second;
        pq.push(a[idx].second);
        idx++;
      }
      int t = pq.top();
      pq.pop();
      nxt++;
      tot -= t;
      ans += tot;
    }
  }
  cout << ans << '\n';
}
