#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, a[12], w[12], p[12];

  scanf("%d", &n);

  for(int i=0;i<n;i++)
    scanf("%d", a+i);

  for(int i=0;i<n;i++)
    scanf("%d", w+i);

  int ans = INF;
  iota(p, p+n, 0);

  do{
    int sum = 0;
    
    for(int i=0;i<n;i++){
      if(a[p[i]] == 0)
        sum += w[p[i]] * (a[p[i]] != a[p[(i+1)%n]]);
      if(a[p[i]] == 1)
        sum += w[p[i]] * (a[p[i]] != a[p[(i+n-1)%n]]);
    }

    ans = min(ans, sum);

  }while(next_permutation(p, p+n));

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


