#include #ifdef _DEBUG #include "debug.hpp" #else #define debug(...) #endif #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long; using ld = long double; using pll = pair; const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932; template inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; } int dp[1<<20]; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector> x(n, vector(n)); rep(i, n) rep(j, n) cin >> x[i][j]; vector a(n); rep(i, n) cin >> a[i]; vector mask(n); rep(i, n) { int t = 0; rep(j, n) { if(x[i][j]) t |= 1<>i&1) continue; int d = ((S&mask[i]) == mask[i] ? 0 : a[i]); chmin(dp[S|1<