#include <bits/stdc++.h>
long long n, sol, cnt, it = 1, sum;
std::pair<long long, long long> list[200005];
std::priority_queue<long long> pq;
int main() {
  std::cin >> n;
  for (int i = 1; i <= n; ++i) std::cin >> list[i].first;
  for (int i = 1; i <= n; ++i) std::cin >> list[i].second;
  std::sort(list + 1, list + n + 1);
  while (it <= n) {
    if (list[it].first == cnt) {
      pq.push(list[it].second);
      sum += list[it++].second;
      continue;
    } else if (pq.empty()) {
      cnt = list[it].first;
      pq.push(list[it].second);
      sum += list[it++].second;
    } else {
      sum -= pq.top();
      sol += sum;
      pq.pop();
      if (!pq.empty())
        ++cnt;
      else
        cnt = -1;
    }
  }
  while (!pq.empty()) {
    sum -= pq.top();
    sol += sum;
    pq.pop();
  }
  std::cout << sol;
  return 0;
}
