class Array
  def upper_bound(x)
    bsearch_index { |v| v > x }
  end

  def lower_bound(x)
    bsearch_index { |v| v >= x }
  end
end

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

mod_list = []
sum = 0
ans = 0

A.each_with_index do |a, index|
  sum += a
  sum %= M
  inv = (M - sum) % M

  if sum == 0
    ans += 1
  end

  s = mod_list.lower_bound(inv)
  t = mod_list.upper_bound(inv) || index

  if s
    ans += t - s
  end

  i = mod_list.upper_bound(sum) || index
  mod_list.insert(i, sum)
end

puts ans
