Buggy python submission (verdict: Time Limit Exceeded):
#尺取り法と累積和
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
for i in range(k):
    count[i] = 0
q = deque()
for i in acc_a:
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)

Fixed submission:
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
q = deque()
for i in acc_a:
    if i not in count:
        count[i] = 0
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#尺取り法と累積和
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [i % k for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0]
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
#print(acc_a)
ans = 0
for i in range(len(acc_a)):
    for j in range(max(0, i - k), i):
        #print("i {}  j {}".format(i,j))
        list_sum = acc_a[i] - acc_a[j]
        if list_sum < 0:
            list_sum += k
        if i - j == list_sum:
            #print("i {}  j {}".format(i,j))
            ans += 1
print(ans)

Fixed submission:
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
q = deque()
for i in acc_a:
    if i not in count:
        count[i] = 0
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#尺取り法と累積和
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [i % k for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0]
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k

"""
#尺取り法、
right = 1
left = 0
ans = 0
while right != len(acc_a) or right != left:
    print("l{}  r{}".format(left, right))
    #選んだ配列の個数
    list_num = 1 + right - left
    #選ぶ配列長さがkより大きいことはない
    if list_num >= k:
        left += 1
    #左が追い付いたら右を増やす
    if right == left:
        right += 1
    sum_list = acc_a[right] - acc_a[left]
    if sum_list < 0:
        sum_list += k
    
    if sum_list == list_num:
        ans += 1
        right += 1
    else:
        left += 1
"""
#print(acc_a)
ans = 0
for i in range(len(acc_a)):
    for j in range(max(0, i - k), i):
        #print("i {}  j {}".format(i,j))
        if i - j > k:
            break
        list_sum = acc_a[i] - acc_a[j]
        if list_sum < 0:
            list_sum += k
        if i - j == list_sum:
            #print("i {}  j {}".format(i,j))
            ans += 1


print(ans)
    


Fixed submission:
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
q = deque()
for i in acc_a:
    if i not in count:
        count[i] = 0
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)