#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool umax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
template <long long sz>
using tut = array<long long, sz>;
const long long N = 2e5 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long double Pi = acos(-1);
void add(long long& a, long long b) { a = (a + b) % mod; }
void sub(long long& a, long long b) { a = ((a - b) % mod + mod) % mod; }
void mul(long long& a, long long b) { a = (a * 1ll * b) % mod; }
long long n, m, k, t, q, ans, res, a[N];
long long b[N];
void solve(long long t_case) {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) cin >> b[i];
  map<long long, vector<long long> > tt;
  for (long long i = 1; i <= n; i++) tt[a[i]].push_back(b[i]);
  priority_queue<long long> qq;
  long long sum = 0, last = 0;
  for (auto x : tt) {
    while (last < x.first && !qq.empty())
      sum -= qq.top(), qq.pop(), res += sum, last++;
    last = x.first;
    for (auto xx : x.second) sum += xx, qq.push(xx);
  }
  while (!qq.empty()) sum -= qq.top(), qq.pop(), res += sum;
  cout << res << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (0) {
    long long t;
    cin >> t;
    for (long long t_case = 1; t_case <= t; t_case++) solve(t_case);
  } else
    solve(1);
  return 0;
}
