#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
int main() {
  multiset<int> s;
  int n;
  cin >> n;
  vector<pair<long long, long long> > v(n);
  for (int i = 0; i < n; i++) cin >> v[i].first;
  for (int i = 0; i < n; i++) cin >> v[i].second;
  sort((v).begin(), (v).end());
  long long cur = 0;
  long long sum = 0;
  long long ans = 0;
  int i = 0;
  while (i < n || !s.empty()) {
    if (s.empty()) cur = v[i].first;
    while (i < n && v[i].first == cur) {
      sum += v[i].second;
      s.insert(v[i].second);
      i++;
    }
    long long x = *s.rbegin();
    sum -= x;
    ans += sum;
    s.erase(s.find(x));
    cur++;
  }
  cout << ans;
}
