#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
using namespace std;
const long long N = 1e5 + 10;
long long n, cnt[N], l[N], d[N], num[N << 2], sum[N << 2], vis[N],
    res = 1e18, s[N], now, tmp;
vector<long long> v[N];
void change(long long p, long long l, long long r, long long x, long long v) {
  if (l == r) {
    sum[p] += x * v, num[p] += v;
    return;
  }
  long long mid = l + r >> 1;
  if (x <= mid)
    change(p << 1, l, mid, x, v);
  else
    change(p << 1 | 1, mid + 1, r, x, v);
  sum[p] = sum[p << 1] + sum[p << 1 | 1],
  num[p] = num[p << 1] + num[p << 1 | 1];
}
long long ask(long long p, long long l, long long r, long long s) {
  if (l == r) return s * l;
  long long mid = l + r >> 1;
  if (num[p << 1] >= s)
    return ask(p << 1, l, mid, s);
  else
    return sum[p << 1] + ask(p << 1 | 1, mid + 1, r, s - num[p << 1]);
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) scanf("%lld", &l[i]);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &d[i]), v[l[i]].push_back(d[i]), s[l[i]] += d[i];
    change(1, 1, 1e5, d[i], 1);
    cnt[l[i]]++;
  }
  now = n;
  for (long long i = 1e5; i >= 1; i--) {
    if (!cnt[i]) continue;
    for (auto j : v[i]) change(1, 1, 1e5, j, -1);
    long long need = now - cnt[i] * 2 + 1;
    if (need <= 0) {
      res = min(res, tmp);
      now -= cnt[i];
      break;
    }
    res = min(res, tmp + ask(1, 1, 1e5, need));
    now -= cnt[i];
    tmp += s[i];
  }
  cout << res;
  return 0;
}
