#include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define int long long

using namespace std;

signed main(){
	
	int n; cin >> n;
	vector<int> a(n);
	vector<int> w(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	for(int i = 0; i < n; i++){
		cin >> w[i];
	}

	vector<int> p(n);
	for(int i = 0; i < n; i++) p[i] = i;
	int ans = 1000000000000000007;
	
	do{
		int tmp = 0;
		for(int i = 0; i < n; i++){
			int val = a[p[i]];
			if(val == 0){
				// みぎきき
				// int idx = 
				int idx = (i + 1) % n;
				int val2 = a[p[idx]];
				if(val2 == 1) tmp += w[p[i]];
			}else{

				int idx = (i + n - 1) % n;
				int val2 = a[p[idx]];
				if(val2 == 0) tmp += w[p[i]];
			}
		}

		ans = min(ans, tmp);
	}while(next_permutation(p.begin(), p.end()));
	
	cout << ans << endl;
	return 0;
}


