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

int main(){
    int N;
    cin >> N;
    vector<int> hand(N), w(N), yancle;
    for(int i = 0; i < N; i++) cin >> hand[i];
    for(int i = 0; i < N; i++) cin >> w[i];
    for(int i = 1; i < N; i++) yancle.emplace_back(i);

    int ans = 1e9;
    do{ 
        int res = 0;
        int left = yancle[N-3];
        int mid = yancle[N-2];
        int right = 0;
        for(int n = 0; n < N; n++){
            if(hand[mid] == 0 && hand[right] == 1) res += w[mid];
            if(hand[mid] == 1 && hand[left] == 0) res += w[mid];
            left = mid;
            mid = right;
            if(n < N-1) right = yancle[n];
        }
        ans = min(ans, res);
    }while(next_permutation(yancle.begin(), yancle.end()));

    cout << ans << endl;
}
