#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T& x) {
  return x * x;
}
template <class T>
inline void updMin(T& a, const T& b) {
  if (b < a) a = b;
}
template <class T>
inline void updMax(T& a, const T& b) {
  if (b > a) a = b;
}
const int maxn = 200005;
int n;
int a[maxn];
int c[maxn];
multiset<pair<long long, int>> p;
int A[maxn];
int C[maxn];
long long ANS = 0;
int N = 5;
void print(multiset<pair<long long, int>> p) {
  for (auto x : p) {
    cout << x.first << " " << x.second << endl;
  }
  cout << endl;
}
bool check() {
  multiset<int> used;
  for (int i = 0; i < N; i++) {
    if (used.find(A[i]) != used.end()) {
      return false;
    }
    used.insert(A[i]);
  }
  return true;
}
void brute(int i, long long cost) {
  if (cost > ANS) {
    return;
  }
  if (i == N) {
    if (cost < ANS && check()) {
      ANS = cost;
    }
    return;
  }
  for (int j = 0; j <= N; j++) {
    A[i] += j;
    brute(i + 1, cost + C[i] * j);
    A[i] -= j;
  }
}
long long solve() {
  p.clear();
  for (int i = 0; i < n; i++) {
    p.insert(make_pair(A[i], -C[i]));
  }
  int last_a = -1;
  long long ans = 0;
  multiset<pair<long long, int>> pending;
  while (p.size()) {
    pair<long long, int> x = *p.begin();
    int aa = x.first;
    int cc = -x.second;
    pending.insert(make_pair(-cc, aa));
    p.erase(p.begin());
    int ax = aa - 1;
    while (pending.size()) {
      ax++;
      cerr << "Before adding " << ax << endl;
      print(pending);
      while (p.size() && p.begin()->first == ax) {
        pending.insert(make_pair(p.begin()->second, p.begin()->first));
        p.erase(p.begin());
      }
      cerr << "After adding " << ax << endl;
      print(pending);
      pair<long long, int> x = *pending.begin();
      int ccur = -x.first;
      int acur = x.second;
      pending.erase(pending.begin());
      long long dx = ax - acur;
      long long dc = ccur;
      ans += dx * dc;
      cerr << " adding for group " << aa << " from " << acur << ", " << ccur
           << " to " << ax << ", cost=" << dx * dc << endl;
    }
    cerr << "iteration passed, set size: " << p.size() << endl;
  }
  cout << ans << endl;
  return ans;
}
int ITER = 0;
void gen() {
  n = N;
  for (int i = 0; i < N; i++) {
    A[i] = a[i] = rand() % 5;
    C[i] = c[i] = rand() % 5;
  }
  ANS = 1000000000000000LL;
  brute(0, 0);
  if (ANS != solve()) {
    cout << "FAILED needed " << ANS << " got " << solve() << endl;
    cout << N << endl;
    for (int i = 0; i < N; i++) {
      cout << A[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < N; i++) {
      cout << C[i] << " ";
    }
    cout << endl;
    exit(0);
  } else {
    cout << ++ITER << " OK\n";
  }
}
map<int, vector<long long>> aa;
int main() {
  srand(42);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    p.insert(make_pair(a[i], -c[i]));
  }
  int last_a = -1;
  long long ans = 0;
  multiset<pair<long long, int>> pending;
  while (p.size()) {
    pair<long long, int> x = *p.begin();
    int aa = x.first;
    int cc = -x.second;
    pending.insert(make_pair(-cc, aa));
    p.erase(p.begin());
    int ax = aa - 1;
    while (pending.size()) {
      ax++;
      while (p.size() && p.begin()->first == ax) {
        pending.insert(make_pair(p.begin()->second, p.begin()->first));
        p.erase(p.begin());
      }
      pair<long long, int> x = *pending.begin();
      int ccur = -x.first;
      int acur = x.second;
      pending.erase(pending.begin());
      long long dx = ax - acur;
      long long dc = ccur;
      ans += dx * dc;
    }
  }
  cout << ans << endl;
  return 0;
}
