#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 1000000007;
const long long INF = 1e12;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> t(n + 1);
  for (long long i = 0; i < n; i++) cin >> t[i];
  t[n] = 0;
  a[n] = 1e10;
  ++n;
  vector<long long> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(),
       [&](long long i, long long j) { return a[i] < a[j]; });
  long long ans = 0;
  long long last = 0;
  multiset<long long> s;
  long long sum = 0;
  for (auto i : ord) {
    while (a[i] > last && !s.empty()) {
      ++last;
      auto it = prev(s.end());
      sum -= *it;
      s.erase(it);
      ans += sum;
    }
    last = a[i];
    s.insert(t[i]);
    sum += t[i];
  }
  cout << ans;
}
