#include <bits/stdc++.h>
using namespace std;
int gcd(int A, int B) {
  if (!B) return A;
  return gcd(B, A % B);
}
int n;
long long int ans = 0, sum = 0;
multiset<int> s;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<int> a(n), t(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> t[i];
  a.push_back((int)(1.01e9));
  t.push_back(0);
  n++;
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) { return a[i] < a[j]; });
  int last = 0;
  for (int x : order) {
    while (a[x] > last && !s.empty()) {
      last++;
      auto it = prev(s.end());
      sum -= *it;
      s.erase(it);
      ans += sum;
    }
    last = a[x];
    s.insert(t[x]);
    sum += t[x];
  }
  cout << ans;
}
