n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

csum = Array.new(n+1, 0)

n.times do |i|
    csum[i+1] = csum[i] + as[i]
end
n.times do |i|
    csum[i+1] = (csum[i+1] - (i+1))%k
end

ans = 0
hh = {}
for i in 0..n
    ci = csum[i]
    hh[ci] = 0 if hh[ci] == nil
    ans += hh[ci]
    hh[ci] += 1
    if i >= k-1
        cj = csum[i-k+1]
        hh[cj] -= 1
    end
end

#p csum
puts ans
