#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> l[100007], d[100007], t[100007];
int ds[100007];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &l[i].first);
    l[i].second = i;
    t[i].first = l[i].first;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &d[i].first);
    d[i].second = i;
    t[i].second = d[i].first;
  }
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  sort(l, l + n);
  sort(d, d + n, greater<pair<int, int> >());
  for (int i = 0; i < n; ++i) ds[i] = t[l[i].second].second;
  for (int i = 1; i < n; ++i) ds[i] += ds[i - 1];
  int ans = 1e9 + 7;
  for (int i = 0; i < n; ++i) {
    int k = 1, s = i, sum = 0;
    while (i < n - 1 && l[i].first == l[i + 1].first) ++k, ++i;
    if (s != 0) sum += ds[s - 1];
    sum += ds[n - 1] - ds[s + k - 1];
    --k;
    int j = 0;
    while (k && j < n) {
      if (t[d[j].second].first < l[s].first) sum -= d[j].first, --k;
      ++j;
    }
    ans = min(ans, sum);
  }
  printf("%d\n", ans);
  return 0;
}
