#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INT = 1e16;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define rep(i,N) FOR(i, 0, N)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).reeal(), (b).real) && EQ((a).imag(), (b).imag()))
#define NIL -1

int main(){
    int n;
    cin>>n;
    vector<int> a(n),w(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>w[i];
    int rmin=100000,lmin=100000;
    rep(i,n){
        if(a[i])lmin=min(lmin,w[i]);
        else rmin=min(rmin,w[i]);
    }
    if(rmin==100000 || lmin==100000)cout<< 0 <<endl;
    else cout<< rmin + lmin <<endl;
}
