#include <bits/stdc++.h>
using namespace std;
priority_queue<int> pq;
pair<int, int> a[200005];
long long n, sum, ret, val;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i].first;
  for (int i = 0; i < n; i++) cin >> a[i].second;
  sort(a, a + n);
  for (int i = 0; i <= n; i++) {
    while (pq.size() && (i == n || a[i].first > val)) {
      sum -= pq.top();
      pq.pop();
      ret += sum;
      val++;
    }
    if (i == n) break;
    val = a[i].first;
    pq.push(a[i].second);
    sum += a[i].second;
  }
  cout << ret << "\n";
  return 0;
}
