local n, k = io.read("*n", "*n")
local function modsub(a, b)
  if a < b then return a + k - b
  else return a - b
  end
end

local a = {}
for i = 1, n do
  a[i] = io.read("*n") % k
end
local sum = {a[1]}
for i = 2, n do
  sum[i] = (sum[i - 1] + a[i]) % k
end
for i = 1, n do
  sum[i] = modsub(sum[i], i)
end
local remlist, remlist_uniq = {0}, {}
remlist_uniq[0] = true
for i = 1, n do
  if not remlist_uniq[sum[i]] then
    remlist_uniq[sum[i]] = true
    table.insert(remlist, sum[i])
  end
end
local remlist_inv = {}
local remcnt = {}
for i = 1, #remlist do
  remlist_inv[remlist[i]] = i
  remcnt[i] = 0
end
remcnt[remlist_inv[0]] = 1
local ret = 0
for i = 1, n do
  local reminv = remlist_inv[sum[i]]
  ret = ret + remcnt[reminv]
  remcnt[reminv] = remcnt[reminv] + 1
  if i == k then
    remcnt[remlist_inv[0]] = remcnt[remlist_inv[0]] - 1
  elseif k < i then
     remcnt[remlist_inv[sum[i - k]]] = remcnt[remlist_inv[sum[i - k]]] - 1
  end
end
print(ret)
