#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> A[200005];
long long ans = 0;
void pro(int s, int e) {
  int idx = s;
  priority_queue<int> pq;
  long long sum = 0;
  for (int i = s; i < e; i++) {
    while (idx < e && A[idx].first <= i - s + A[s].first) {
      pq.push(A[idx].second);
      sum += A[idx].second;
      idx++;
    }
    sum -= (long long)pq.top();
    pq.pop();
    ans += sum;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i].first;
  for (int i = 1; i <= n; i++) cin >> A[i].second;
  sort(A + 1, A + n + 1);
  int st = 1, ed = 2;
  while (st <= n && ed <= n) {
    if (A[ed].first - A[st].first > ed - st) {
      pro(st, ed);
      st = ed;
      ed = st + 1;
    } else
      ed++;
  }
  if (st <= n) pro(st, ed);
  cout << ans;
  return 0;
}
