#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int &x : arr) {
    cin >> x;
  }
  map<int, vector<int>> cost;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    cost[arr[i]].push_back(tmp);
  }
  long long price = 0, curp = 0;
  sort(arr.begin(), arr.end());
  arr.erase(unique(arr.begin(), arr.end()), arr.end());
  priority_queue<long long> tmp;
  for (auto x : arr) {
    for (auto i = 0; i < cost[x].size(); i++) {
      curp += cost[x][i];
      tmp.push(cost[x][i]);
    }
    curp -= tmp.top();
    int dist = x;
    dist++;
    tmp.pop();
    int ext = 0;
    while (!tmp.empty()) {
      price += curp;
      if (cost[dist].size()) {
        break;
      } else {
        curp -= tmp.top();
        dist++;
        tmp.pop();
      }
    }
  }
  cout << price << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int testcase = 1;
  for (int i = 0; i < testcase; i++) {
    solve();
  }
  return 0;
}
