from collections import defaultdict, deque



n, k = list(map(int, input().split()))

a = tuple(map(int, input().split()))

acc = [0]

t = 0

for a_ in a:

    t = (t + a_ - 1) % k

    acc.append(t)



d = defaultdict(int)



ret = 0

count = 0

dq = deque()



for acc_ in acc:

    ret += d[acc_]

    d[acc_] += 1

    dq.append(acc_)

    if len(dq) >= k:

        v = dq.popleft()

        d[v] -= 1

print(ret)

def main():

    from collections import defaultdict, deque



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

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



    def accumulate(a, mod):

        s = 0

        yield s

        for x in a:

            s = (s + x - 1) % mod

            yield s



    *acc, = accumulate(a, mod=K)



    d = defaultdict(int)

    dq = deque()

    ans = 0

    for x in acc:

        ans += d[x]

        d[x] += 1

        dq.append(x)

        if len(dq) >= K:

            r = dq.popleft()

            d[r] -= 1

    print(ans)





if __name__ == '__main__':

    main()



# import sys

#

# sys.setrecursionlimit(10 ** 7)

#

# input = sys.stdin.readline

# rstrip()

# int(input())

# map(int, input().split())

from collections import defaultdict, deque

n, k = list(map(int, input().split()))
a = tuple(map(int, input().split()))
acc = [0]
t = 0
for a_ in a:
    t = (t + a_ - 1) % k
    acc.append(t)
d = defaultdict(int)
ret = 0
count = 0
dq = deque()
for acc_ in acc:
    ret += d[acc_]
    d[acc_] += 1
    dq.append(acc_)
    if len(dq) >= k:
        v = dq.popleft()
        d[v] -= 1
print(ret)

def main():
    from collections import defaultdict, deque

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

    def accumulate(a, mod):
        s = 0
        yield s
        for x in a:
            s = (s + x - 1) % mod
            yield s

    (*acc,) = accumulate(a, mod=K)
    d = defaultdict(int)
    dq = deque()
    ans = 0
    for x in acc:
        ans += d[x]
        d[x] += 1
        dq.append(x)
        if len(dq) >= K:
            r = dq.popleft()
            d[r] -= 1
    print(ans)


if __name__ == "__main__":
    main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

-from collections import defaultdict, deque +def main(): +    from collections import defaultdict, deque -n, k = list(map(int, input().split())) -a = tuple(map(int, input().split())) -acc = [0] -t = 0 -for a_ in a: -    t = (t + a_ - 1) % k -    acc.append(t) -d = defaultdict(int) -ret = 0 -count = 0 -dq = deque() -for acc_ in acc: -    ret += d[acc_] -    d[acc_] += 1 -    dq.append(acc_) -    if len(dq) >= k: -        v = dq.popleft() -        d[v] -= 1 -print(ret) +    N, K = list(map(int, input().split())) +    a = list(map(int, input().split())) + +    def accumulate(a, mod): +        s = 0 +        yield s +        for x in a: +            s = (s + x - 1) % mod +            yield s + +    (*acc,) = accumulate(a, mod=K) +    d = defaultdict(int) +    dq = deque() +    ans = 0 +    for x in acc: +        ans += d[x] +        d[x] += 1 +        dq.append(x) +        if len(dq) >= K: +            r = dq.popleft() +            d[r] -= 1 +    print(ans) + + +if __name__ == "__main__": +    main() +# import sys +# +# sys.setrecursionlimit(10 ** 7) +# +# input = sys.stdin.readline +# rstrip() +# int(input()) +# map(int, input().split())