#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
void run() {
  long long n;
  cin >> n;
  vector<long long> a(n), cost(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; ++i) {
    cin >> cost[i];
  }
  vector<pair<long long, long long> > v(n);
  for (long long i = 0; i < n; ++i) {
    v[i] = {a[i], cost[i]};
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  long long sum = 0;
  multiset<long long> costs;
  long long itr = 0;
  long long cur_val = v[0].first;
  while (itr < n || costs.size()) {
    if (costs.size() == 0 && v[itr].first != cur_val) {
      cur_val = v[itr].first;
    }
    while (itr < n && v[itr].first == cur_val) {
      costs.insert(v[itr].second);
      sum += v[itr].second;
      ++itr;
    }
    long long max_val = *costs.rbegin();
    ans += sum - max_val;
    costs.erase(costs.find(max_val));
    sum -= max_val;
    cur_val++;
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  run();
  return 0;
}
