#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n;
pair<int, int> niz[maxn];
priority_queue<int> pq;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> niz[i].first;
  for (int i = 0; i < n; i++) cin >> niz[i].second;
  sort(niz, niz + n);
  long long rez = 0, zbir = 0;
  for (int i = 0; i < n; i++) {
    pq.push(niz[i].second);
    zbir += niz[i].second;
    while (i + 1 < n && niz[i + 1].first == niz[i].first) {
      i++;
      pq.push(niz[i].second);
      zbir += niz[i].second;
    }
    long long x = niz[i].first;
    while (!pq.empty() && (i + 1 == n || x != niz[i + 1].first)) {
      zbir -= pq.top();
      pq.pop();
      rez += zbir;
      x++;
    }
  }
  cout << rez << endl;
  return 0;
}
