Problem p02851 (python)

Fixed submission:
import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([1] + lr())
A = (A-1) % K
N += 1
Acum = (A.cumsum() % K).tolist()
d = defaultdict(int)
answer = 0
for i, x in enumerate(Acum):
    answer += d[x]
    d[x] += 1
    if i >= K-1:
        d[Acum[i-(K-1)]] -= 1

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A = (A-1) % K
Acum = A.cumsum()
counter = defaultdict(int)
answer = 0
for i, x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-(K-1)]] -= 1

print(answer)



for i in range(len(Acum)):
    x = Acum(i)
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-(K-1)]] -= 1

print(answer)
# 27

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A = (A-1) % K
Acum = A.cumsum()
counter = defaultdict()
answer = 0
for i, x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-(K-1)]] -= 1

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
A = np.array([0] + rl())
A_cum = A.cumsum()
A_cum2 = A_cum - np.arange(N+1)
A_cum2 = A_cum2 % K
answer = 0
remain = [0] * (K)
cnt = 0
for i in range(N+1):
    x = A_cum2[i] % K    
    if i - K >= 0:
        y = A_cum2[i-K] % K
        remain[y] -= 1
    answer += remain[x]
    remain[x] += 1
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
A = np.array([0] + rl())
A_cum = A.cumsum()
A_cum2 = A_cum - np.arange(N+1)
A_cum2 = A_cum2 % K
answer = 0
remain = [0] * (K)
cnt = 0
for i in range(N+1):
    x = A_cum2[i] % K    
    if i - K >= 0:
        y = A_cum2[i-K] % K
        remain[y] -= 1
    answer += remain[x]
    remain[x] += 1
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
A = np.array([0] + rl())
A_cum = A.cumsum()
A_cum2 = A_cum - np.arange(N+1)
A_cum2 = A_cum2 % K
answer = 0
remain = [0] * (K)
cnt = 0
for i in range(N+1):
    x = A_cum2[i] % K    
    if i - K >= 0:
        y = A_cum2[i-K] % K
        remain[y] -= 1
    answer += remain[x]
    remain[x] += 1
print(answer)