#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long inf = 1e10;
signed main() {
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> arr(n + 1);
  for (long long i = 0; i < n; i++) cin >> arr[i].first;
  for (long long i = 0; i < n; i++) cin >> arr[i].second;
  arr[n] = {inf, 0};
  sort((arr).begin(), (arr).end());
  priority_queue<long long> q;
  long long ans = 0, val = 0, sum = 0;
  for (long long i = 0; i <= n; i++) {
    while (!q.empty() && val < arr[i].first) {
      sum -= q.top();
      q.pop();
      ans += sum;
      val++;
    }
    val = arr[i].first;
    sum += arr[i].second;
    q.push(arr[i].second);
  }
  cout << ans << endl;
  return 0;
}
