#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int, int>> 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());
  a.push_back(make_pair(static_cast<int>(2e9), 0));
  n++;
  multiset<int> s;
  int recent = 0;
  long long ans = 0LL, sum = 0LL;
  for (int i = 0; i < n; i++) {
    while (a[i].first > recent && s.size()) {
      recent++;
      auto it = prev(s.end());
      sum -= *it;
      ans += sum;
      s.erase(it);
    }
    recent = a[i].first;
    sum += a[i].second;
    s.insert(a[i].second);
  }
  cout << ans << '\n';
  return 0;
}
