Maximize It!

  • + 0 comments
    from itertools import product
    n, k = list(map(int, list(input().split())))
    m = []
    #n = int(input())
    for i in range(n):
        m.append(list(map(int, (input().split()[1:]))))
    
    combinations = list(product(*m))
    
    squared_m = []
    semifinal_list = []
    
    for combination in combinations:
        tuples = ()
        for i in combination:
            tuples += (i**2),
        squared_m.append(tuples)
    for i in squared_m:
        semifinal_list.append(sum(i)%k)
    
    print(max(semifinal_list))