#include <bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
const long long int M1 = 998244353;
const long long int M2 = 1000000000000000001;
long long int ceill(long long int a, long long int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
long long int extended_gcd(long long int a, long long int b, long long int &x,
                           long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1, ans = extended_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return ans;
}
long long int power_mod(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b != 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    a = a * a;
    a %= m;
    b /= 2;
  }
  return ans;
}
long long int mod_inverse(long long int a, long long int m) {
  return power_mod(a, m - 2, m);
}
void mod_inverse_array(long long int inv[], long long int u, long long int m) {
  inv[1] = 1;
  for (long long int i = 2; i <= u; i++) {
    inv[i] = ((-(m / i) * inv[m % i] % m) + m) % m;
  }
}
long long int N_C_r_mod_m(long long int N, long long int r,
                          long long int factorial[]) {
  long long int a = factorial[N], b = mod_inverse(factorial[N - r], M),
                c = mod_inverse(factorial[r], M);
  return ((a * b) % M * c) % M;
}
void prime_factorization(long long int n,
                         unordered_map<long long int, long long int> &m) {
  long long int i;
  for (i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      m[i]++;
      n = n / i;
    }
  }
  if (n != 1) m[n]++;
}
void linear_sieve(vector<long long int> &pr, long long int lp[],
                  long long int N) {
  for (long long int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (long long int j = 0;
         j < (long long int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
}
void solve() {
  long long int n;
  cin >> n;
  long long int A[n], T[n];
  map<long long int, vector<long long int>> map;
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> A[i];
  }
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> T[i];
  }
  for (long long int i = 0; i <= n - 1; i++) {
    map[A[i]].push_back(T[i]);
  }
  long long int timer = 0, sum = 0;
  priority_queue<long long int> pq;
  long long int current = 0;
  for (auto x : map) {
    if (current == x.first) {
      for (long long int y : x.second) {
        pq.push(y);
        sum += y;
      }
      if (!pq.empty()) {
        sum -= pq.top();
        pq.pop();
        timer += sum;
      }
      current++;
    } else {
      while (!pq.empty() && current < x.first) {
        sum -= pq.top();
        timer += sum;
        pq.pop();
        current++;
      }
      current = x.first;
      for (long long int y : x.second) {
        pq.push(y);
        sum += y;
      }
      if (!pq.empty()) {
        sum -= pq.top();
        pq.pop();
        timer += sum;
      }
      current++;
    }
  }
  while (!pq.empty()) {
    sum -= pq.top();
    timer += sum;
    pq.pop();
  }
  cout << timer << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) solve();
}
