#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {

    int N; cin >> N;
    vector<int> a(N), w(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> w[i];

    vector<int> v(N, 0);
    iota(v.begin(), v.end(), 0);
    int ans = 1e8;
    do {

        int tmp = 0;
        rep(i, N) {
            // 右効き

            if (a[v[i]] == 0) {
                if (i+1 == N) {
                    if (a[v[0]] == 1) tmp += w[v[i]];
                }
                else {
                    if (a[v[i+1]] == 1) tmp += w[v[i]];
                }
            }
            else {
                if (i == 0) {
                    if (a[v[N-1]] == 0) tmp += w[v[i]];
                }
                else {
                    if (a[v[i-1]] == 0) tmp += w[v[i]];
                }
            }
        }

        ans = min(ans, tmp);

    } while (next_permutation(v.begin(), v.end()));

    cout << ans << endl;
    return 0;
}

