#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N;
	cin >> N;
	
	int a[15], w[15];
	int S1 = 100000, S2 = 100000;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < N; i++){
		cin >> w[i];
		if(a[i]){
			S1 = min(S1, w[i]);
		}else{
			S2 = min(S2, w[i]);
		}
	}
	
	if(S1 == 100000 || S2 == 100000){
		cout << 0 << endl;
	}else{
		cout << S1 + S2 << endl;
	}
	
	return 0;
}

