#include using namespace std; int main() { ios::sync_with_stdio(false); int N; { cin >> N; } vector> X(N, vector(N)); { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cin >> X[i][j]; } } } vector A(N); { for (int i = 0; i < N; ++i) { cin >> A[i]; } } int res = accumulate(A.begin(), A.end(), 0); for (int s = 0; s < 1 << N; ++s) { int cost = 0; { for (int i = 0; i < N; ++i) if (s >> i & 1) { cost += A[i]; } } int t = s; { for (int i = 0; i < N; ++i) { bool ok = true; for (int j = 0; j < N; ++j) { ok &= (s >> j & 1) || !X[i][j]; } t |= ok << i; } } if (t == (1 << N) - 1) res = min(res, cost); } cout << res << endl; }