#include <bits/stdc++.h>
using namespace std;
long long int godram;
int main() {
  long long int n;
  cin >> n;
  long long int b[n + 1];
  long long int g[n + 1];
  long long int a[n + 1];
  long long int i = 1;
  while (i <= n) {
    cin >> a[i];
    long long int p = a[i];
    g[i] = p;
    i++;
  }
  sort(a + 1, a + n + 1);
  multiset<long long int> w;
  long long int max = 0;
  i = 1;
  while (i <= n) {
    if (a[i] <= max) {
      b[i] = max + 1;
      max++;
    } else {
      b[i] = a[i];
      max = a[i];
    }
    w.insert(b[i]);
    i++;
  }
  vector<pair<long long int, long long int>> c;
  i = 1;
  while (i <= n) {
    long long int x;
    cin >> x;
    pair<long long int, long long int> ram = {x, i};
    c.push_back(ram);
    i++;
  }
  sort(c.begin(), c.end());
  i = n - 1;
  while (i >= 0) {
    long long int cost = c[i].first;
    long long int index = c[i].second;
    long long int actual = g[index];
    auto it = w.upper_bound(actual - 1);
    long long int real = *it;
    w.erase(w.find(real));
    godram += abs(actual - real) * cost;
    i--;
  }
  cout << godram;
  return 0;
}
