Buggy python submission (verdict: Runtime Error):
from collections import deque


def p_e():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    s = [0] * (n + 1)
    for i in range(n):
        s[i + 1] = (s[i] + a[i] - 1) % k
    mp = [0] * k
    q = deque()
    ans = 0
    for i in range(n + 1):
        ans += mp[s[i]]
        mp[s[i]] += 1
        q.append(s[i])
        if len(q) == k:
            mp[q.popleft()] -= 1
    print(ans)
    
p_e()

Fixed submission:

from collections import deque
from collections import defaultdict


def p_e():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    for i in range(n):
        a[i + 1] = (a[i + 1] + a[i] - 1) % k
    d = defaultdict(int)
    d[0] = 1
    q = deque()
    ans = 0
    for i in range(1, n + 1):
        if i - k >= 0:
            d[a[i - k]] -= 1
        ans += d[a[i]]
        d[a[i]] += 1
    print(ans)
    
p_e()

Buggy python submission (verdict: Runtime Error):
from collections import deque


def p_e():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    s = [0] * (n + 1)
    for i in range(n):
        s[i + 1] = (s[i] + a[i] - 1) % k
    mp = [0] * k
    q = deque()
    ans = 0
    for i in range(n + 1):
        ans += mp[s[i]]
        mp[s[i]] += 1
        q.append(s[i])
        if len(q) == k:
            mp[q.popleft()] -= 1
    print(ans)
    
p_e()

Fixed submission:

from collections import deque
from collections import defaultdict


def p_e():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    for i in range(n):
        a[i + 1] = (a[i + 1] + a[i] - 1) % k
    d = defaultdict(int)
    d[0] = 1
    q = deque()
    ans = 0
    for i in range(1, n + 1):
        if i - k >= 0:
            d[a[i - k]] -= 1
        ans += d[a[i]]
        d[a[i]] += 1
    print(ans)
    
p_e()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import deque


def p_e():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    dp = np.array([0] * n)
    q = deque([-1] * n)
    ans = 0
    for i in range(n):
        q.appendleft(i + 1)
        q.pop()
        c = a[i] % k
        dp[:i + 1] += c
        dp[:i + 1] %= k
        ans += (dp == q).sum()
    print(ans)
    
p_e()

Fixed submission:

from collections import deque
from collections import defaultdict


def p_e():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    for i in range(n):
        a[i + 1] = (a[i + 1] + a[i] - 1) % k
    d = defaultdict(int)
    d[0] = 1
    q = deque()
    ans = 0
    for i in range(1, n + 1):
        if i - k >= 0:
            d[a[i - k]] -= 1
        ans += d[a[i]]
        d[a[i]] += 1
    print(ans)
    
p_e()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import deque


def p_e():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    dp = np.array([0] * n)
    q = deque()
    ans = 0
    for i in range(n):
        q.appendleft(i + 1)
        c = a[i] % k
        now_dp = dp[:i + 1]
        now_dp += c
        now_dp %= k
        ans += np.sum(now_dp == q)
    print(ans)

p_e()

Fixed submission:

from collections import deque
from collections import defaultdict


def p_e():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    for i in range(n):
        a[i + 1] = (a[i + 1] + a[i] - 1) % k
    d = defaultdict(int)
    d[0] = 1
    q = deque()
    ans = 0
    for i in range(1, n + 1):
        if i - k >= 0:
            d[a[i - k]] -= 1
        ans += d[a[i]]
        d[a[i]] += 1
    print(ans)
    
p_e()