#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005], x;
priority_queue<int> q;
int a[100005], b[100005];
int main(int argc, char** argv) {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    int x = a[i], y = b[i];
    v[x].push_back(y);
    sum += y;
  }
  int ans = 0;
  for (int i = 1; i <= 100000; i++) {
    int t = 0;
    for (int j = 0; j < v[i].size(); j++) t += v[i][j];
    x.clear();
    for (int j = 1; j < v[i].size(); j++) {
      if (!q.empty()) x.push_back(q.top()), t += q.top(), q.pop();
    }
    for (auto j : x) q.push(j);
    for (auto j : v[i]) q.push(j);
    ans = max(ans, t);
  }
  cout << sum - ans;
  return 0;
}
