import heapq def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 c = [] for _ in range(N): row = list(map(int, input[idx:idx+N])) c.append(row) idx += N target = (1 << N) - 1 heap = [] INF = float('inf') distance = {} for s in range(1, N+1): w_mask = 1 << (s-1) b_mask = 0 state = (s, w_mask, b_mask) distance[state] = 0 heapq.heappush(heap, (0, s, w_mask, b_mask)) min_cost = INF while heap: cost, current_p, w_mask, b_mask = heapq.heappop(heap) state_key = (current_p, w_mask, b_mask) if cost > distance.get(state_key, INF): continue if w_mask == target: if (b_mask & (1 << (current_p - 1))) != 0: if cost < min_cost: min_cost = cost continue for q in range(1, N+1): if (w_mask & (1 << (q-1))) != 0: continue new_cost = cost + c[current_p-1][q-1] new_w_mask_A = w_mask | (1 << (q-1)) if new_w_mask_A == target: if (b_mask & (1 << (current_p - 1))) != 0: if new_cost < min_cost: min_cost = new_cost continue if (b_mask & (1 << (current_p - 1))) == 0: new_w_mask = new_w_mask_A & ~(1 << (current_p - 1)) new_b_mask = b_mask | (1 << (current_p - 1)) else: new_w_mask = new_w_mask_A new_b_mask = b_mask new_state = (q, new_w_mask, new_b_mask) if new_cost < distance.get(new_state, INF): distance[new_state] = new_cost heapq.heappush(heap, (new_cost, q, new_w_mask, new_b_mask)) print(min_cost) if __name__ == '__main__': main()