#include <bits/stdc++.h>
using namespace std;
struct node {
  int idx;
  int val;
};
node nodes[4 * 1000007];
int l[1000007], d[1000007], c[1000007], f[1000007];
pair<int, int> a[1000007], b[1000007];
void updateSumIT(int root, int left, int right, int i, int j, int x) {
  if (i > right || j < left) return;
  if (i <= left && right <= j) {
    nodes[root].val = x;
    return;
  }
  int mid = (left + right) / 2;
  updateSumIT(2 * root, left, mid, i, j, x);
  updateSumIT(2 * root + 1, mid + 1, right, i, j, x);
  nodes[root].val = nodes[2 * root].val + nodes[2 * root + 1].val;
  return;
}
int querySumIT(int root, int left, int right, int i, int j) {
  if (i > right || j < left) return 0;
  if (i <= left && right <= j) return nodes[root].val;
  int mid = (left + right) / 2;
  return querySumIT(2 * root, left, mid, i, j) +
         querySumIT(2 * root + 1, mid + 1, right, i, j);
}
void updateIdxIT(int root, int left, int right, int i, int j) {
  if (i > right || j < left) return;
  if (i <= left && right <= j) {
    nodes[root].idx = 1;
    return;
  }
  int mid = (left + right) / 2;
  updateIdxIT(2 * root, left, mid, i, j);
  updateIdxIT(2 * root + 1, mid + 1, right, i, j);
  nodes[root].idx = nodes[2 * root].idx + nodes[2 * root + 1].idx;
  return;
}
int queryIdxIT(int root, int left, int right, int i, int j) {
  if (i > right || j < left) return 0;
  if (i <= left && right <= j) return nodes[root].idx;
  int mid = (left + right) / 2;
  return queryIdxIT(2 * root, left, mid, i, j) +
         queryIdxIT(2 * root + 1, mid + 1, right, i, j);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", &l[i]);
  for (int i = (1); i <= (n); ++i) scanf("%d", &d[i]);
  for (int i = (1); i <= (n); ++i) a[i] = make_pair(l[i], d[i]);
  sort(a + 1, a + n + 1);
  for (int i = (1); i <= (n); ++i) b[i] = make_pair(a[i].second, i);
  sort(b + 1, b + n + 1);
  for (int i = (1); i <= (n); ++i) c[b[i].second] = i;
  for (int i = (n); i >= (1); --i) f[i] = f[i + 1] + a[i].second;
  int cur = 0;
  int ans = 1000000007LL;
  queue<int> q;
  for (int i = (1); i <= (n); ++i) {
    if (a[i].first == a[i - 1].first)
      q.push(i);
    else {
      while (q.size()) {
        updateIdxIT(1, 1, n, c[q.front()], c[q.front()]);
        updateSumIT(1, 1, n, c[q.front()], c[q.front()], a[q.front()].second);
        q.pop();
      }
      q.push(i);
    }
    int k = i - (2 * (int)q.size() - 1);
    int res = f[i + 1];
    int left = 0;
    int right = n + 1;
    while (left < right - 1) {
      int mid = (left + right) / 2;
      if (queryIdxIT(1, 1, n, 1, mid) <= k)
        left = mid;
      else
        right = mid;
    }
    if (queryIdxIT(1, 1, n, 1, left) < k) continue;
    res += querySumIT(1, 1, n, 1, left);
    ans = min(ans, res);
  }
  printf("%d\n", ans);
  return 0;
}
