#include<bits/stdc++.h>
#define INF INT_MAX
using namespace std;
int main(void){
	int n;
	cin >> n;
	int a[n], b[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	int rmn = INF, lmn = INF;
	for(int i = 0; i < n; i++){
		if(a[i]) lmn = min(lmn, b[i]);
		else rmn = min(rmn, b[i]);
	}
	if(rmn == INF || lmn == INF) cout << 0 << endl;
	else cout << rmn + lmn << endl;
	return 0;
}
