import sys import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 10**18 N = int(readline()) m = map(int, read().split()) ABC = list(zip(m, m, m)) pattern = [None] * (3 * N) for i in range(N): a, b, c = sorted(ABC[i]) pattern[3 * i] = (a, b, c) pattern[3 * i + 1] = (b, c, a) pattern[3 * i + 2] = (a, c, b) dp = [[-INF] * (3 * N) for _ in range(1 << N)] for i in range(N): for k in range(3): dp[1 << i][3 * i + k] = pattern[3 * i + k][2] for s in range(1 << N): for i in range(N): if not (s & (1 << i)): continue for j in range(N): if s & (1 << j): continue t = s ^ (1 << j) for k in (3 * i, 3 * i + 1, 3 * i + 2): for l in (3 * j, 3 * j + 1, 3 * j + 2): a1, b1, c1 = pattern[k] a2, b2, c2 = pattern[l] if a1 > a2: continue if b1 > b2: continue x = dp[s][k] + c2 if dp[t][k] < x: dp[t][k] = x answer = max(itertools.chain(*dp)) print(answer)