#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1E9 + 7, INF = 2E18 + 5;
const double PI = 2 * acos(0.0);
const long double EPS = 1.0E-14;
pair<long long, long long> pt[200005];
bool comp(const pair<long long, long long> &A,
          const pair<long long, long long> &B) {
  if (A.first == B.first)
    return A.second < B.second;
  else
    return A.first < B.first;
}
priority_queue<long long> pq;
int main() {
  long long n, ans = 0, cur = 0, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &pt[i].first);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &pt[i].second);
  }
  sort(pt, pt + n, comp);
  for (int i = 0; i < n; i++) {
    if (cur == pt[i].first) {
      pq.push(pt[i].second);
      sum += pt[i].second;
    } else {
      if (!pq.empty()) {
        sum -= pq.top();
        pq.pop();
        ans += sum;
        cur++;
        i--;
      } else {
        sum += pt[i].second;
        cur = pt[i].first;
        pq.push(pt[i].second);
      }
    }
  }
  while (!pq.empty()) {
    sum -= pq.top();
    pq.pop();
    ans += sum;
  }
  printf("%lld\n", ans);
  return 0;
}
