import itertools n = int(input()) students = [] for _ in range(n): m, i, p, c, b, e = map(int, input().split()) students.append((m, i, p, c, b, e)) # Collect top 5 indices for each subject subjects = [0, 1, 2, 3, 4, 5] # M, I, P, C, B, E candidate_indices = set() for subj in subjects: # Sort students by the subject's score in descending order, then by index ascending sorted_students = sorted( [(i, students[i][subj]) for i in range(n)], key=lambda x: (-x[1], x[0]) ) # Take top 5 indices top_indices = [i for i, val in sorted_students[:5]] candidate_indices.update(top_indices) candidates = list(candidate_indices) max_score = 0 # Generate all combinations of 4 students from candidates for combo in itertools.combinations(candidates, 4): m_max = max(students[i][0] for i in combo) i_max = max(students[i][1] for i in combo) p_max = max(students[i][2] for i in combo) c_max = max(students[i][3] for i in combo) b_max = max(students[i][4] for i in combo) e_max = max(students[i][5] for i in combo) product = m_max * i_max * p_max * c_max * b_max * e_max if product > max_score: max_score = product print(max_score)