N = int(input()) D = [] for i in range(N): D.append(list(map(int, input().split()))) N2 = 1 << N inf = 10 ** 18 dp = [[-inf] * (N * 3) for i in range(N2)] ans = 0 for i in range(N): for k in range(3): dp[1 << i][i * 3 + k] = D[i][k] ans = max(ans, dp[1 << i][i * 3 + k]) def check(i, j, a, b): if D[i][(a + 1) % 3] <= D[j][(b + 1) % 3] and D[i][(a + 2) % 3] <= D[j][(b + 2) % 3]: return True if D[i][(a + 2) % 3] <= D[j][(b + 1) % 3] and D[i][(a + 1) % 3] <= D[j][(b + 2) % 3]: return True return False for s in range(1, N2): for p in range(3 * N): q, r = divmod(p, 3) if (s >> q) & 1 == 0: continue for i in range(N): if (s >> i) & 1: continue for k in range(3): if check(q, i, r, k): dp[s | (1 << i)][3 * i + k] = max(dp[s | (1 << i)][3 * i + k], dp[s][p] + D[i][k]) ans = max(ans, dp[s | (1 << i)][3 * i + k]) print(ans)