#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
using namespace std;
struct wor {
  long long c;
  long long t;
};
struct Node {
  int x;
  int y;
  int size;
  Node *left;
  Node *right;
  Node(int x) {
    this->x = x;
    y = rand();
    size = 1;
    left = nullptr;
    right = nullptr;
  }
};
struct treap {
  Node *root;
  treap() { root = nullptr; }
  void recalc(Node *a) {
    int left_size = a->left == nullptr ? 0 : a->left->size;
    int right_size = a->right == nullptr ? 0 : a->right->size;
    a->size = left_size + right_size + 1;
  }
  Node *merge(Node *a, Node *b) {
    if (a == nullptr) {
      return b;
    }
    if (b == nullptr) {
      return a;
    }
    if (a->y > b->y) {
      a->right = merge(a->right, b);
      recalc(a);
      return a;
    } else {
      b->left = merge(a, b->left);
      recalc(b);
      return b;
    }
  }
  pair<Node *, Node *> split(Node *a, int key) {
    if (a == nullptr) {
      return {nullptr, nullptr};
    } else if (a->x <= key) {
      auto alpha = split(a->right, key);
      a->right = alpha.first;
      recalc(a);
      return {a, alpha.second};
    } else {
      auto alpha = split(a->left, key);
      a->left = alpha.second;
      recalc(a);
      return {alpha.first, a};
    }
  }
  void add(int a) {
    auto [alpha, beta] = split(root, a);
    Node *t = new Node(a);
    root = merge(merge(alpha, t), beta);
  }
  int size(int l, int m) {
    auto [alpha, beta] = split(root, l - 1);
    auto [g, v] = split(beta, m - 1);
    int res = 0;
    if (g != nullptr) {
      res = g->size;
    }
    root = merge(alpha, merge(g, v));
    return res;
  }
};
bool operator<(wor a, wor b) { return a.t < b.t; }
int main() {
  int n;
  cin >> n;
  vector<wor> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].c;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].t;
  }
  sort(a.rbegin(), a.rend());
  treap h;
  long long ans = 0;
  for (auto e : a) {
    int l = e.c;
    int r = e.c + n + 2;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      int sz = h.size(e.c, m);
      if (sz < m - e.c) {
        r = m;
      } else {
        l = m;
      }
    }
    ans += (l - e.c) * e.t;
    h.add(l);
  }
  cout << ans;
  return 0;
}
