def input_int(): return int(input()) def input_ints(): return list(map(int, input().split())) N = input_int() A = [] B = [] C = [] for _ in range(N): a, b, c = sorted(input_ints()) A.append(a) B.append(b) C.append(c) # 0: AB # 1: AC # 2: BC def height(k): i, j = divmod(k, 3) if j == 0: return C[i] elif j == 1: return B[i] else: return A[i] def face(k): i, j = divmod(k, 3) if j == 0: return A[i], B[i] elif j == 1: return A[i], C[i] else: return B[i], C[i] INF = 10**9 dp = [[-INF for j in range(N * 3)] for i in range(1 << N)] for i in range(N): dp[1 << i][i * 3 + 0] = height(i * 3 + 0) dp[1 << i][i * 3 + 1] = height(i * 3 + 1) dp[1 << i][i * 3 + 2] = height(i * 3 + 2) def can(x, y): f1 = face(x) f2 = face(y) return f1[0] <= f2[0] and f1[1] <= f2[1] ans = 0 for i in range(1 << N): for j in range(N * 3): if dp[i] == -INF: continue ans = max(ans, dp[i][j]) for k in range(N * 3): kx = k // 3 if ~i >> kx & 1: if can(j, k): dp[i | 1 << kx][k] = max(dp[i | 1 << kx][k], dp[i][j] + height(k)) print(ans)