#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, X[10];
	vector<long long> V[2];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> X[i];
	for (int i = 0; i < N; i++) {
		long long Y;
		cin >> Y;
		V[X[i]].push_back(Y);
	}
	if (V[0].empty() || V[1].empty()) {
		cout << 0 << endl;
		return 0;
	}
	sort(V[0].begin(), V[0].end());
	sort(V[1].begin(), V[1].end());
	cout << V[0][0] + V[1][0] << endl;
}
