import sys from collections import defaultdict def main(): n = int(sys.stdin.readline()) cuboids = [] for _ in range(n): a, b, c = map(int, sys.stdin.readline().split()) opts = [] opts.append((tuple(sorted([a, b])), c)) opts.append((tuple(sorted([a, c])), b)) opts.append((tuple(sorted([b, c])), a)) cuboids.append(opts) dp = defaultdict(dict) # Initialize with each cuboid's possible orientations for i in range(n): for (base, h) in cuboids[i]: a, b = base mask = 1 << i if (a, b) not in dp[mask] or h > dp[mask].get((a, b), 0): dp[mask][(a, b)] = h # Process all masks for mask in list(dp.keys()): current_entries = list(dp[mask].items()) for (a_prev, b_prev), current_h in current_entries: for i in range(n): if not (mask & (1 << i)): for (new_base, h_new) in cuboids[i]: a_new, b_new = new_base if a_new <= a_prev and b_new <= b_prev: new_mask = mask | (1 << i) total_h = current_h + h_new if (a_new, b_new) not in dp[new_mask] or dp[new_mask].get((a_new, b_new), 0) < total_h: dp[new_mask][(a_new, b_new)] = total_h max_height = 0 for mask in dp: for (a, b) in dp[mask]: if dp[mask][(a, b)] > max_height: max_height = dp[mask][(a, b)] print(max_height) if __name__ == "__main__": main()