#include <bits/stdc++.h>
using namespace std;
map<long long int, vector<long long int>> arr;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int &i : a) {
    cin >> i;
  }
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    arr[a[i]].push_back(x);
  }
  long long int res = 0;
  priority_queue<long long int> temp;
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  bool done = false;
  long long int ans = 0;
  for (auto v : a) {
    if (arr[v].size() > 1 || !temp.empty()) {
      for (long long int i = 0; i < arr[v].size(); i++) {
        temp.push(arr[v][i]);
        ans += arr[v][i];
      }
      ans -= temp.top();
      temp.pop();
      long long int curr = v;
      while (!temp.empty()) {
        curr++;
        res += ans;
        if (arr[curr].size()) {
          break;
        } else {
          ans -= temp.top();
          temp.pop();
        }
      }
    }
  }
  cout << res << endl;
}
int main() {
  solve();
  return 0;
}
