HackerRank Python - Maximize It


You have to pick one element from each list so that the value from the equation below is maximized:

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from itertools import product
  3. k, m = map(int, input().split())
  4. array = []
  5. for _ in range(k):
  6. array.append(list(map(int, input().split()))[1:])
  7. result = 0
  8. for combination in product(*array):
  9. result = max(sum([x * x for x in combination]) % m, result)
  10. print(result)

download android app