Maximize It!

  • + 1 comment

    unable to pass 4 test cases any help in logic would be appriciated

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import itertools
    k_n_list=input().split()  #take K,M as input
    number=int(k_n_list[0])   # getting number of K
    new_list=[]               # empty list 
    find_element=[]           # empty list to store all possible squared modulo operated value
    for i in range(0,number):   # for loop for appending the number of inputed list
        new_list.append(input().split())  # nested list of lists
    combinations = list(itertools.product(*new_list))  # all possible values of the nested list
    # it dose not conatain the same element from the list 
    for comb in combinations: # square and modulo operation in this loop
        b =list((map(int, comb)))
        out=sum(map(lambda i: i*i , b))% int(k_n_list[1])
        find_element.append(out)
    print(max(find_element))