#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int, int> > pubs(n);
  for (int i = 0; i < n; i++) cin >> pubs[i].first;
  for (int i = 0; i < n; i++) cin >> pubs[i].second;
  sort((pubs).begin(), (pubs).end());
  reverse((pubs).begin(), (pubs).end());
  priority_queue<int> bads;
  int idx = 0;
  long long ans = 0;
  long long cur_cost = 0;
  while (!pubs.empty() || !bads.empty()) {
    if (bads.empty()) {
      idx = pubs.back().first;
    }
    while (!pubs.empty() && pubs.back().first == idx) {
      cur_cost += pubs.back().second;
      bads.push(pubs.back().second);
      pubs.pop_back();
    }
    if (!bads.empty()) {
      cur_cost -= bads.top();
      bads.pop();
    }
    ans += cur_cost;
    idx++;
  }
  cout << ans;
}
