(n,k),a = $<.map{|l|l.split.map(&:to_i)}

accum = a.inject([0]){|s,r|s+[s[-1]+r]}

modk = accum.map.with_index{|ac,i|(ac-i)%k}+[k]*k

valmap = [0]*(k+1)
l = 0
r = k+l-1

(l+1..r).each{|i|
  valmap[modk[i]] += 1
}
cnt = 0
n.times{
  cnt += valmap[modk[l]]
  l += 1
  r += 1
  valmap[modk[l]] -= 1
  valmap[modk[r]] += 1
}
p cnt