In this HackerRank Maximize It! problem solution You are given a function f(X) = X*X. You are also given K lists. The ith list consists of Ni elements. You have to pick one element from each list so that the value from the equation below is maximized: S = (f(X1) + f(X2) + ... + f(Xk)) % M. Xi denotes the element picked from the ith list. Find the maximized value Smax obtained. % denotes the modulo operator. Note that you need to take exactly one element from each list, not necessarily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem.

HackerRank Maximize It! in python problem solution

HackerRank Maximize It! in python problem solution

import itertools

tests,mod = map(int, input().split())
maximum = 0
allLists = []

for t in range(tests):
  data = list(map(int, input().split()))
  data = list(map(lambda x: x*x, data))

for each in itertools.product(*allLists):
  num = sum(each) % mod
  if num > maximum:
    maximum = num