n,k=gets.split.map &:to_i
a=gets.split.map &:to_i
b=a.map {|x|(x+k-1)%k}
s=0
m={0=>[-1]}
ans=0
b.each_with_index {|x,i|
  s=(s+x)%k
  if m.key?(s) then
    ans += m[s].bsearch {|j| i-j<k}
    m[s] << i
  else
    m[s] = [i]
  end
}
puts ans
