Maximize It!

  • + 0 comments

    k, m = map(int, input().split()) matrix = [] count = 0 def map_square(x): x = i for i in range(k): x= [*map(lambda x: (int(x)**2)%m, input().split())] x.sort() matrix.append(x) matrix.sort(key=lambda x: max(x) )

    def calculate_sum_all_elements(matrix:list): if len(matrix) == 1: return max(matrix) else: lst1 = matrix.pop(0) lst2 = matrix.pop(0) lst = [(x+y)%m for x in lst1 for y in lst2] matrix.insert(0, lst) return calculate_sum_all_elements(matrix)

    print(max(calculate_sum_all_elements(matrix)))