mod = 1000000007 eps = 10**-9 inf = 10**9 def main(): import sys input = sys.stdin.readline N = int(input()) xyz = [] val = set() for i in range(N): a, b, c = map(int, input().split()) x, y, z = sorted([a, b, c]) xyz.append((x, y, z, i)) xyz.append((x, z, y, i)) xyz.append((y, z, x, i)) val.add(x) val.add(y) val.add(z) val.add(0) val = sorted(list(val)) val2idx = {v: i for i, v in enumerate(val)} xyz.sort(key=lambda p: p[1]) dp = [[-inf] * (N*3+1) for _ in range(2**N)] dp[0][0] = 0 for i in range(N*3): x, y, z, ii = xyz[i] j = val2idx[x] for state in range(2**N): if state >> ii & 1: continue for last in range(j+1): dp[state | (1 << ii)][j] = max(dp[state | (1 << ii)][j], dp[state][last] + z) ans = 0 for state in range(2**N): for last in range(N*3+1): ans = max(ans, dp[state][last]) print(ans) if __name__ == '__main__': main()