def comb2(n)
  if n < 2
    return 0
  else
    n * (n - 1) / 2
  end
end

N, M = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
sum_modM_idx = Array.new(M) {0}

sum_modM = 0
A.each do |a|
  sum_modM += a
  sum_modM %= M
  sum_modM_idx[sum_modM] += 1
end

ans = sum_modM_idx[0]
sum_modM_idx.each do |n|
  ans += comb2(n)
end
puts ans