#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 200000;
pair<int, int> cat[MAXN + 2];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> cat[i].first;
  for (int i = 0; i < n; i++) cin >> cat[i].second;
  sort(cat, cat + n);
  priority_queue<int> pq;
  long long sum = 0, ans = 0;
  int x = 0, i = 0;
  do {
    if (pq.empty()) {
      if (i >= n) break;
      x = cat[i].first;
    }
    while (cat[i].first == x) {
      sum += cat[i].second;
      pq.push(cat[i].second);
      i++;
    }
    sum -= pq.top();
    pq.pop();
    ans += sum;
    ++x;
  } while (true);
  cout << ans << '\n';
}
