#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0, 0, 0, 0};
const long long inf = 1e11;
const int seivesize = 5000005;
const double eps = 0.000000009;
long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n], t[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> t[i];
  map<int, vector<long long> > b;
  for (int i = 0; i < n; i++) b[a[i]].push_back(t[i]);
  long long curr = (*b.begin()).first;
  long long ans = 0;
  long long csum = 0;
  map<int, vector<long long> >::iterator it = b.end();
  it--;
  long long last = (*it).first;
  priority_queue<long long> pq;
  while (1) {
    if (b.find(curr) != b.end()) {
      vector<long long> x = b[curr];
      for (int i = 0; i < x.size(); i++) {
        pq.push(x[i]);
        csum += x[i];
      }
    }
    if (!pq.empty()) {
      long long x = pq.top();
      pq.pop();
      csum -= x;
      ans += csum;
    }
    if (pq.empty()) {
      if (curr >= last) break;
      it = b.upper_bound(curr);
      curr = (*it).first;
      continue;
    }
    curr++;
  }
  cout << ans << endl;
  return 0;
}
