#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << ", ";
  err(++it, args...);
}
const long long inf = 1LL << 60;
const long long md = 1000000007;
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  map<long long, vector<long long>> v;
  set<pair<long long, long long>> s;
  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;
    mp[a[i]] += x;
    v[a[i]].push_back(x);
  }
  long long ans = 0;
  long long y = 0;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    for (auto j : v[i->first]) s.insert({j, y}), y++;
    long long xx = s.rbegin()->first;
    long long yy = s.rbegin()->second;
    s.erase({xx, yy});
    if (s.size()) {
      ans += i->second - xx;
      mp[i->first + 1] += (i->second - xx);
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
    cout << '\n';
  }
}
