#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, F;
  long long int S = 0, s = 0;
  cin >> n;
  vector<pair<int, int> > X(n);
  for (int i = 0; i < n; i++) {
    cin >> X[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> X[i].second;
  }
  sort(X.begin(), X.end());
  priority_queue<int> Y;
  Y.push(X[0].second);
  F = X[0].first;
  s += X[0].second;
  for (long long int i = 1; i < n; i++) {
    if (X[i].first == F) {
      Y.push(X[i].second);
      s += X[i].second;
    } else {
      for (long long int j = 0; j < X[i].first - F; j++) {
        if (!Y.empty()) {
          s -= Y.top();
          Y.pop();
          S += s;
        } else
          break;
      }
      F = X[i].first;
      Y.push(X[i].second);
      s += X[i].second;
    }
  }
  int N = Y.size();
  for (int i = 0; i < N; i++) {
    s -= Y.top();
    Y.pop();
    S += s;
  }
  cout << S;
  return 0;
}
