#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int power(long long int x, unsigned long long int y,
                    long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  pair<long long int, long long int> arr[n + 1];
  for (long long int i = 0; i < n; i++) cin >> arr[i].first;
  for (long long int i = 0; i < n; i++) cin >> arr[i].second;
  sort(arr, arr + n);
  priority_queue<long long int, vector<long long int> > pq;
  long long int ans = 0, sum = 0, val;
  for (long long int i = 0; i < n + 1; i++) {
    while (pq.size() && (i == n || arr[i].first > val)) {
      sum -= pq.top();
      pq.pop();
      ans += sum;
      val++;
    }
    if (i == n) break;
    val = arr[i].first;
    sum += arr[i].second;
    pq.push(arr[i].second);
  }
  cout << ans;
  return 0;
}
