import itertools def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) students = [] index = 1 for _ in range(N): m = int(data[index]) i_val = int(data[index+1]) p = int(data[index+2]) c = int(data[index+3]) b = int(data[index+4]) e = int(data[index+5]) students.append((m, i_val, p, c, b, e)) index += 6 K = 20 subject_indices = [] for subj in range(6): temp = [] for idx in range(N): val = students[idx][subj] temp.append((val, idx)) temp.sort(reverse=True, key=lambda x: x[0]) top_indices = [idx for (val, idx) in temp[:K]] subject_indices.append(top_indices) candidates = set() for top in subject_indices: for idx in top: candidates.add(idx) candidates = list(candidates) if len(candidates) < 4: print(0) return max_score = 0 for combo in itertools.combinations(candidates, 4): max_m = max(students[i][0] for i in combo) max_i = max(students[i][1] for i in combo) max_p = max(students[i][2] for i in combo) max_c = max(students[i][3] for i in combo) max_b = max(students[i][4] for i in combo) max_e = max(students[i][5] for i in combo) product = max_m * max_i * max_p * max_c * max_b * max_e if product > max_score: max_score = product print(max_score) if __name__ == "__main__": main()