#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %
         1000000007LL;
}
void Flash() {
  long long n;
  cin >> n;
  pair<long long, long long> a[n];
  map<long long, vector<long long>> mpp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  for (long long i = 0; i < n; i++) {
    cin >> a[i].second;
    mpp[a[i].first].push_back(a[i].second);
  }
  priority_queue<long long> pq;
  long long tSum = 0;
  long long ans = 0;
  vector<long long> temp;
  for (auto it : mpp) {
    for (auto itt : it.second) {
      pq.push(itt);
      tSum += itt;
    }
    tSum -= pq.top();
    pq.pop();
    ans += tSum;
    if (!pq.empty()) {
      mpp.insert(make_pair(it.first + 1, temp));
    }
  }
  cout << ans << "\n";
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
