#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
const long long inf = 1e+9;
#pragma comment(linker, "/STACK:36777216")
template <typename T>
istream &operator>>(istream &, vector<T> &);
template <typename T>
ostream &operator<<(ostream &, const vector<T> &);
void solve() {
  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());
  long long ans = 0;
  long long cur = a[0].first;
  map<int, int> sp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    while (sp.size() && (a[i].first != cur)) {
      auto it = (--sp.end());
      sum -= it->first;
      ans += sum;
      it->second--;
      if (it->second == 0) {
        sp.erase(it);
      }
      cur++;
    }
    cur = a[i].first;
    int add = 0;
    while (i + add < n && a[i + add].first == cur) {
      sp[a[i + add].second]++;
      sum += a[i + add].second;
      add++;
    }
    i += add - 1;
  }
  while (sp.size()) {
    auto it = (--sp.end());
    sum -= it->first;
    ans += sum;
    it->second--;
    if (it->second == 0) {
      sp.erase(it);
    }
    cur++;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) is >> v[i];
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) os << v[i] << " ";
  return os;
}
