#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
long long a[maxn], b[maxn];
vector<pair<long long, long long>> V;
priority_queue<int> pq;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) V.push_back({a[i], b[i]});
  sort(V.begin(), V.end());
  pq.push(V.front().second);
  long long now = V[0].first, ans = 0, sum = V[0].second;
  for (int i = 1; i < V.size(); i++) {
    while (!pq.empty() && V[i].first > now) {
      now++;
      ans += sum - pq.top();
      sum -= pq.top();
      pq.pop();
    }
    if (pq.empty() || V[i].first == now) {
      pq.push(V[i].second);
      sum += V[i].second;
      now = V[i].first;
      continue;
    }
  }
  while (!pq.empty()) {
    ans += sum - pq.top();
    sum -= pq.top();
    pq.pop();
  }
  cout << ans << endl;
  return 0;
}
