#include <bits/stdc++.h>
using namespace std;
const long long N = 1001;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n), t(n);
  map<long long, vector<long long> > mp;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> t[i];
  for (long long i = 0; i < n; i++) {
    mp[a[i]].push_back(t[i]);
  }
  priority_queue<long long> pq;
  long long pos = 0;
  long long T = 0;
  long long del = 0;
  long long cost = 0;
  while (true) {
    if (del == n) break;
    if (!pq.size()) {
      auto data = *mp.lower_bound(pos);
      long long new_pos = data.first;
      cost += (new_pos - pos) * T;
      pos = new_pos;
    }
    for (long long u : mp[pos]) {
      pq.push(u);
      T += u;
    }
    T -= pq.top();
    pq.pop();
    del++;
    pos++;
    cost += T;
  }
  cout << cost;
}
