#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const double eps = 1e-10;
const long long N = 1e3 + 7;
const long long MOD = 1e9 + 7;
long long pw(long long b, long long p) {
  b %= MOD;
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (long long i = 0; i < n; i++) cin >> a[i].first;
  for (long long i = 0; i < n; i++) cin >> a[i].second;
  sort(a.begin(), a.end());
  a.emplace_back(0, 0);
  vector<long long> suf(n + 1), pre(n + 1);
  for (long long i = n - 1; i >= 0; i--) suf[i] = suf[i + 1] + a[i].second;
  for (long long i = 0; i < n; i++)
    pre[i] = (!i ? a[i].second : pre[i - 1] + a[i].second);
  multiset<long long> temp, temp2;
  long long x = 1, ans = 0x3f3f3f3f3f3f3f3fLL;
  for (long long i = 0; i < n; i++) {
    if (a[i].first == a[i + 1].first) {
      temp2.insert(a[i].second);
      x++;
      continue;
    }
    long long cur = suf[i + 1];
    long long y = i + 1 - x;
    long long flag = 0;
    if (x <= y) {
      cur += pre[i - x];
      long long tt = x - 1;
      auto it = prev(temp.end());
      while (tt--) {
        cur -= *it;
        if (it == temp.begin()) {
          flag = 1;
          break;
        }
        it = prev(it);
      }
    }
    if (!flag) ans = min(ans, cur);
    x = 1;
    for (auto it : temp2) temp.insert(it);
    temp2.clear();
    temp.insert(a[i].second);
  }
  cout << ans;
  return 0;
}
