#include <bits/stdc++.h>
using namespace std;
long long sol = 0;
int pMax = 0;
void findNextAvailable(set<int>& s, map<int, int>& m, int pos) {
  if (m.find(pos + 1) == m.end()) s.insert(pos + 1);
}
void insertMap(set<int>& s, map<int, int>& m, pair<int, int> val) {
  if (m.find(val.first) == m.end()) {
    m[val.first]++;
    if (s.find(val.first) != s.end()) {
      s.erase(s.find(val.first));
    }
    findNextAvailable(s, m, val.first);
  } else {
    auto it = s.upper_bound(val.first);
    int pos = *it;
    sol += (0ll + pos - val.first) * val.second;
    s.erase(it);
    findNextAvailable(s, m, pos);
    m[pos]++;
  }
}
int cmp(const pair<int, int>& a, const pair<int, int>& b) {
  return a.second > b.second;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) cin >> a[i].first;
  for (int i = 0; i < n; i++) cin >> a[i].second;
  sort(a.begin(), a.end(), cmp);
  set<int> s;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    insertMap(s, m, a[i]);
  }
  cout << sol << endl;
  return 0;
}
