#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; ll dp[1 << 16][16]; } int main() { ios::sync_with_stdio(false); cin.tie(0); constexpr long long INF = 1002003004005006007; rep(s, 1 << 16) rep(u, 16) dp[s][u] = INF; int n; cin >> n; int d[16][16]; rep(i, n) rep(j, n) cin >> d[i][j]; rep(k, n) rep(i, n) rep(j, n) chmin(d[i][j], d[i][k] + d[k][j]); dp[1][0] = 0; rep(s, 1 << n) { int rest = n - popcount(0U + s); rep(u, n) if (ll now = dp[s][u]; now != INF) { rep(v, n) if (~s >> v & 1) { chmin(dp[s | 1 << v][v], now + d[u][v] * rest); } } } ll ans = INF; rep(u, n) chmin(ans, dp[(1 << n) - 1][u]); cout << ans << '\n'; }