Maximize It!

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