#include <bits/stdc++.h>
using namespace std;
const long long N = 200001;
const long long MOD = 1000000007;
const long long INF = LLONG_MAX;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t = 1, cs = 0;
  while (t--) {
    long long n, i, last, sum = 0, ans = 0;
    cin >> n;
    vector<pair<long long, long long> > v(n);
    for (i = 0; i < n; i++) cin >> v[i].first;
    for (i = 0; i < n; i++) cin >> v[i].second;
    sort(v.begin(), v.end());
    v.push_back(make_pair(INT_MAX, 0LL));
    priority_queue<long long> p;
    for (i = 0; i <= n; i++) {
      while (p.size() && v[i].first > last) {
        sum -= p.top();
        p.pop();
        ans += sum;
        last++;
      }
      last = v[i].first;
      sum += v[i].second;
      p.push(v[i].second);
    }
    cout << ans << '\n';
  }
}
