#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T, class U>
using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
const int INF = 1e9;
int n;
V<P<int, int> > at;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  at.resize(n);
  for (int i = 0; i < n; i++) cin >> at[i].first;
  for (int i = 0; i < n; i++) cin >> at[i].second;
  sort(at.begin(), at.end());
  ll ans = 0;
  ll mc = 0;
  int preva = at[0].first;
  map<int, int> cost;
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      for (int nxti = at[i - 1].first + 1; nxti < at[i].first && mc > 0;
           nxti++) {
        ans += mc;
        mc -= -(*cost.begin()).first;
        cost[(*cost.begin()).first]--;
        if ((*cost.begin()).second == 0) cost.erase((*cost.begin()).first);
      }
    }
    ans += mc;
    int j = i;
    for (; j < n && at[i].first == at[j].first; j++) {
      cost[-at[j].second]++;
      mc += at[j].second;
    }
    i = j - 1;
    mc -= -(*cost.begin()).first;
    cost[(*cost.begin()).first]--;
    if ((*cost.begin()).second == 0) cost.erase((*cost.begin()).first);
  }
  while (mc > 0) {
    ans += mc;
    mc -= -(*cost.begin()).first;
    cost[(*cost.begin()).first]--;
    if ((*cost.begin()).second == 0) cost.erase((*cost.begin()).first);
  }
  cout << ans << '\n';
  return 0;
}
