#include <bits/stdc++.h>
using namespace std;
struct dat {
  long long a, d, h;
} a[300005];
bool cmp(dat a, dat b) {
  if (a.a == b.a) return a.d < b.d;
  return a.a < b.a;
}
priority_queue<pair<long long, long long> > pq1, pq2;
int main() {
  long long n, i, nr, sum = 0, ind, ans, del, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i].a;
  }
  for (i = 1; i <= n; i++) {
    cin >> a[i].d;
  }
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    pq2.push({-a[i].d, i});
  }
  ans = 1e18;
  del = 0;
  sum = 0;
  nr = 0;
  for (i = n; i >= 1;) {
    while (!pq1.empty() && a[pq1.top().second].a >= a[i].a) {
      ind = pq1.top().second;
      pq1.pop();
      nr -= a[ind].h;
      sum -= a[ind].d * a[ind].h;
      a[ind].h = 0;
    }
    j = i;
    while (a[j].a >= a[i].a) {
      ind = j;
      sum -= a[ind].d * a[ind].h;
      nr -= a[ind].h;
      a[ind].h = 0;
      j--;
    }
    while ((i - nr) - (i - j) * 2 < 0 && !pq1.empty()) {
      ind = pq1.top().second;
      pq1.pop();
      nr -= a[ind].h;
      sum -= a[ind].d * a[ind].h;
      a[ind].h = 0;
      if (a[ind].a < a[i].a) {
        pq2.push({-a[ind].d, ind});
      }
    }
    while ((i - nr) - (i - j) * 2 >= 0) {
      ind = pq2.top().second;
      pq2.pop();
      if (ind > j) continue;
      pq1.push({a[ind].d, ind});
      a[ind].h = 1;
      nr++;
      sum += a[ind].d;
    }
    if ((i - nr) - (i - j) * 2 < 0) ans = min(ans, sum + del);
    while (i > j) del += a[i--].d;
    i = j;
  }
  cout << ans << '\n';
  return 0;
}
