#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, z, res = 0, f, curr, ans = 0, y;
  cin >> n;
  int a[n];
  int b[n];
  map<int, int> m;
  unordered_map<int, vector<int> > u;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    m[a[i]]++;
    u[a[i]].push_back(b[i]);
  }
  map<int, int>::iterator it;
  priority_queue<int> pq;
  for (it = m.begin(); it != m.end(); it++) {
    x = (*it).first;
    y = (*it).second;
    if (y > 1 || !pq.empty()) {
      for (int i = 0; i < u[x].size(); i++) {
        pq.push(u[x][i]);
        ans += u[x][i];
      }
      ans -= pq.top();
      pq.pop();
      curr = x;
      while (!pq.empty()) {
        res += ans;
        curr++;
        if (u[curr].size())
          break;
        else {
          ans -= pq.top();
          pq.pop();
        }
      }
    }
  }
  cout << res << "\n";
}
