#include using namespace std; int main() { const int inf = 2000000000; int n; cin >> n; vector c(n, vector(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; } } vector power(n + 1, 1); int s = 1; for (int i = 0; i < n; i++) { s *= 3; power[i + 1] = s; } vector cost(s, vector(n, inf)); for (int i = 0; i < n; i++) { cost[power[i]][i] = 0; } for (int i = 0; i < s; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (j == k) continue; if (i / power[k] % 3 == 2) continue; int newi = i + power[k]; cost[newi][k] = min(cost[newi][k], cost[i][j] + c[j][k]); } } } int ans = inf; for (int i = 0; i < n; i++) { ans = min({ans, cost[s - 1][i], cost[s - 1 - power[i]][i], cost[s - 1 - 2 * power[i]][i]}); } cout << ans << endl; }