#include <bits/stdc++.h>
using namespace std;
map<int, int> Fa;
struct Categories {
  long long a, t;
  bool operator<(const struct Categories c) const {
    if (t == c.t) return a < c.a;
    return t > c.t;
  }
};
int Find(int x) {
  if (Fa[x] == 0) return x;
  return Fa[x] = Find(Fa[x]);
}
void Un(int a, int b) {
  int aa = Find(a), bb = Find(b);
  if (aa != bb) Fa[aa] = bb;
}
Categories cate[200010];
int main() {
  int n;
  while (cin >> n) {
    Fa.clear();
    for (int i = 0; i < n; i++) {
      cin >> cate[i].a;
    }
    for (int i = 0; i < n; i++) {
      cin >> cate[i].t;
    }
    sort(cate, cate + n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      int tmp = Find(cate[i].a);
      if (tmp == cate[i].a) {
        Un(tmp, tmp + 1);
      } else {
        ans += (tmp - cate[i].a) * cate[i].t;
        Un(tmp, tmp + 1);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
