Maximize It!

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