#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const long long MAXN = 3e5 + 10, inf = 1e9 + 10;
long long n, m, ans;
struct node {
  long long a, t;
  friend bool operator<(node x, node y) { return x.a < y.a; }
} q[MAXN];
priority_queue<long long> f;
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) q[i].a = read();
  for (long long i = 1; i <= n; i++) q[i].t = read();
  for (long long i = 1; i <= n; i++) ans -= q[i].a * q[i].t;
  sort(q + 1, q + n + 1);
  long long p = 0, tot = 1;
  while (tot <= n || !f.empty()) {
    if (f.empty()) p = q[tot].a;
    while (tot <= n && q[tot].a <= p) {
      f.push(q[tot].t);
      tot++;
    }
    ans += p * f.top();
    p++;
    f.pop();
  }
  printf("%lld\n", ans);
  return 0;
}
