#include #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=int(a);i=int(b);--i) #define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__) #define _all(arg) begin(arg),end(arg) #define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg)) #define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary) #define clr(a,b) memset((a),(b),sizeof(a)) #define bit(n) (1LL<<(n)) #define popcount(n) (__builtin_popcountll(n)) using namespace std; templatebool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;} templatebool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;} using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);} inline R sq(R x) {return sqrt(max(x, 0.0L));} const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; // Problem Specific Parameter: vector min_cost_match(vector> a) { int n = a.size(), m = a[0].size(); vector left(n, -1), right(m, -1); vector ofsleft(n, 0), ofsright(m, 0); auto cost = [&](int i, int j) { return a[i][j] + ofsleft[i] + ofsright[j];}; rep(r, n) { vector s(n, false), t(m, false); vector trace(m, -1), edge(m, r); s[r] = true; int b = -1; while (1) { int d = numeric_limits::max(); rep(j, m) if (!t[j]) d = min(d, cost(edge[j], j)); rep(i, n) if (s[i]) ofsleft[i] -= d; rep(j, m) if (t[j]) ofsright[j] += d; rep(j, m) if (!t[j] && cost(edge[j], j) == 0) b = j; trace[b] = edge[b]; int c = right[b]; if (c < 0) break; s[c] = t[b] = true; rep(j, m) if (cost(c, j) < cost(edge[j], j)) edge[j] = c; } while (b >= 0) { int a = trace[b], nb = left[a]; right[b] = a, left[a] = b, b = nb; } } return left; } int f[24][24]; int main(void) { int n; cin >> n; rep(i, n)rep(j, n) cin >> f[i][j]; int ans = 0; rep(mask, 1 << n) { if (mask & 1) continue; if (__builtin_popcountll(mask) != n / 2) continue; vector a, b; rep(i, n) { if (mask & (1 << i)) a.push_back(i); else b.push_back(i); } vector> c(n / 2, vector(n / 2, 0)); rep(i, n / 2)rep(j, n / 2) c[i][j] = -f[a[i]][b[j]]; vector idx = min_cost_match(c); int cur = 0; rep(i, n / 2) cur += c[i][idx[i]]; chmin(ans, cur); } cout << -ans << endl; return 0; }