You are viewing a single comment's thread. Return to all comments →
I couldn't find a single easy to understand way, So here is mine with extra comments to make it easier
K, M = map(int, input().split()) POSSIBLE = {0} for i in range(K): count, *num = list(map(int, input().split())) #1st number in count, and rest in num denoted by * vals = {pow(x, 2, M) for x in num} #num will be squared and its MOD M result will be stored in vals POSSIBLE = {(a+v)%M for a in POSSIBLE for v in vals} #Every value in vals is added with every value in POSSIBLE and then MOD M on each, finally stored in POSSIBLE print(max(POSSIBLE))
Seems like cookies are disabled on this browser, please enable them to open this website
Maximize It!
You are viewing a single comment's thread. Return to all comments →
I couldn't find a single easy to understand way, So here is mine with extra comments to make it easier