#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  fastio();
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int f[n];
  for (int i = 0; i < n; i++) cin >> f[i];
  vector<pair<long long int, long long int>> v;
  for (int i = 0; i < n; i++) {
    v.push_back({a[i], f[i]});
  }
  sort(v.begin(), v.end());
  multiset<long long int> m;
  int i = 0;
  long long int cur = 0;
  long long int ans = 0;
  while (m.size() == 0 && i < v.size()) {
    long long int sum = 0;
    cur = v[i].first;
    m.insert(v[i].second);
    sum += v[i].second;
    i++;
    while (1) {
      while (i < v.size() && v[i].first == cur) {
        m.insert(v[i].second);
        sum += v[i].second;
        i++;
      }
      if (m.size() == 0) break;
      sum -= *(prev(m.end()));
      ans += sum;
      m.erase(prev(m.end()));
      cur++;
    }
  }
  cout << ans;
}
