#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), w(n);
  vector<int> r, l;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> w[i];
    if (a[i]) {
      l.push_back(w[i]);
    } else {
      r.push_back(w[i]);
    }
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  if (l.size() == 0 || r.size() == 0) {
    cout << 0 << endl;
  } else {
    cout << r[0] + l[0] << endl;
  }
  return 0;
}

