#include using namespace std; using ll = long long int; using ull = unsigned long long int; using P = pair; using P3 = pair; using PP = pair

; constexpr ll MOD = 998244353; constexpr int IINF = INT_MAX; constexpr ll LLINF = LLONG_MAX; constexpr int MAX_N = int(1e6) + 5; constexpr double EPS = 1e-8; constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0}; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define SORT(v) sort((v).begin(), (v).end()) #define SORTR(v) sort((v).rbegin(), (v).rend()) #define ALL(v) (v).begin(), (v).end() int main(){ int n; cin >> n; vector > x(n, vector(n)); for(int i=0;i> x[i][j]; } } vector a(n); for(int i=0;i> a[i]; } int ans = IINF; for(int S=0;S<1<>i)&1) continue; bool ok = true; for(int j=0;j>j)&1) || ((S>>j)&1); } if(ok){ T |= 1<>i)&1) cost += a[i]; } ans = min(ans, cost); } } cout << ans << endl; return 0; }