Maximize It!

  • + 0 comments

    import itertools

    user_input = input().split()

    k = int(user_input[0]) m = int(user_input[1])

    lists = []

    for _ in range(k): lists.append([int(x) for x in input().split()][1:])

    combinations = list(itertools.product(*lists))

    squared_combinations = [[x**2 for x in combination] for combination in combinations]

    s_max = []

    for squared_combination in squared_combinations: if (sum(squared_combination) % m > sum(s_max) % m): s_max = squared_combination

    print(sum(s_max) % m)