#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int a[200005], t[200005];
pair<int, int> ara[200005];
priority_queue<int> pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> t[i];
    ara[i] = {a[i], t[i]};
  }
  sort(ara + 1, ara + n + 1);
  ll ans = 0, sum = (ll)(ara[1].second);
  pq.push(ara[1].second);
  int pos = 2, cur = ara[1].first;
  while (!pq.empty()) {
    if (cur == ara[pos].first) {
      sum += (ll)(ara[pos].second);
      pq.push(ara[pos].second);
      pos++;
    } else {
      int u = pq.top();
      pq.pop();
      ans += (ll)sum - (ll)u;
      sum -= u;
      if (pq.empty() && pos <= n) {
        pq.push(ara[pos].second);
        cur = ara[pos].first;
        sum = (ll)(ara[pos].second);
        pos++;
      } else if (pq.empty())
        break;
      else {
        cur++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
