#include <bits/stdc++.h>
using namespace std;
const int o = 1 << 17;
const int MAXN = 100005;
struct node {
  int num, sum;
  node(int a = 0, int b = 0) {
    num = a;
    sum = b;
  }
};
int n;
int sol;
pair<int, int> a[MAXN];
node t[o * 4];
int fin[MAXN], sum[MAXN];
void update(int x, int lo, int hi, int y) {
  if (y >= hi || y < lo) return;
  if (lo == hi - 1) {
    t[x].num++;
    t[x].sum += y;
    return;
  }
  int mid = (lo + hi) / 2;
  update(x * 2, lo, mid, y);
  update(x * 2 + 1, mid, hi, y);
  t[x].sum = t[x * 2].sum + t[x * 2 + 1].sum;
  t[x].num = t[x * 2].num + t[x * 2 + 1].num;
}
int query(int x, int lo, int hi, int y) {
  if (y == 0) return 0;
  if (lo == hi - 1) {
    return lo * y;
  }
  int l = t[x * 2].num;
  int r = t[x * 2 + 1].num;
  int mid = (lo + hi) / 2;
  if (l <= y) return t[x * 2].sum + query(x * 2 + 1, mid, hi, y - l);
  return query(x * 2, lo, mid, y);
}
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i].first;
  for (int i = 0; i < n; i++) cin >> a[i].second;
  sort(a, a + n);
  for (int i = n - 1; i >= 0; i--) {
    sum[i] = sum[i + 1] + a[i].second;
    fin[a[i].first] = max(fin[a[i].first], i);
  }
  sol = sum[0];
  for (int i = 0; i < n; i++) {
    int curr = sum[fin[a[i].first] + 1];
    int l = fin[a[i].first] + 1;
    int numB = fin[a[i].first] - i + 1;
    int numS = l - numB;
    curr += query(1, 0, o, max(0, numS - numB + 1));
    sol = min(sol, curr);
    for (int j = i; j <= fin[a[i].first]; j++) update(1, 0, o, a[j].second);
    i = fin[a[i].first];
  }
  cout << sol << endl;
  return 0;
}
