N, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

C = Hash.new
C[0] = [0]
s, ans = [0, 0]
A.map.with_index(1){|a, idx|
  s += a
  tmp = (s - idx) % K
  if C.key?(tmp) then
    i = C[tmp].bsearch_index{|c| idx - c < K}
    ans += (C[tmp].size - i) if !i.nil?
    C[tmp] << idx
  else
    C[tmp] = [idx]
  end
}

puts ans
