Maximize It!

  • + 0 comments

    import itertools

    k,m=map(int,input().split())

    el_list=[]

    for i in range(k):

    el_list.append(list(map(int,input().split()))[1:])
    

    all_possibility = list(itertools.product(*el_list))

    print(max([sum([j**2 for j in i])%m for i in all_possibility]))