#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pii> a(n);
  for (int i = 0; i < n; i++) cin >> a[i].first;
  for (int i = 0; i < n; i++) cin >> a[i].second;
  sort(a.begin(), a.end());
  multiset<int> t;
  int curr = -1;
  ll tot = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    while (!t.empty() && a[i].first != curr) {
      tot += *t.begin();
      t.erase(t.begin());
      ans += tot;
      curr++;
    }
    if (t.empty()) curr = a[i].first;
    t.insert(-a[i].second);
    tot += a[i].second;
  }
  while (!t.empty()) {
    tot += *t.begin();
    t.erase(t.begin());
    ans += tot;
    curr++;
  }
  cout << ans << endl;
}
