#include <bits/stdc++.h>
using namespace std;
void setup() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
}
signed main() {
  setup();
  long long n;
  cin >> n;
  map<long long, vector<long long>> a;
  vector<pair<long long, long long>> tmp(n);
  for (long long i = 0; i < n; ++i) cin >> tmp[i].first;
  map<long long, long long> sum;
  for (long long i = 0; i < n; ++i) cin >> tmp[i].second;
  for (auto i : tmp) {
    sum[i.first] = 0;
    a[i.first].push_back(i.second);
  }
  long long ans = 0;
  multiset<long long> now;
  for (auto i : sum) {
    for (auto j : a[i.first]) {
      i.second += j;
      now.insert(j);
    }
    ans += i.second - *now.rbegin();
    if (i.second - *now.rbegin()) sum[i.first + 1] += i.second - *now.rbegin();
    now.erase(now.find(*now.rbegin()));
  }
  cout << ans << '\n';
}
