#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  priority_queue<long long> p;
  vector<vector<long long>> a(n, vector<long long>(2));
  for (long long i = 0; i < n; i++) cin >> a[i][0];
  for (long long i = 0; i < n; i++) cin >> a[i][1];
  sort(a.begin(), a.end());
  long long i = 0, cur = 1, sum = 0, ans = 0;
  while (i < n || p.size()) {
    while (i < n && a[i][0] == cur) {
      sum += a[i][1];
      p.push(a[i][1]);
      i += 1;
    }
    if (p.size() == 0) {
      cur = a[i][0];
    } else {
      sum -= p.top();
      p.pop();
      ans += sum;
      cur += 1;
    }
  }
  cout << ans;
}
