#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<size_t> idx(N);
  std::iota(idx.begin(), idx.end(), 0);

  std::vector<int> a(N), w(N);
  for (auto& ai: a) scanf("%d", &ai);
  for (auto& wi: w) scanf("%d", &wi);

  int res = 1e9;
  do {
    int cur = 0;
    for (size_t i = 0; i < N; ++i) {
      size_t ii = idx[i];
      size_t jj = idx[(i+1)%N];
      if (a[ii] == 0 && a[jj] == 1) {
        cur += w[ii];
      } else if (a[ii] == 1 && a[jj] == 0) {
        cur += w[ii];
      }
    }
    res = std::min(res, cur);
  } while (std::next_permutation(idx.begin(), idx.end()));
  printf("%d\n", res);
}

