N,K,*A = `dd`.split.map &:to_i
A.map!{ |a| (a - 1) % K }
ring = [0]
ch = { 0 => 1 }
s = 0
n = 0
A.each_with_index{ |a,i|
  s = (s + a) % K
  n += (ch[s] || 0)
  ch[s] = (ch[s] || 0) + 1
  ring << s
  if ring.size >= K
    t = ring[-K]
    if t && ch[t]
      ch[t] = ch[t] - 1
    end
  end
}
p n