#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e19;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, i, a, b, c, r, k, x = 0, y, m, j;
  cin >> n;
  vector<pair<long long, long long> > v[n + 1], arr(n);
  for (i = 0; i < n; i++) {
    cin >> m;
    arr[i].first = m;
  }
  for (i = 0; i < n; i++) {
    cin >> m;
    arr[i].second = m;
  }
  sort(arr.begin(), arr.end());
  c = 1;
  v[c].push_back({arr[0].second, c});
  for (i = 1; i < n; i++) {
    if (arr[i].first == arr[i - 1].first)
      v[c].push_back({arr[i].second, c});
    else {
      c = min(i + 1, c + arr[i].first - arr[i - 1].first);
      v[c].push_back({arr[i].second, c});
    }
  }
  multiset<pair<long long, long long>, greater<pair<long long, long long> > > s;
  for (i = 1; i <= n; i++) {
    j = v[i].size();
    while (j) {
      s.insert(v[i][j - 1]);
      v[i].pop_back();
      j = v[i].size();
    }
    v[i].push_back((*s.begin()));
    s.erase(s.begin());
    x = x + (i - v[i][0].second) * (v[i][0].first);
  }
  cout << x << '\n';
}
