#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long> > pq;
pair<long long, long long> ara[200006];
int main() {
  long long n, i, ans, now;
  bool flag;
  pair<long long, long long> val;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &ara[i].first);
  for (i = 1; i <= n; i++) scanf("%lld", &ara[i].second);
  sort(ara + 1, ara + n + 1);
  ara[n + 1].first = 2e9, ans = 0;
  for (i = 1; i <= n; i++) {
    while (ara[i].first == ara[i + 1].first)
      pq.push({ara[i].second, ara[i].first}), i++;
    if (!pq.empty()) {
      pq.push({ara[i].second, ara[i].first});
      now = ara[i].first;
      while (now < ara[i + 1].first && !pq.empty()) {
        val = pq.top();
        ans += ((now - val.second) * val.first);
        now++, pq.pop();
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
