Maximize It!

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