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

RUI = [0]

A.map { |a| a - 1 }.each do |a|
  RUI << (RUI.last + a) % K
end

counter = Hash.new(0)
counter[0] += 1

ans = 0

1.upto(N) do |i|
  ans += counter[RUI[i]]
  counter[RUI[i]] += 1

  j = i - K + 1
  counter[RUI[j]] -= 1 if j >= 0
end

puts ans
