#nullable enable #region var (_input, _iter) = (Array.Empty(), 0); string String() { while (_iter >= _input.Length) (_input, _iter) = (Console.ReadLine()!.Trim().Split(' '), 0); return _input[_iter++]; } T I() where T : IParsable => T.Parse(String(), null); #endregion var n = I(); var d = new int[n, n]; for (var i = 0; i < n; i++) for (var j = 0; j < n; j++) d[i, j] = I(); var m = n.ToFlag(); var dp = new long[m, n]; var max = long.MaxValue / 8; for (var i = 0; i < m; i++) for (var j = 0; j < n; j++) dp[i, j] = max; dp[1, 0] = 0; for (var s = 1; s < m; s++) { for (var i = 0; i < n; i++) { for (var j = 0; j < n; j++) { if (s.OfFlag(j)) continue; var ns = s.WithFlag(j, true); dp[ns, j] = Math.Min(dp[ns, j], dp[s, i] + d[i, j] * (n - int.PopCount(s))); } } } var ans = max; for (var i = 0; i < n; i++) ans = Math.Min(dp[m - 1, i], ans); Console.WriteLine(ans); static class BitExtensions { public static int ToFlag(this int i) { if (i < 0 || 31 <= i) throw new IndexOutOfRangeException(); return 1 << i; } public static bool OfFlag(this int value, int i) => (value & ToFlag(i)) > 0; public static int WithFlag(this int value, int i, bool f) => f ? (value | ToFlag(i)) : (value & ~ToFlag(i)); public static int FlagCount(this int value) => int.PopCount(value); public static int HighestFlagIndex(this int value) => 31 - int.LeadingZeroCount(value); }