#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n), t(n);
  vector<pair<long long, long long> > vp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vp.push_back({a[i], i});
  }
  for (int i = 0; i < n; i++) cin >> t[i];
  long long ans = 0;
  sort(vp.begin(), vp.end());
  long long sum = 0;
  priority_queue<long long> pq;
  int i = 0;
  while (i < n) {
    int j;
    for (j = i; j < n; j++) {
      if (vp[i].first == vp[j].first) {
        sum += t[vp[j].second];
        pq.push(t[vp[j].second]);
      } else
        break;
    }
    long long num = vp[i].first;
    while (j < n && pq.empty() == 0 && num < vp[j].first) {
      sum -= pq.top();
      pq.pop();
      ans += sum;
      num++;
    }
    i = j;
  }
  while (pq.empty() == 0) {
    sum -= pq.top();
    pq.pop();
    ans += sum;
  }
  cout << ans << "\n";
}
int main(void) {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
