Maximize It!

  • + 0 comments

    import itertools

    # Read input K, M = map(int, input().split()) lists = []

    # Reading each list for _ in range(K): data = list(map(int, input().split())) lists.append(data[1:]) # Skip the first element as it's the size N

    # Generate all possible combinations (one element from each list) max_s = 0 # To track the maximum S

    # Iterate through all combinations for combo in itertools.product(lists): # Calculate S for the current combination s = sum(x * 2 for x in combo) % M # Update the maximum S if needed max_s = max(max_s, s)

    Output the result

    print(max_s)