#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
#define pprint(a,m,n) rep(j,0,m){ print(a[j],n); }
const int mod = 1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int N;cin>>N;
	int A[N],W[N];priority_queue<int> left,right;
	rep(i,0,N) cin>>A[i];
	rep(i,0,N){
		cin>>W[i];
		if(A[i]) left.push(-W[i]);
		else right.push(-W[i]); 
	}
	if(left.empty()||right.empty()) cout<<0<<endl;
	else cout<<-left.top()-right.top()<<endl;
	return 0;
}
