#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int len[N + 3], d[N + 3], xh[N + 3], T[N + 3];
int n, base, root, ans;
class Lt {
 public:
  int s, sum;
} Q[N * 3 + 3];
bool _comp(const int &A, const int &B) { return d[A] < d[B]; }
bool comp(const int &A, const int &B) { return len[A] < len[B]; }
void Build(int w, int l, int r) {
  if (l == r) {
    Q[w].s = 1;
    Q[w].sum = d[xh[l]];
    return;
  }
  int mid = (l + r) >> 1;
  Build(w << 1, l, mid);
  Build((w << 1) ^ 1, mid + 1, r);
  Q[w].s = Q[w << 1].s + Q[(w << 1) ^ 1].s;
  Q[w].sum = Q[w << 1].sum + Q[(w << 1) ^ 1].sum;
}
int gets(int w, int l, int r, int k) {
  if (l == r) return Q[w].sum;
  int mid = (l + r) >> 1;
  if (k > Q[w << 1].s)
    return Q[w << 1].sum + gets((w << 1) ^ 1, mid + 1, r, k - Q[w << 1].s);
  else
    return gets(w << 1, l, mid, k);
}
void del(int w, int l, int r, int x) {
  if (l == r) {
    Q[w].s = Q[w].sum = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    del(w << 1, l, mid, x);
  else
    del((w << 1) ^ 1, mid + 1, r, x);
  Q[w].s = Q[w << 1].s + Q[(w << 1) ^ 1].s;
  Q[w].sum = Q[w << 1].sum + Q[(w << 1) ^ 1].sum;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &len[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 1; i <= n; i++) xh[i] = i;
  sort(xh + 1, xh + n + 1, _comp);
  for (int i = 1; i <= n; i++) T[xh[i]] = i;
  Build(1, 1, n);
  sort(xh + 1, xh + n + 1, comp);
  ans = 2e9;
  for (int i = n; i >= 1; i--) {
    int w = i;
    for (; w && len[xh[w - 1]] == len[xh[w]]; del(1, 1, n, T[xh[w--]]))
      ;
    del(1, 1, n, T[xh[w]]);
    if (w == 1) {
      ans = min(ans, base);
      break;
    }
    int k = i - w + 1;
    k--;
    k = w - 1 - k;
    if (!k) {
      ans = min(ans, base);
      break;
    }
    int ww = gets(1, 1, n, k);
    ans = min(ans, base + ww);
    for (int j = w; j <= i; j++) base += d[xh[j]];
    i = w;
  }
  printf("%d", ans);
}
