#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 100010;
int N;
vector<int> d[MAX_N];
int sumD[MAX_N];
int L[MAX_N];
int D[MAX_N];
int sum;
int main() {
  cin >> N;
  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    sumD[L[i]] += D[i];
    d[L[i]].push_back(D[i]);
    sum += D[i];
  }
  priority_queue<int> Que;
  int ans = 1145141919;
  for (int i = 1; i < MAX_N; i++) {
    int rest = sum - sumD[i];
    int size = d[i].size() - 1;
    vector<int> tmp;
    while (Que.size() > 0 and size > 0) {
      int t = Que.top();
      Que.pop();
      rest -= t;
      tmp.push_back(t);
      size--;
    }
    for (auto &val : d[i]) {
      Que.push(val);
    }
    for (auto &val : tmp) {
      Que.push(val);
    }
    ans = min(ans, rest);
  }
  cout << ans << endl;
  return 0;
}
