#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
priority_queue<int> pr;
int cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > ve(n);
  for (auto &p : ve) cin >> p.first;
  for (auto &p : ve) cin >> p.second;
  sort(ve.begin(), ve.end(), cmp);
  int l = 0;
  long long ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    int cnt = ve[i].first - l;
    if (cnt > 0) {
      for (int j = 0; j < cnt && !pr.empty(); j++)
        sum -= pr.top(), pr.pop(), ans += sum;
      l = ve[i].first;
    }
    pr.push(ve[i].second);
    sum += ve[i].second;
  }
  while (!pr.empty()) sum -= pr.top(), pr.pop(), ans += sum;
  cout << ans << endl;
  return 0;
}
