#include <bits/stdc++.h>
template <typename Tp>
void read(Tp &res) {
  static char ch;
  ch = getchar(), res = 0;
  static bool flag;
  flag = 0;
  while (!isdigit(ch)) flag = (ch == '-'), ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - 48, ch = getchar();
  if (flag) res = -res;
}
const int maxn = 2e5 + 19;
long long ans;
int n;
std::pair<int, int> a[maxn];
std::priority_queue<std::pair<int, int>> q;
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i].first);
  for (int i = 1; i <= n; ++i) read(a[i].second);
  std::sort(a + 1, a + 1 + n), a[n + 1].first = 2e9;
  for (int i = 1; i <= n; ++i) {
    int r = i;
    q.emplace(a[r].second, a[r].first);
    while (r < n && a[r + 1].first == a[r].first)
      ++r, q.emplace(a[r].second, a[r].first);
    i = r;
    for (int j = a[i].first; j < a[i + 1].first && q.size(); ++j)
      ans += (long long)q.top().first * (j - q.top().second), q.pop();
  }
  printf("%lld\n", ans);
}
