(N, K), As = readlines.map{|l| l.split.map(&:to_i)}

h = {}; h[0] = [0]
s, ans = 0, 0
As.each.with_index(1) do |a, i|
  s += a
  t = (s - i) % K
  if h.key?(t)
    j = h[t].bsearch_index{|j| i - j < K}
    ans += h[t].size - j unless j.nil?
    h[t] << i
  else
    h[t] = [i]
  end
end
puts ans