#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)2e5 + 7;
const long long MOD = (long long)1e9 + 7;
const long long inf = (long long)1e9 + 7;
const long long INF = (long long)1e18 + 7;
long long n, suf[N], st[N], lst[N], cnt[N];
pair<long long, long long> p[N];
vector<long long> v[N];
void solve() {
  cin >> n;
  long long ans = inf;
  for (long long i = 1; i <= n; ++i) cin >> p[i].first;
  for (long long i = 1; i <= n; ++i) cin >> p[i].second;
  sort(p + 1, p + 1 + n);
  for (long long i = 1; i <= n; ++i) {
    if (st[p[i].first] == 0) st[p[i].first] = i;
    lst[p[i].first] = i, cnt[p[i].first]++;
  }
  for (long long i = 1; i <= n; ++i) {
    v[p[i].second].push_back(p[i].first);
  }
  for (long long i = n; i >= 1; --i) suf[i] = suf[i + 1] + p[i].second;
  for (long long i = 1; i <= 100000; ++i) {
    long long cur = 0;
    if (cnt[i] == 0) continue;
    cur += suf[lst[i] + 1];
    long long c = cnt[i];
    long long need = max(0ll, ((st[i] - 1) - (c - 1)));
    for (long long h = 1; h <= 200; ++h) {
      vector<long long>::iterator it =
          upper_bound(v[h].begin(), v[h].end(), i - 1);
      long long j = it - v[h].begin();
      long long del = min(need, j);
      cur += del * h;
      need -= del;
    }
    ans = min(ans, cur);
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  for (long long i = 1; i <= test; i++) {
    solve();
  }
  return 0;
}
