#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> pub(n);
  vector<long long> t(n);
  for (int i = 0; i < n; i++) {
    cin >> pub[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  map<long long, multiset<long long>> mp;
  for (int i = 0; i < n; i++) {
    mp[pub[i]].insert(t[i]);
  }
  long long ans = 0;
  auto it = mp.begin();
  multiset<pair<long long, long long>, greater<pair<long long, long long>>> acc;
  long long last = (it->first) - 1;
  while (it != mp.end()) {
    auto see = acc.begin();
    while (see != acc.end()) {
      if (last + 1 < it->first) {
        last++;
        ans += (last - (see->second)) * (see->first);
        auto to_erase = see++;
        acc.erase(to_erase);
      } else {
        break;
      }
    }
    for (auto temp = (it->second).begin(); temp != (it->second).end(); temp++) {
      acc.insert({*temp, it->first});
    }
    last = it->first - 1;
    it++;
  }
  auto see = acc.begin();
  while (see != acc.end()) {
    last++;
    ans += (last - see->second) * (see->first);
    see++;
  }
  cout << ans << endl;
  return 0;
}
