#include <iostream>
#include <algorithm>
using namespace std;

int N, A[1 << 18], W[1 << 18], minx = (1 << 30);
int p[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> W[i];

	do {
		int sum = 0;
		for (int i = 0; i < N; i++) {
			if (A[p[i]] == 0) {
				if (A[p[(i + 1) % N]] == 1) sum += W[p[i]];
			}
			else {
				if (A[p[(i + N - 1) % N]] == 0) sum += W[p[i]];
			}
		}
		minx = min(minx, sum);
	} while (next_permutation(p, p + N));

	cout << minx << endl;
	return 0;
}
