#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[200010];
priority_queue<long long> pq;
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i].first);
  }
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i].second);
  }
  a[n + 1].first = 1e18;
  sort(a + 1, a + 1 + n);
  long long ans = 0;
  long long now = 0;
  for (long long i = 1; i <= n; i++) {
    pq.push(a[i].second);
    if (a[i].first == a[i + 1].first) {
      now += a[i].second;
    } else {
      long long diff = a[i + 1].first - a[i].first;
      now += a[i].second;
      for (long long i = 1; i <= diff; i++) {
        if (pq.empty()) break;
        now -= pq.top();
        ans += now;
        pq.pop();
      }
    }
  }
  cout << ans << endl;
  return 0;
}
