#include <bits/stdc++.h>

using namespace std;

using i64 = long long int;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()

int main(){
    i64 n;
    cin >> n;
    vector<i64> a(n), w(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> w[i];
    vector<i64> pat(n);
    rep(i, n) pat[i] = i;
    i64 ans = numeric_limits<i64>::max();
    do{
        i64 cost = 0;
        rep(i, n){
            if(i == 0){
                if(a[pat[i]] == 1 && a[pat[i + 1]] == 0) cost += w[pat[i]];
                if(a[pat[i]] == 0 && a[pat[n - 1]] == 1) cost += w[pat[i]];
            }else if(i == n - 1){
                if(a[pat[i]] == 1 && a[pat[0]] == 0) cost += w[pat[i]];
                if(a[pat[i]] == 0 && a[pat[i - 1]] == 1) cost += w[pat[i]];
            }else{
                if(a[pat[i]] == 1 && a[pat[i + 1]] == 0) cost += w[pat[i]];
                if(a[pat[i]] == 0 && a[pat[i - 1]] == 1) cost += w[pat[i]];
            }
        }
        ans = min(ans, cost);
    }while(next_permutation(all(pat)));
    cout << ans << endl;
}
