#include <bits/stdc++.h>
using namespace std;
mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
T least_significant_one(T x) {
  return (x & (-x));
}
struct fenwick_tree {
  int n;
  vector<long long> freq, ct;
  fenwick_tree(int N) : n(N), freq(N + 1, 0), ct(N + 1, 0){};
  long long sum(int a) {
    long long res = 0;
    for (; a; a -= least_significant_one(a)) res += freq[a];
    return res;
  }
  long long count(int a) {
    long long res = 0;
    for (; a; a -= least_significant_one(a)) res += ct[a];
    return res;
  }
  long long num(int a) {
    int lo = 1, hi = n;
    while (lo <= hi) {
      int mid = lo + (hi - lo) / 2;
      if (count(mid) < a)
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    return sum(lo) - (count(lo) - a) * lo;
  }
  void add(int a, int v) {
    for (; a <= n; a += least_significant_one(a)) freq[a] += v, ct[a]++;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  long long cur = 0;
  for (auto &x : a) cin >> x.first;
  for (auto &x : a) cin >> x.second, cur += x.second;
  sort(a.begin(), a.end());
  fenwick_tree ft(250);
  long long ans = cur;
  for (int i = 0; i < n;) {
    int j;
    for (j = i; j < n; j++) {
      if (a[j].first == a[i].first) {
        cur -= a[j].second;
      } else
        break;
    }
    int need = max(0, i - (j - i - 1));
    ans = min(ans, cur + ft.num(need));
    for (int k = i; k < j; k++) {
      ft.add(a[k].second, a[k].second);
    }
    i = j;
  }
  cout << ans << endl;
}
