#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  cin >> n;
  pair<int, int> v[n];
  for (int i = 0; i < n; i++) cin >> v[i].first;
  for (int i = 0; i < n; i++) cin >> v[i].second;
  sort(v, v + n);
  int pref[n];
  for (int i = 0; i < n; i++) {
    if (i == 0)
      pref[i] = v[i].second;
    else
      pref[i] = pref[i - 1] + v[i].second;
  }
  int lo = 0, mcost = INT_MAX;
  multiset<int> m;
  while (lo < n) {
    int hi = lo;
    while (hi < n && v[hi].first == v[lo].first) {
      hi++;
    }
    hi--;
    int cnt = hi - lo + 1;
    int cost = pref[n - 1] - pref[hi];
    if (lo != 0) cost += pref[lo - 1];
    for (int x : m) {
      if (cnt <= 1) break;
      cost += x;
      cnt--;
    }
    mcost = min(cost, mcost);
    for (int i = lo; i <= hi; i++) m.insert(-v[i].second);
    lo = hi + 1;
  }
  cout << mcost << endl;
  return 0;
}
