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)) pool = set() # For each subject, add top 4 students' indices to pool for s in range(6): subj_list = [(students[i][s], i) for i in range(n)] subj_list.sort(key=lambda x: (-x[0], x[1])) for i in range(4): if i >= len(subj_list): break pool.add(subj_list[i][1]) pool = list(pool) max_product = 0 # Iterate all possible combinations of 4 indices from the pool for quad_indices in itertools.combinations(pool, 4): quad_students = [students[idx] for idx in quad_indices] max_values = [] for s in range(6): current_max = max(st[s] for st in quad_students) max_values.append(current_max) product = 1 for mv in max_values: product *= mv if product > max_product: max_product = product print(max_product)