(N, M) = map(int, input().split())
box = [int(x) for x in input().split()]

def sum_list(n, m, li):
  sum = 0
  for i in range(n, m+1):
    sum += li[i]
  return sum

count = 0

for l in range(N):
  for r in range(l, N):
    if sum_list(l, r, box) % M == 0:
      count += 1
      print (str(box[l]) + " " + str(box[r]))
  
  

print (box)
print (count)