#include<iostream>
using namespace std;
#define min(a,b) (a>b?b:a)
#define MAX 1010
#define INF 12345678

int N, a[MAX], w[MAX], used[11]={1,};

int huga(int t, int y){
	int dis = 0;
	if(!a[t]&&a[y]) dis += w[t];
	if(a[y]&&!a[t]) dis += w[y];
	return dis;
}

int solve(int z){//cout<<z<<endl;
	int ans = INF, count = 0;
	
	for(int i = 0; i < N; i++){
		if(used[i]) continue;
		used[i] = true;
		ans = min(ans,solve(i)+huga(z,i));
		used[i] = false;
		count++;
	}//cout<<z<<" "<<ans<<" "<<count<<endl;
	if(count == 0) return huga(z,0);
	return ans;
}

int main(){
	cin>>N;
	for(int i = 0; i < N; i++)cin>>a[i];
	for(int i = 0; i < N; i++)cin>>w[i];
	
	cout<<solve(0)<<endl;
	return 0;
}

/*
5
1 0 0 1 0
2 3 5 1 2

3
0 0 0
1 2 3
*/
