#include <bits/stdc++.h>
#include <assert.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n), w(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> w[i];
	int r = -1, l = -1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 0)
			r = (r == -1 ? w[i] : min(r, w[i]));
		else
			l = (l == -1 ? w[i] : min(l, w[i]));
	}
	cout << (r == -1 || l == -1 ? 0 : l + r) << endl;

	return 0;
}

