Maximize It!

  • + 0 comments

    The most common error is that each line starts with the number of subsequent elements on the line (this is quite uncommon to have it on the same line in HR challenges)!

    The shortest code I found in Python (not the fastest, it is faster to check the max each time in the loop):

    from itertools import product
    
    K, M = (int(x) for x in input().split())
    print(max(sum(t)%M for t in product(*[[int(x)**2 for x in input().split()][1:] for _ in range(K)])))