#include <bits/stdc++.h>
using namespace std;
int cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second) return a.second < b.second;
  return a.first < b.first;
}
int main() {
  int n;
  cin >> n;
  vector<long long> a, t;
  a.resize(n);
  t.resize(n);
  for (auto &i : a) cin >> i;
  for (auto &i : t) cin >> i;
  vector<pair<long long, long long> > ar;
  for (int i = 0; i < n; i++) {
    ar.push_back(make_pair(t[i], a[i]));
  }
  sort(ar.begin(), ar.end(), cmp);
  priority_queue<pair<long long, long long> > pq;
  long long ans = 0, sum = 0, nb = -1;
  long long tmp = ar[0].second;
  int p = 0;
  while (1) {
    while (pq.empty() or nb == tmp) {
      nb = tmp;
      sum += ar[p].first;
      pq.push(ar[p++]);
      if (p >= n) break;
      tmp = ar[p].second;
    }
    sum -= pq.top().first;
    pq.pop();
    ans += sum;
    nb++;
    if (pq.empty() and p >= n) break;
  }
  cout << ans << endl;
}
