n, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

bs = [0]

b = 0
n.times do |i|
  b += as[i]
  bs << b % m
end

ht = {}

bs.each do |b|
  ht[b] ||= 0
  ht[b] += 1
end

p ht.values.map { |v| v * (v - 1) / 2 }.sum
