You are viewing a single comment's thread. Return to all comments →
from itertools import product
K, M = map(int,input().split())
N = (list(map(int, input().split()))[1:] for _ in range(K))
max_lst = [] for item in product(*N): S = 0 for val in item: S += val**2 S_max = S % M max_lst.append(S_max)
print(max(max_lst))
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 →
from itertools import product
K, M = map(int,input().split())
N = (list(map(int, input().split()))[1:] for _ in range(K))
max_lst = [] for item in product(*N): S = 0 for val in item: S += val**2 S_max = S % M max_lst.append(S_max)
print(max(max_lst))