N, K = list(map(int,input().split()))

A = list(map(int, input().split()))

S = [0]*(N+1)

S2 = [0]*(N+1)

dict = {}#最新K件の度数分布の管理



for i in range(N):

    S[i+1]=S[i]+A[i]

    S2[i+1] =(S[i+1]-i-1)%K



ans =0

for i in range(N+1):

    if dict.get(S2[i],0):

        ans += dict[S2[i]]

    dict[S2[i]]=dict.get(S2[i],0)+1

    if i >=K-1:

        dict[S2[i-(K-1)]]-=1



print(ans)
import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))





"""

N^2なので素直に計算は無理，部分和を使いたいのでとりあえず累積和

[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同．

移行して，S[j]-jとS[i]-iが合同

基本は個数だけ見れば良い



これだけだと，個数がKより大きい時にダメ

直近Kこの情報だけ持つ，今見てる数字が直近K個のものと何個組にできるか

"""

def main():



    mod=10**9+7

    N,K=MI()

    A=LI()

    from collections import defaultdict

    dd = defaultdict(int)

    

    S=[0]*(N+1)

    for i in range(N):

        S[i+1]=(S[i]+A[i])%K

        

    ans=0

    for i in range(min(K,N+1)):

        temp=(S[i]-i)%K

        ans+=dd[temp]

        dd[temp]+=1

        

    for i in range(K,N+1):

        temp=(S[i]-i)%K

        temp_m=(S[(i-K)]-(i-K))%K

        dd[temp_m]-=1

        ans+=dd[temp]

        dd[temp]+=1

        

    print(ans)

        

        

    



        



main()

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1)
S2 = [0] * (N + 1)
dict = {}  # 最新K件の度数分布の管理
for i in range(N):
    S[i + 1] = S[i] + A[i]
    S2[i + 1] = (S[i + 1] - i - 1) % K
ans = 0
for i in range(N + 1):
    if dict.get(S2[i], 0):
        ans += dict[S2[i]]
    dict[S2[i]] = dict.get(S2[i], 0) + 1
    if i >= K - 1:
        dict[S2[i - (K - 1)]] -= 1
print(ans)

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


"""
N^2なので素直に計算は無理，部分和を使いたいのでとりあえず累積和
[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同．
移行して，S[j]-jとS[i]-iが合同
基本は個数だけ見れば良い
これだけだと，個数がKより大きい時にダメ
直近Kこの情報だけ持つ，今見てる数字が直近K個のものと何個組にできるか
"""


def main():
    mod = 10**9 + 7
    N, K = MI()
    A = LI()
    from collections import defaultdict

    dd = defaultdict(int)
    S = [0] * (N + 1)
    for i in range(N):
        S[i + 1] = (S[i] + A[i]) % K
    ans = 0
    for i in range(min(K, N + 1)):
        temp = (S[i] - i) % K
        ans += dd[temp]
        dd[temp] += 1
    for i in range(K, N + 1):
        temp = (S[i] - i) % K
        temp_m = (S[(i - K)] - (i - K)) % K
        dd[temp_m] -= 1
        ans += dd[temp]
        dd[temp] += 1
    print(ans)


main()

-N, K = list(map(int, input().split())) -A = list(map(int, input().split())) -S = [0] * (N + 1) -S2 = [0] * (N + 1) -dict = {}  # 最新K件の度数分布の管理 -for i in range(N): -    S[i + 1] = S[i] + A[i] -    S2[i + 1] = (S[i + 1] - i - 1) % K -ans = 0 -for i in range(N + 1): -    if dict.get(S2[i], 0): -        ans += dict[S2[i]] -    dict[S2[i]] = dict.get(S2[i], 0) + 1 -    if i >= K - 1: -        dict[S2[i - (K - 1)]] -= 1 -print(ans) +import sys + +input = sys.stdin.readline + + +def I(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +""" +N^2なので素直に計算は無理，部分和を使いたいのでとりあえず累積和 +[i+1:j]が条件を満たすとはS[j]-S[i]とj-iが合同． +移行して，S[j]-jとS[i]-iが合同 +基本は個数だけ見れば良い +これだけだと，個数がKより大きい時にダメ +直近Kこの情報だけ持つ，今見てる数字が直近K個のものと何個組にできるか +""" + + +def main(): +    mod = 10**9 + 7 +    N, K = MI() +    A = LI() +    from collections import defaultdict + +    dd = defaultdict(int) +    S = [0] * (N + 1) +    for i in range(N): +        S[i + 1] = (S[i] + A[i]) % K +    ans = 0 +    for i in range(min(K, N + 1)): +        temp = (S[i] - i) % K +        ans += dd[temp] +        dd[temp] += 1 +    for i in range(K, N + 1): +        temp = (S[i] - i) % K +        temp_m = (S[(i - K)] - (i - K)) % K +        dd[temp_m] -= 1 +        ans += dd[temp] +        dd[temp] += 1 +    print(ans) + + +main()