#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int N;
int a[10], w[10];
int ans = INT_MAX;

void solve(int already, vector<int> now){
    bool tmp[10] = {};
    for(int i=0; i<already; i++) tmp[now[i]] = true;
    if(already == N){
        int W = 0;
        for(int i=0; i<N-1; i++){
            if(a[now[i]] == 0 && a[now[i+1]] == 1) W += w[now[i]] + w[now[i+1]];
        }
        if(a[now[N-1]] == 0 && a[now[0]] == 1) W += w[now[N-1]] + w[now[0]];
        ans = min(ans, W);
        return;
    }
    for(int i=0; i<N; i++){
        if(tmp[i] == false){
            now[already] = i;
            solve(already+1, now);
            now[already] = -1;
        }
    }
}

int main(){
    iostream::sync_with_stdio(false);
    
    cin >> N;
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N; i++) cin >> w[i];
    vector<int> tmp;
    tmp.push_back(0);
    for(int i=1; i<N; i++) tmp.push_back(-1);
    solve(1, tmp);
    cout << ans << endl;
    
    return 0;
}
