import itertools # Read input n = int(input()) students = [] for idx in range(n): M, I, P, C, B, E = map(int, input().split()) students.append((M, I, P, C, B, E, idx)) # Collect the top 5 students for each subject candidate_set = set() for subject in range(6): # Sort students by the current subject in descending order sorted_students = sorted(students, key=lambda x: -x[subject]) # Take top 5 top5 = sorted_students[:5] for student in top5: candidate_set.add(student) # Convert the set to a list candidates = list(candidate_set) # If there are less than 4 candidates, which shouldn't happen as per constraints if len(candidates) < 4: print(0) exit() max_product = 0 # Iterate through all combinations of 4 candidates for combo in itertools.combinations(candidates, 4): # Extract the subject values for each student in the combo m = max(s[0] for s in combo) i = max(s[1] for s in combo) p = max(s[2] for s in combo) c = max(s[3] for s in combo) b = max(s[4] for s in combo) e = max(s[5] for s in combo) product = m * i * p * c * b * e if product > max_product: max_product = product print(max_product)