#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), cost(n);
  for (int& p : a) cin >> p;
  for (int& p : cost) cin >> p;
  priority_queue<pair<int, int> > q;
  priority_queue<int> t;
  for (int i = 0; i < n; i++) {
    q.push({-a[i], cost[i]});
  }
  int index = 0;
  long long sol = 0, total = 0;
  while (q.size() > 0) {
    while (t.size() > 0 && index + 1 < -q.top().first) {
      index++;
      sol += total - t.top();
      total -= t.top();
      t.pop();
    }
    total += q.top().second;
    index = -q.top().first - 1;
    t.push(q.top().second);
    q.pop();
  }
  while (t.size() > 0) {
    sol += total - t.top();
    total -= t.top();
    t.pop();
  }
  cout << sol << "\n";
}
