#include <bits/stdc++.h>
using namespace std;
const int maxN = (int)1e5 + 100;
const int MAX = (int)1e5 + 1;
int l[maxN], d[maxN], cnt[maxN], q[maxN];
vector<int> pool[maxN];
multiset<int> p;
void solveTask() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> l[i];
  for (int i = 1; i <= n; ++i) cin >> d[i];
  for (int i = 1; i <= n; ++i)
    q[l[i]] += d[i], cnt[l[i]] += 1, pool[l[i]].push_back(d[i]);
  int answer = 0;
  int all_sum = 0;
  for (int i = 1; i <= MAX; ++i) {
    if (cnt[i] == 0) continue;
    int possibleCnt = cnt[i] - 1;
    int cur_sum = 0;
    for (set<int>::iterator it = p.begin(); it != p.end(); ++it) {
      if (possibleCnt == 0) break;
      cur_sum -= *it;
      --possibleCnt;
    }
    answer = max(answer, cur_sum + q[i]);
    all_sum += q[i];
    for (int j = 0; j < pool[i].size(); ++j) {
      p.insert(-pool[i][j]);
    }
  }
  cout << all_sum - answer << endl;
}
int main() {
  solveTask();
  ios_base::sync_with_stdio(false);
  return 0;
}
