#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, t;
  cin >> n;
  vector<pair<long long, long long> > vc(n);
  for (int i = 0; i < n; i++) {
    cin >> t;
    vc[i] = make_pair(t, 0);
  }
  for (int i = 0; i < n; i++) {
    cin >> t;
    vc[i].second = t;
  }
  sort(vc.begin(), vc.end());
  long long ssum = vc[0].second, ans = 0;
  priority_queue<long long> pq;
  pq.push(vc[0].second);
  long long cur = vc[0].first;
  for (int i = 1; i < n; i++) {
    if (vc[i].first != cur) {
      while (pq.size() && cur < vc[i].first) {
        ssum -= pq.top();
        pq.pop();
        ans += ssum;
        cur++;
      }
      cur = vc[i].first;
      ssum += vc[i].second;
      pq.push(vc[i].second);
    } else {
      ssum += vc[i].second;
      pq.push(vc[i].second);
    }
  }
  while (pq.size()) {
    ssum -= pq.top();
    pq.pop();
    ans += ssum;
  }
  cout << ans << endl;
  return 0;
}
