#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int x;
  cin >> x;
  vector<pair<int, int>> v(x);
  for (int i = 0; i < x; i++) cin >> v[i].first;
  for (int i = 0; i < x; i++) cin >> v[i].second;
  sort(v.begin(), v.end());
  priority_queue<int> q;
  long long ans = 0, sum = 0, val = v[0].first;
  int i = 0;
  sort(v.begin(), v.end());
  while (i < x || !q.empty()) {
    while (i < x && val == v[i].first) {
      sum += v[i].second;
      q.push(v[i].second);
      i++;
    }
    sum -= q.top();
    ans += sum;
    q.pop();
    if (q.empty())
      val = v[i].first;
    else
      val++;
  }
  cout << ans;
  return 0;
}
