Maximize It!

  • + 0 comments
    from functools import reduce
    def evaluate(arr):
        sq = list(map(lambda x : x**2, arr))
        sum_1 = reduce(lambda x, y :x+y, sq )
        return sum_1
    
    s = list(map(int, input().split()))
    count_arr = s[0]
    M = s[1]
    Sum = 0
    all_arr = []
    for _ in range(count_arr):
        arr = list(map(int, input().split()))
        all_arr.append(arr[1:])
    combinations = list(product(*all_arr)) 
    result = []
    for comb in combinations:
        result.append(evaluate(list(comb))%M)
    
    print(max(result))