Skip to content

Instantly share code, notes, and snippets.

@rjshekar90
Created March 7, 2017 23:42
Show Gist options
  • Save rjshekar90/be9926c529adf16507aad0c2940d9dd4 to your computer and use it in GitHub Desktop.
Save rjshekar90/be9926c529adf16507aad0c2940d9dd4 to your computer and use it in GitHub Desktop.
from itertools import product
k, m = map(int, input().split())
arrays = [list(map(int, input().split()[1:])) for _ in range(k)]
lst = []
for a in list(product(*arrays)):
lst.append(sum([b ** 2 for b in a]) % m)
print(max(lst))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment