n, m = gets.split.map(&:to_i)
candies = gets.split.map(&:to_i)
tmp = 0
cumulative_mods = []
hash = Hash.new{ |hash, key| hash[key] = [] }
candies.each_with_index do |c, i|
  mod = (tmp + c) % m
  cumulative_mods << mod
  hash[mod] << i
  tmp = mod
end
sum = 0
(0...n).each do |i|
  tmp_mod = cumulative_mods[i]
  deduction = i == 0 ? 0 : cumulative_mods[i - 1]
  tmp_mod -= deduction
  sum += 1 if tmp_mod == 0
  target = (m - deduction) % m
  target_array = hash[target]
  usable_index = target_array.bsearch_index { |e| e > i } || target_array.size
  usable = target_array.size - usable_index
  sum += usable
end
puts sum
