#include <bits/stdc++.h>
using namespace std;
const long long MX = 3e5;
struct Publication {
  long long a, t;
  bool operator<(const Publication &x) const { return t < x.t; }
} P[MX];
bool cmp(Publication &a, Publication &b) { return a.a < b.a; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 0; i < (long long)n; i++) {
    cin >> P[i].a;
  }
  for (long long i = 0; i < (long long)n; i++) {
    cin >> P[i].t;
  }
  sort(P, P + n, cmp);
  priority_queue<Publication> pq;
  long long sum = 0;
  long long i = 0;
  long long ans = 0;
  long long curA = -1;
  while (i < n || !pq.empty()) {
    if (pq.empty()) {
      long long a = P[i].a;
      curA = a;
      while (i < n && P[i].a == a) {
        sum += P[i].t;
        pq.push(P[i]);
        i++;
      }
    } else {
      if (i < n) {
        while (i < n && P[i].a == curA) {
          sum += P[i].t;
          pq.push(P[i]);
          i++;
        }
      }
      curA++;
      sum -= pq.top().t;
      pq.pop();
      ans += sum;
    }
  }
  cout << ans << endl;
  return 0;
}
