import itertools

def main():
    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 = 20
    candidates = set()
    
    # For each subject (0 to 5), collect top k students' indices
    for subject in range(6):
        # Create list of tuples (-score for descending order, index)
        subject_scores = [ (-students[i][subject], i) for i in range(n) ]
        # Sort by score ascending (which is descending when score is negated)
        subject_scores.sort()
        # Take top k entries
        for i in range(min(k, n)):
            idx = subject_scores[i][1]
            candidates.add(idx)
    
    candidates = list(candidates)
    if len(candidates) < 4:
        print(0)
        return
    
    max_product = 0
    # Iterate over all combinations of 4 students from candidates
    for group in itertools.combinations(candidates, 4):
        m = max(students[i][0] for i in group)
        info = max(students[i][1] for i in group)
        p = max(students[i][2] for i in group)
        c = max(students[i][3] for i in group)
        b = max(students[i][4] for i in group)
        e = max(students[i][5] for i in group)
        product = m * info * p * c * b * e
        if product > max_product:
            max_product = product
    
    print(max_product)

if __name__ == "__main__":
    main()