#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    vector<int> b(0),c(0);
    int o;
    rep(i,n){
        cin >> o;
        if (a.at(i)==0) b.push_back(o);
        else c.push_back(o);
    }
    if (b.size()==0 || c.size()==0) {cout << 0 << endl;return 0;} 
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    cout << b.at(0)+c.at(0) << endl;

}

