#include <bits/stdc++.h>
using LL = long long;
using namespace std;

int main(){
    int N;cin>>N;
    vector<int> vec;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    vector<int> b1,b2;
    for(int a= 0;a < N;a++){
        int b;cin >> b;
        if(vec.at(a) == 0)b1.push_back(b);
        if(vec.at(a) == 1)b2.push_back(b);
    }
    if(b1.empty() || b2.empty()){
        cout<<0<<endl;
    }else{
        cout<<*min_element(b1.begin(),b1.end())+*min_element(b2.begin(),b2.end())<<endl;
    }
}
//2t+2

