#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
using namespace std;
const long double pi = acosl(-1);
template <class T>
bool uax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool uin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void solve() {
  int n;
  cin >> n;
  map<int, vector<int> > A;
  long long S = 0, ans = 0;
  vector<pair<int, int> > input(n, pair<int, int>(1000000000, 100000));
  for (int i = 0; i < (int)(n); ++i) {
    cin >> input[i].first;
  }
  for (int i = 0; i < (int)(n); ++i) {
    cin >> input[i].second;
  }
  for (int i = 0; i < (int)(n); ++i) {
    A[input[i].first].push_back(input[i].second);
  }
  A[1000000000 + n + 1].resize(0);
  multiset<int> M;
  int px = -1;
  for (auto& [x, vy] : A) {
    while (px < x && !M.empty()) {
      auto it = M.end();
      --it;
      S -= *it;
      M.erase(it);
      ans += S;
      px += 1;
    }
    px = x;
    for (int e : vy) {
      M.insert(e);
      S += e;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed;
  cout.precision(15);
  cerr << fixed;
  cerr.precision(15);
  solve();
  return 0;
}
