Maximize It!

  • + 0 comments

    Solution

    from itertools import product
    
    k,m = map(int, input().split())
    listy = []
    
    for _ in range(k):
        listy.append(list(map(int, input().split()))[1:])
    
    najw = 0
    for i in product(*listy):
        wartosc = sum(x**2 for x in i)%m
        najw = max(najw, wartosc)
    
    print(najw)