#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  map<int, vector<int>> mp;
  for (int i = 0; i < n; i++) mp[a[i]].push_back(b[i]);
  priority_queue<int> que;
  long long ans = 0;
  long long sum = 0;
  int val = 0;
  for (auto& p : mp) {
    while (que.size() && val < p.first) {
      val++;
      ans += sum;
      sum -= que.top();
      que.pop();
    }
    val = p.first + 1;
    ans += sum;
    for (int x : p.second) {
      que.push(x);
      sum += x;
    }
    sum -= que.top();
    que.pop();
  }
  while (que.size()) {
    ans += sum;
    sum -= que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}
