#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[20],b[20];
int main(){
	int n;cin>>n;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n)scanf("%d",&b[i]);
	vector<int>v;
	rep(i,n)v.push_back(i);
	int Min=INT_MAX;
	do{
		int cnt=0;
		rep(i,n){
			int j=v[i],k;
			if(a[v[i]]==0){
				k=v[(i+1)%n];
			}
			else{
				k=v[(i+n-1)%n];
			}
			if(a[j]!=a[k])cnt+=b[j];
		}
		Min=min(Min,cnt);
	}while(next_permutation(v.begin(),v.end()));
	cout<<Min<<endl;
}
