#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int> > b(n);
  unsigned long long ans = 0;
  for (int i = 0; i < n; i++) cin >> b[i].first;
  for (int i = 0; i < n; i++) cin >> b[i].second;
  sort(b.begin(), b.end());
  int x = b[0].first;
  multiset<int> s;
  unsigned long long su = 0;
  for (int i = 0; i < n; i++) {
    if (b[i].first != x) {
      for (int j = x; j < b[i].first; j++) {
        if (s.empty()) break;
        int r = (*s.rbegin());
        s.erase(s.lower_bound(r));
        su -= r;
        ans += su;
      }
      x = b[i].first;
    }
    s.insert(b[i].second), su += b[i].second;
  }
  while (!s.empty()) {
    int r = (*s.rbegin());
    s.erase(s.lower_bound(r));
    su -= r;
    ans += su;
  }
  cout << ans << endl;
}
