#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long 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<long long int, vector<long long int> > m;
  for (int i = 0; i < n; ++i) {
    m[a[i]].push_back(b[i]);
  }
  priority_queue<long long int> q;
  long long int ans = 0, sm = 0;
  for (auto &i : m) {
    ans += sm;
    vector<long long int> v = i.second;
    for (int i = 0; i < v.size(); ++i) {
      if (v[i] == -1) {
        continue;
      }
      q.push(v[i]);
      sm += v[i];
    }
    sm -= (q.top());
    q.pop();
    if (sm != 0) {
      m[i.first + 1].push_back(-1);
    }
  }
  cout << ans << "\n";
  return 0;
}
