We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import itertools
n = input()
n = n.split(" ")
n = list(map(int, n))
k = n[0]
m = n[1]
s = 0
finallist = []
for i in range(0, k):
n = input()
n = n.split(" ")
n = list(map(int, n))
n = n[1:]
n = [i**2 for i in n]
finallist.append(n)
combinations = list(itertools.product(*finallist))
result = []
for i in combinations:
result.append(sum(i)%m)
print(max(result))
Cookie support is required to access HackerRank
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 →
import itertools n = input() n = n.split(" ") n = list(map(int, n)) k = n[0] m = n[1] s = 0 finallist = [] for i in range(0, k): n = input() n = n.split(" ") n = list(map(int, n)) n = n[1:] n = [i**2 for i in n] finallist.append(n) combinations = list(itertools.product(*finallist)) result = [] for i in combinations: result.append(sum(i)%m) print(max(result))