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.
# Enter your code here. Read input from STDIN. Print output to STDOUTfromitertoolsimportproduct# Input readingk,m=map(int,input().split())#k=numberoflists,m=modulovalue# Read all listslists=[]for_inrange(k):data=list(map(int,input().split()))[1:]#Skipthefirstnumber(sizeoflist)lists.append(data)# Calculate the maximum value of the function using itertools.productmax_value=0forcombinationinproduct(*lists):# Calculate the value for the current combinationcurrent_value=sum(x**2forxincombination)%m# Update the maximum valuemax_value=max(max_value,current_value)# Output the resultprint(max_value)
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 →