Maximize It!

  • + 0 comments

    was a bit tough and fun

    from itertools import product
    
    k, m = map(int, input().split())
    L, max_value = [], 0
    for i in range(0, k):
        L.append(list(map(lambda x: int(x) ** 2, input().split()[1:])))
    
    for i in product(*L):
        if max_value < (sum(i) % m):
            max_value = sum(i) % m
    print(max_value)