N,K=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)

S=Hash.new{|h,k|h[k]=[]}
A.each.with_index.inject(0) do |s,(a,i)|
  s=(s+a-1)%K
  S[s]<<i
  s
end

ans = 0
A.each.with_index.inject(0) do |s,(a,i)|
  s+=a
  ans+=1 if s%K==i+1
  s
end
S.each do |k,v|
  r=0
  v.size.times do |l|
    r+=1 while r<v.size && v[r]-v[l]+1<K
    ans += r-l-1
  end
end
p ans
