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.
fromitertoolsimportproductk,m=list(map(int,input().split()))# f(X) functiondeff(x):returnx**2lst=[]for_inrange(k):local_input=list(map(int,input().split()))lst.append(local_input[1:])# Apply f(X) functionsqared_list=[[f(x)forxinl]forlinlst]# Generate cartesian product to obtain all possible combinationscombined=product(*sqared_list)max_s=0forcincombined:# Get local sumlocal_sum=sum(c)# Get local mod of mlocal_mod=local_sum%m# Get the maximized valuemax_s=max(max_s,local_mod)print(max_s)
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 →
More clear solution