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

int main(void) {
	int n, right = 0,left=0,minR=100000,minL=100000;
	scanf("%d", &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];
	for (int i = 0; i < n; i++) {
		if(a[i]){
			left++;
			if (minL > w[i]) minL = w[i];
		}else{
			right++;
			if (minR > w[i]) minR = w[i];
		}
	}
	if(right == 0 || right == n)
		printf("0\n");
	else
		printf("%d\n", minL + minR);
	return 0;
}
