#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i].first;
  for (long long i = 0; i < n; i++) cin >> v[i].second;
  sort(v.begin(), v.end());
  priority_queue<long long> pq;
  long long cur = 0, sum = 0, ans = 0;
  for (long long i = 0; i < n;) {
    while (pq.size() && cur < v[i].first) {
      sum -= pq.top();
      pq.pop();
      ans += sum;
      cur++;
    }
    if (cur < v[i].first) cur = v[i].first;
    long long j;
    for (j = i; j < n && v[i].first == v[j].first; j++) {
      sum += v[j].second;
      pq.push(v[j].second);
    }
    i = j;
  }
  while (pq.size()) {
    sum -= pq.top();
    pq.pop();
    ++cur;
    ans += sum;
  }
  cout << ans << '\n';
  return 0;
}
