#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> w(n);
  for(int i=0;i<n;++i) cin >> a[i];
  for(int i=0;i<n;++i) cin >> w[i];

  int rmin=1001,lmin=1001,rnum=0,lnum=0;
  for(int i=0;i<n;++i){
    if(a[i]==0){
      if(rmin>w[i]) rmin = w[i];
      rnum++;
    }else{
      if(lmin>w[i]) lmin = w[i];
      lnum++;
    }
  }

  if(rnum==n||lnum==n){
    rmin=0;
    lmin=0;
  }

    cout << rmin + lmin << endl;
  
  return 0;
}


