//* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include // #include using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<> n; vll c(n, vl(n)); rep (i, n) rep (j, n) cin >> c[i][j]; map mp; rep (i, n) { string s(n, '0'); s[i] = '1'; mp[s] = vl(n, INF); mp[s][i] = 0; } ll ans = INF; for (auto itr = mp.begin(); itr != mp.end(); itr++) { string s = itr->first; vl dp = itr->second; rep (i, n) { ll cost = dp[i]; rep (j, n) { if (i == j) continue; if (s[j] == '2') continue; string s2 = s; s2[j]++; if (mp.count(s2) == 0) { mp[s2] = vl(n, INF); } chmin(mp[s2][j], cost + c[i][j]); int cnt1 = 0, cnt2 = 0; rep (i, s2.size()) { if (s2[i] == '1') cnt1++; else if (s2[i] == '2') cnt2++; } if (cnt1 == 1 and cnt2 == n - 1 and s2[j] == '1') { chmin(ans, cost + c[i][j]); } } } } string res(n, '2'); vl dp = mp[res]; rep (i, n) chmin(ans, dp[i]); cout << ans << endl; }