#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin >> n;
    
    vector<int> te(n);
    vector<int> fu(n);
    
    for( int i = 0; i < n; i++ ){
        cin >> te[i];
    }
    
    for( int i = 0; i < n; i++ ){
        cin >> fu[i];
    }
    
    int left = 1001, right = 1001, lc = 0, rc = 0;
    for( int i = 0; i < n; i++ ){
        if( te[i] == 0 ){
            if( right > fu[i] ){
                right = fu[i];
                rc++;
            }
        }
        
        if( te[i] == 1 ){
            if( left > fu[i] ){
                left = fu[i];
                lc++;
            }
        }
    }
    
    if( lc == 0 || rc == 0 ){
        cout << 0 << endl;
    }else{
        cout << right + left << endl;
    }
}

