#include <bits/stdc++.h>

using namespace std;

int N;
vector<int> PersonId;
vector<int> PersonInfo;
vector<int> Claim;

void solve() {
	int p1, p2, sum, minTotal;

	minTotal = 10000000;
	do {
		sum = 0;
		for (int i = 0; i < N; ++i) {
			p1 = PersonInfo[PersonId[i]];
			p2 = PersonInfo[PersonId[(i + 1) % N]];
			if (!p1 && p2) {
				sum += Claim[PersonId[i]] + Claim[PersonId[(i + 1) % N]];
			}
		}
		minTotal = min(minTotal, sum);
	} while (next_permutation(PersonId.begin(), PersonId.end()));

	cout << minTotal << endl;
}

int main() {
	int num;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		PersonId.push_back(i);
		cin >> num;
		PersonInfo.push_back(num);
	}
	for (int i = 0; i < N; ++i) {
		cin >> num;
		Claim.push_back(num);
	}
	solve();

	return 0;
}
