class Array
  def cumsum; s = 0; map{|k| s += k } end
  def mod(m); map{|k|k%m} end
end

n,k = gets.split.map(&:to_i)
a   = [0] + gets.split.map{ |k| k.to_i - 1 }

c = a.cumsum.mod(k)

ans = 0
h = Hash.new(0)

(n+1).times do |i|
  h[c[i-k]] -= 1 if i >= k
  ans += h[c[i]]
  h[c[i]] += 1
end

puts ans