Maximize It!

  • + 0 comments
    from itertools import product
    def f(x):
        return int(x)**2
    a, b = tuple(list(map(int, input().split())))
    pro = []
    for i in list(product(*[list(map(f, input()[1:].split())) for _ in range(a)])):
        pro.append(sum(i) % b)
    print(max(pro))