// 2018/12/10 Tazoe

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

int main()
{
	int N;
	cin >> N;

	int a[10];
	for(int i=0; i<N; i++){
		cin >> a[i];
	}

	int w[10];
	for(int i=0; i<N; i++){
		cin >> w[i];
	}

	int wmin0 = 1001;
	int wmin1 = 1001;

	for(int i=0; i<N; i++){
		if(a[i]==0){
			wmin0 = min(wmin0, w[i]);
		}
		else{
			wmin1 = min(wmin1, w[i]);
		}
	}

	if(wmin0==1001 || wmin1==1001){
		cout << 0 << endl;
	}
	else{
		cout << wmin0+wmin1 << endl;
	}

	return 0;
}

