#include <iostream>
#include <cstdio>
#include <string>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	/*
	int n;
	cin >> n;
	vector<vector<int>> f(n, vector<int>(6));
	for(int j = 0; j < n; j++)
		for (int i = 0; i < 6; i++) cin >> f[j][i];

	// 相手のカードもわかる 6 + 6 + 1 = 13のため
	bool win = true;


	// 自分が出し終わるあとの数字が相手に残っている
	*/

	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];

	int rmin = 10000;
	int lmin = 10000;

	bool all = true;
	int r = a[0];
	for (int i = 0; i < n; i++) {
		if (r != a[i]) {
			all = false;
		}
		if (a[i] == 0) rmin = min(rmin, w[i]);
		else lmin = min(lmin, w[i]);
	}

	if (all) cout << 0 << endl;
	else cout << rmin + lmin << endl;

}
