#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  pair<long long, long long> arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i].first;
  for (long long i = 0; i < n; i++) cin >> arr[i].second;
  sort(arr, arr + n);
  priority_queue<long long> pq;
  long long ans = 0;
  long long i = 0;
  long long x;
  long long sum = 0;
  while (!pq.empty() || i < n) {
    if (pq.empty()) x = arr[i].first;
    for (; i < n; i++) {
      if (arr[i].first == x)
        pq.push(arr[i].second), sum += arr[i].second;
      else
        break;
    }
    sum -= pq.top();
    pq.pop();
    ans += sum;
    x++;
  }
  cout << ans;
}
