#include <bits/stdc++.h>
using namespace std;
template <typename T>
vector<T>& operator--(vector<T>& v) {
  for (auto& i : v) --i;
  return v;
}
template <typename T>
vector<T>& operator++(vector<T>& v) {
  for (auto& i : v) ++i;
  return v;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& i : v) os << i << ' ';
  return os;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
template <typename T, typename U>
void umin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void umax(T& a, U b) {
  if (a < b) a = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<long long> a(n);
  cin >> a;
  vector<long long> t(n);
  cin >> t;
  long long ans = 0;
  set<pair<long long, int>> s;
  map<long long, vector<int>> m;
  for (int i = 0; i < n; ++i) {
    m[a[i]].push_back(i);
  }
  int clast = -100;
  m[(long long)1e12].clear();
  for (auto& [cnew, v] : m) {
    while (clast < cnew && !s.empty()) {
      auto it = --s.end();
      ans += (clast - a[it->second]) * t[it->second];
      ++clast;
      s.erase(it);
    }
    clast = cnew;
    for (auto k : v) {
      s.emplace(t[k], k);
    }
  }
  cout << ans << endl;
  return 0;
}
