#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  vector<int> a(n);
  vector<int> t(n);
  map<int, vector<int> > mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int tm = -100;
  long long tot = 0;
  set<pair<int, int> > s;
  while (true) {
    if (s.empty()) {
      auto it = mp.upper_bound(tm);
      if (it == mp.end()) break;
      tm = it->first;
    } else {
      tm++;
    }
    auto q = mp.find(tm);
    if (q != mp.end()) {
      for (auto i : q->second) {
        pair<int, int> p = {t[i], i};
        s.insert(p);
        tot += t[i];
      }
    }
    auto curr = *s.rbegin();
    s.erase(curr);
    tot -= curr.first;
    ans += tot;
  }
  cout << ans << endl;
  return 0;
}
