#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> a(n),w(n);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>w[i];
  vector<int> x,y;
  for(int i=0;i<n;i++)
    (a[i]?x:y).emplace_back(w[i]);
  if(x.empty()||y.empty()){
    cout<<0<<endl;
    return 0;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  cout<<x[0]+y[0]<<endl;
  return 0;
}

