#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> a,w[2];

	cin >> N;
	a.resize(N);
	for(int i = 0; i < N; i++)
		cin >> a[i];
	llong in;
	for(int i = 0; i < N; i++){
		cin >> in;
		w[a[i]].push_back(in);
	}

	sort(BE(w[0]));
	sort(BE(w[1]));

	llong ans = 0;
	if(w[0].size() && w[1].size())
		ans += w[0][0] + w[1][0];

	cout << ans << endl;

	return 0;
}
