n = int(input()) info = [list(map(int, input().split())) for i in range(n)] # dp[bit_state][i][j] := bit_stateの積み木を使って、最後に使ったのがi番目の積み木。 # また、i番目の積み木のj番目の辺が高さになっている dp = [[[-1] * (3) for i in range(n)] for j in range(1 << n)] for i in range(n): for j, val in enumerate(info[i]): dp[1 << i][i][j] = val for bit_state in range(1 << n): for i in range(n): if not((1 << i) & bit_state): continue # dp[bit_state][i][?]から遷移出来る for j in range(n): if (1 << j) & bit_state: continue for ii in range(3): for jj in range(3): ai, bi = info[i][(ii + 1) % 3], info[i][(ii + 2) % 3] aj, bj = info[j][(jj + 1) % 3], info[j][(jj + 2) % 3] if dp[bit_state][i][ii] == -1: continue if (aj <= ai and bj <= bi) or (aj <= bi and bj <= ai): dp[bit_state|j][j][jj] = max(dp[bit_state][i][ii] + info[j][jj], dp[bit_state|j][j][jj]) ans = 0 for bit_state in range(1 << n): for i in range(n): for j in range(3): ans = max(ans, dp[bit_state][i][j]) print(ans)