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 candidates for each subject subjects = [0, 1, 2, 3, 4, 5] # Indices for M, I, P, C, B, E candidate_indices = set() for subj in subjects: # Sort students by the current subject in descending order and take top 5 sorted_indices = sorted(range(n), key=lambda x: students[x][subj], reverse=True) top_indices = sorted_indices[:5] candidate_indices.update(top_indices) # Convert indices to actual student data candidates = [students[i] for i in candidate_indices] max_score = 0 # Generate all combinations of 4 students from candidates for group in itertools.combinations(candidates, 4): m_max = max(s[0] for s in group) i_max = max(s[1] for s in group) p_max = max(s[2] for s in group) c_max = max(s[3] for s in group) b_max = max(s[4] for s in group) e_max = max(s[5] for s 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)