#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    long long vec[n];
    for (long long i = 0; i < n; i++) {
      cin >> vec[i];
    }
    vector<pair<long long, long long> > arr;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      arr.push_back({vec[i], x});
    }
    sort(arr.begin(), arr.end());
    priority_queue<long long> pq;
    long long id = -1;
    long long sum = 0;
    long long maxi;
    long long curr = 0;
    long long i = 0;
    while (i < n || !pq.empty()) {
      while (i < n && arr[i].first == id) {
        curr += arr[i].second;
        pq.push(arr[i].second);
        i++;
      }
      if (pq.size() > 0) {
        id++;
        curr -= pq.top();
        sum += curr;
        pq.pop();
      } else {
        if (i < n) {
          id = arr[i].first;
          curr = 0;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
