#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long double pi = 3.1415926535897932384626433;
const long long inf = 1e18;
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = ((res % mod) * (x % mod)) % mod;
    y = y >> 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long max(long long a, long long b) {
  long long sol = a > b ? a : b;
  return sol;
}
long long min(long long a, long long b) {
  long long sol = a < b ? a : b;
  return sol;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<pair<long long, long long>> b;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    b.push_back({a[i], x});
  }
  sort(b.begin(), b.end());
  long long sum = 0;
  long long ans = 0;
  sum = b[0].second;
  multiset<long long> s;
  s.insert(b[0].second);
  for (long long i = 1; i < n; i++) {
    if (b[i].first == b[i - 1].first) {
      s.insert(b[i].second);
      sum += b[i].second;
    } else {
      long long k = b[i].first - b[i - 1].first;
      while (k and s.size()) {
        sum -= *(--s.end());
        s.erase(--s.end());
        ans += sum;
        k--;
      }
      s.insert(b[i].second);
      sum += b[i].second;
    }
  }
  while (s.size()) {
    sum -= *(--s.end());
    s.erase(--s.end());
    ans += sum;
  }
  cout << ans;
}
