Maximize It!

  • + 0 comments

    k, l = list(map(int,input().split()))

    z=[]

    for i in range(k): z.append(list(map(int,input().split()))[1:])

    import itertools product_result = list(itertools.product(*z))

    final_list=[]

    def square(x): return (x**2)

    for i in product_result: s=(sum(list(map(square,i)))) % l final_list.append(s)

    print(max(final_list))