N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

from itertools import accumulate

tmp = list(accumulate(A))
mod = [a%M for a in tmp]
print(mod)

mod_dict={}
mod_dict[0]=1

for m in mod:
  mod_dict[m]=mod_dict.get(m,0)+1
  
print(mod_dict)

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

answer=0

for x in mod_dict.values():
  if x>=2:
    print(x, combinations_count(x, 2))
    answer+=combinations_count(x, 2)
    
print(int(answer))
