#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N; cin >> N;
    ll a[100005];
    ll f1,f0;
    f1 = f0 = false;
    for (int i = 0;i < N;i++){
        cin >> a[i];
        if(a[i] == 0) f0 = true;
        if(a[i] == 1) f1 = true;
    }
    ll w[100005];
    for (int i = 0;i < N;i++){
        cin >> w[i];
    }

    if(!f0 || !f1) cout << 0 << endl;
    else{
        ll s,t;
        s = t = INT_MAX;
        for (int i = 0;i < N;i++){
            if(a[i] == 0) s = min(s,w[i]);
            else t = min(t,w[i]);
        }
        cout << s+t << endl;
    }

    return 0;

}
