#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,ans=1e9;
	cin>>n;
	int a[n],w[n],A[n];
	r(i,n)cin>>a[i];
	r(i,n)cin>>w[i];
	r(i,n)A[i]=i;
	do{
		int sum=0;
		for(int i=0;i<n;i++){
			int X=a[A[i]];
			int Y=a[A[(i+1)%n]];
			if(X&&!Y){
				sum+=w[A[(i+1)%n]]+w[A[i]];
			}
		}
		ans=min(sum,ans);
	}while(next_permutation(A,A+n));

	cout<<ans<<endl;
}
