#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a(n, 0), t(n, 0);
long long solve() {
  map<int, set<pair<int, int>>> m;
  for (int i = 0; i < n; i++) {
    m[a[i]].insert({t[i], i});
  }
  long long res = 0;
  int v = 0;
  while (m.size() < n) {
    auto it = m.lower_bound(v);
    v = it->first;
    auto &s = it->second;
    if (s.size() >= 2) {
      int c = s.size();
      for (int ic = 0; ic < c - 1; ic++) {
        auto p = *s.begin();
        s.erase(s.begin());
        int up = c - 1 - ic;
        m[v + up].insert(p);
        res += 1ll * p.first * up;
      }
    }
    v++;
  }
  return res;
}
long long solve2() {
  map<int, set<pair<int, int>>> m;
  for (int i = 0; i < n; i++) {
    m[a[i]].insert({t[i], i});
  }
  long long sumUp = 0, res = 0;
  set<pair<int, int>> up;
  int v = 0;
  while (m.size() < n) {
    auto it = m.lower_bound(v);
    v = it->first;
    auto &s = it->second;
    for (auto &p : s) {
      if (p.first == -1) continue;
      up.insert(p);
      sumUp += p.first;
    }
    s.clear();
    if (!up.empty()) {
      auto it = prev(up.end());
      sumUp -= it->first;
      up.erase(it);
    }
    if (!up.empty()) m[v + 1].insert({-1, -1});
    res += sumUp;
    v++;
  }
  return res;
}
int main() {
  cin >> n;
  a.assign(n, 0), t.assign(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) cin >> t[i];
  auto res2 = solve2();
  cout << res2 << "\n";
  return 0;
}
