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)) k = 5 # Number of top students to consider per subject candidates = set() for subject in range(6): sorted_students = sorted([(idx, s[subject]) for idx, s in enumerate(students)], key=lambda x: (-x[1], x[0])) for i in range(min(k, len(sorted_students))): candidates.add(sorted_students[i][0]) candidate_list = list(candidates) max_score = 0 for group in itertools.combinations(candidate_list, 4): m_max = max(students[i][0] for i in group) i_max = max(students[i][1] for i in group) p_max = max(students[i][2] for i in group) c_max = max(students[i][3] for i in group) b_max = max(students[i][4] for i in group) e_max = max(students[i][5] for i in group) product = m_max * i_max * p_max * c_max * b_max * e_max if product > max_score: max_score = product print(max_score)