#include <bits/stdc++.h>
using namespace std;
struct solver {
  long long key, sum = 0;
  priority_queue<long long> pq;
  void add(long long x) {
    pq.push(x);
    sum += x;
  }
  long long extract_max() {
    long long x = pq.top();
    pq.pop();
    sum -= x;
    return x;
  }
  bool empty() { return pq.empty(); }
};
int32_t main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i].first;
  for (long long i = 0; i < n; ++i) cin >> a[i].second;
  sort(a.begin(), a.end());
  long long ans = 0;
  solver s;
  long long a_idx = 0;
  s.key = a[a_idx].first;
  while (a_idx < n) {
    if (s.empty()) {
      s.key = a[a_idx].first;
    }
    while (a_idx < n && a[a_idx].first == s.key) {
      s.add(a[a_idx].second);
      ++a_idx;
    }
    s.extract_max();
    ans += s.sum;
    if (!s.empty()) ++s.key;
  }
  while (!s.empty()) {
    s.extract_max();
    ans += s.sum;
  }
  cout << ans << endl;
}
