Maximize It!

  • + 0 comments
    from itertools import product
    
    K, M = map(int, input().split())
    lists = []
    
    for i in range(K):
        lists.append([int(x)**2 for x in input().split()[1:]])
        
    per = list(product(*lists))
    
    ans = list(map(lambda x: sum(x) % M, per))
    
    print(max(ans))