#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > p(n);
  for (int i = 0; i < n; ++i) cin >> p[i].first;
  for (int i = 0; i < n; ++i) cin >> p[i].second;
  sort(p.begin(), p.end());
  long long ans = 0;
  for (int i = 0; i < n;) {
    priority_queue<int> pq;
    int cur = p[i].first;
    pq.push(p[i].second);
    long long sum = p[i].second;
    int j = i + 1;
    while (1) {
      while (j < n && p[j].first <= cur) {
        pq.push(p[j].second);
        sum += p[j].second;
        j++;
      }
      if (pq.size() == 1) break;
      sum -= pq.top();
      ans += sum;
      pq.pop();
      cur++;
    }
    i = j;
  }
  cout << ans << endl;
  return 0;
}
