#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11, mod = 1e9 + 7;
const int INF1 = 2e9 + 11;
const long long INF2 = 2e18 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-12;
const double PI = acos(-1.0);
int n, ans, ct[N], pref[N];
pair<int, int> l[N];
multiset<int> st;
inline int get(int l, int r) {
  if (l > r) return 0;
  return pref[r] - pref[l - 1];
}
int main() {
  if (fopen("queue"
            ".in",
            "r"))
    freopen(
        "queue"
        ".in",
        "r", stdin),
        freopen(
            "queue"
            ".out",
            "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i += 1) cin >> l[i].first, ct[l[i].first]++;
  for (int i = 1; i <= n; i += 1) cin >> l[i].second;
  sort(l + 1, l + n + 1);
  for (int i = 1; i <= n; i += 1) pref[i] = pref[i - 1] + l[i].second;
  int ans = INF1;
  for (int i = 1; i <= n; i += 1) {
    int left = i, right = i + ct[l[i].first] - 1;
    int val = get(right + 1, n);
    int half = right / 2 + 1;
    int cur = 0, need = right - left;
    for (auto it = st.rbegin(); it != st.rend() && need; ++it)
      cur += *it, --need;
    val += get(1, left - 1) - cur;
    ans = min(ans, val);
    for (int j = i; j <= i + ct[l[i].first] - 1; j += 1) st.insert(l[j].second);
    i += ct[l[i].first] - 1;
  }
  cout << ans;
  return 0;
}
