#include <bits/stdc++.h>
using namespace std;
struct Cate {
  long long a, t;
  bool operator<(const Cate &rhs) const {
    return a < rhs.a || (a == rhs.a && t < rhs.t);
  }
} category[200005];
long long n;
priority_queue<long long> p;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) scanf("%lld", &category[i].a);
  for (long long i = 0; i < n; i++) scanf("%lld", &category[i].t);
  sort(category, category + n);
  long long cnt = 0;
  long long a = category[0].a;
  long long now = 0;
  long long sum = 0;
  while (true) {
    while (cnt < n && category[cnt].a == a) {
      p.push(category[cnt].t);
      now += category[cnt].t;
      cnt++;
    }
    now -= p.top();
    p.pop();
    sum += now;
    if (cnt == n && p.empty()) break;
    if (!p.empty())
      a++;
    else
      a = category[cnt].a;
  }
  cout << sum << endl;
}
