#include <bits/stdc++.h>
using namespace std;
int main() {
  multiset<long long> s;
  vector<pair<long long, long long>> v;
  long long i, j, nw, od, cursum = 0, k, a[200005], n, b, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    cin >> b;
    v.push_back({a[i], b});
  }
  sort(v.begin(), v.end());
  v.push_back({1000000000000000, -1});
  for (i = 0; i < n; i++) {
    cursum += v[i].second;
    s.insert(v[i].second);
    if (v[i].first != v[i + 1].first) {
      nw = v[i + 1].first;
      od = v[i].first;
      while (s.size() > 0 && od < nw) {
        auto t = s.end();
        t--;
        cursum -= *t;
        ans += cursum;
        s.erase(t);
        od++;
      }
    }
  }
  cout << ans << endl;
}
