def min(a,b); a < b ? a : b; end
  
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
dp = Hash.new {|h,k| h[k] = [] }
dp[0] << 0

A.each.with_index(1).inject(0) do |sum, (a, i)|
  dp[(sum + a - i) % K] << i
  sum + a
end

ans = dp.inject(0) do |sum, (mod, 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