def min(a,b); a < b ? a : b; end
  
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
S = Array.new(N + 1, 0)
dp = Array.new(min(N,K)){ [] }
A.each_with_index do |a,i|
  S[i + 1] = S[i] + a
end

(0 .. N).each do |i|
  dp[(S[i] - i) % K] << i
end

ans = dp.inject(0) do |sum, mods|
  count = 0
  mods.each_index.inject(0) do |l, r|
    (l .. r).find{|l_| mods[r] - mods[l_] < K }.tap{|l_| count += (r - l_) }
  end
  sum + count
end
puts ans