#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long mod = 1e18;
long long fast_pow(long long b, long long p) {
  if (p == 0) return 1;
  long long m = fast_pow(b, p / 2);
  m = ((m % mod) * (m % mod)) % mod;
  if (p % 2 == 1) m = ((m % mod) * (b % mod)) % mod;
  return m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  pair<int, int> arr[N];
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> arr[i].second;
  }
  sort(arr, arr + n);
  long long cu = 1;
  priority_queue<long long> q;
  long long sum = 0;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (q.empty()) cu = arr[i].first;
    if (arr[i].first == cu) {
      q.push(arr[i].second);
      sum += arr[i].second;
    } else {
      sum -= q.top();
      q.pop();
      ans += sum;
      while (q.size() && (++cu) < arr[i].first) {
        sum -= q.top();
        q.pop();
        ans += sum;
      }
      i--;
    }
  }
  while (q.size()) {
    sum -= q.top();
    q.pop();
    ans += sum;
  }
  cout << ans;
  return 0;
}
