#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gi() {
  T f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;
int n;
struct Node {
  int l, d;
} a[N];
long long tr[N << 2], sum[N << 2];
int t[N];
long long suf[N], pre[N], ans;
inline bool cmp(Node x, Node y) { return x.l < y.l; }
inline int ls(int p) { return p << 1; }
inline int rs(int p) { return p << 1 | 1; }
inline void pushup(int p) {
  tr[p] = tr[ls(p)] + tr[rs(p)], sum[p] = sum[ls(p)] + sum[rs(p)];
}
void modify(int x, int l, int r, int p) {
  if (l == r) {
    ++tr[p];
    sum[p] += x;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    modify(x, l, mid, ls(p));
  else
    modify(x, mid + 1, r, rs(p));
  pushup(p);
}
long long getans(int x, int k, int l, int r, int p) {
  if (k >= tr[p]) return sum[p];
  if (l == r) return (long long)l * min(1ll * k, tr[p]);
  int mid = (l + r) >> 1;
  if (k >= tr[rs(p)])
    return sum[rs(p)] + getans(x, k - tr[rs(p)], l, mid, ls(p));
  else
    return getans(x, k, mid + 1, r, rs(p));
}
int main() {
  n = gi<int>();
  for (int i = 1; i <= n; i += 1) a[i].l = gi<int>(), ++t[a[i].l];
  for (int i = 1; i <= n; i += 1) a[i].d = gi<int>();
  sort(a + 1, a + 1 + n, cmp);
  for (int i = n; i >= 1; i -= 1) suf[i] = suf[i + 1] + a[i].d;
  for (int i = 1; i <= n; i += 1) pre[i] = pre[i - 1] + a[i].d;
  ans = suf[1];
  for (int i = 1; i <= n; i += 1) {
    if (a[i].l == a[i - 1].l) continue;
    int now = a[i].l, x = t[now];
    int tmp = x - 1;
    ans = min(ans, suf[i + x] + pre[i - 1] - getans(100000, tmp, 1, 100000, 1));
    for (int j = i; j <= i + x - 1; j += 1) modify(a[j].d, 1, 100000, 1);
    i = i + x - 1;
  }
  printf("%lld\n", ans);
  return 0;
}
