ZhenlongDai/ACPR huggingface dataset:
Problem: p02652
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from itertools import accumulate

S = input()
N = len(S)

A = [0] + list(accumulate(1 if s == "1" else -1 for s in S))

ma = max(A)
cur = A[-1]
C = [ma - cur]
for a in reversed(A):
    cur = max(a, cur)
    C.append(ma - cur)

d, e = 0, 0
D, E = A[:], A[:]
for i, (s, c) in enumerate(zip(S, reversed(C)), 1):
    if s == '?' and c >= d + 2:
        d += 2
    if s == '?' and c >= e + 1:
        e += 2
    D[i] += d
    E[i] += e

print(min(max(D) - min(D), max(E) - min(E)))

Failing test case input:
1???111?10?1???1?1?11???1??01??0?0????0??0???@0/??

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from itertools import accumulate

S = input()
N = len(S)

A = [0] + list(accumulate(1 if s == "1" else -1 for s in S))

ma = max(A)
cur = A[-1]
C = [ma - cur]
for a in reversed(A):
    cur = max(a, cur)
    C.append(ma - cur)

d, e = 0, 0
D, E = A[:], A[:]
for i, (s, c) in enumerate(zip(S, reversed(C[:-1])), 1):
    if s == '?' and c >= d + 2:
        d += 2
    if s == '?' and c >= e + 1:
        e += 2
    D[i] += d
    E[i] += e

print(min(max(D) - min(D), max(E) - min(E)))

Problem: p02652
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
S = input()
N = len(S)

A = [0]*(N+1)
for i,s in enumerate(S,1):
    if s=="1":
        A[i] = A[i-1]+1
    else:
        A[i] = A[i-1]-1

m = max(A)
B = [A[-1]]*(N+1)
C = [m-A[-1]]*(N+1)
for i in range(N):
    i = N-i-1
    B[i] = max(A[i],B[i+1])
    C[i] = m-B[i]

d = 0
D = A[:]
for i,s in enumerate(S,1):
    if s=='?' and C[i] >= d+2:
        d += 2
    D[i] += d

print(max(D)-min(D))

Failing test case input:
??10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
S = input()
N = len(S)

A = [0]*(N+1)
for i,s in enumerate(S,1):
    if s=="1":
        A[i] = A[i-1]+1
    else:
        A[i] = A[i-1]-1

m = max(A)
B = [A[-1]]*(N+1)
C = [m-A[-1]]*(N+1)
for i in range(N):
    i = N-i-1
    B[i] = max(A[i],B[i+1])
    C[i] = m-B[i]

d = 0
e = 0
D = A[:]
E = A[:]
for i,s in enumerate(S,1):
    if s=='?' and C[i] >= d+2:
        d += 2
    if s=='?' and C[i] >= e+1:
        e += 2
    D[i] += d
    E[i] += e
ans = min(max(D)-min(D),max(E)-min(E))
print(ans)
Problem: p03203
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h, w, n = map(int, input().split())
xy = sorted([list(map(int, input().split())) for _ in range(n)])
c = 0
for x, y in xy:
  if x-y > c:
    print(x-1)
    break
  if y == x:
    c += 1
else:
  print(h)

Failing test case input:
10 10 14
4 3
2 2
9 5
9 10
7 7
8 2
10 10
5 6
4 5
2 8
6 4
5 4
5 8
9 2

Expected output:
7


Actual output:
5


Fixed submission (verdict: Accepted):
h, w, n = map(int, input().split())
xy = sorted([list(map(int, input().split())) for _ in range(n)])
dx = 0
dy = 0
for x, y in xy:
  x -= dx
  y -= dy
  if x == y:
    dx += x-1
    dy += y-2
  elif y < x:
    print(dx+x-1)
    break
else:
  print(h)
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))
sa = [0]
for a in A:
    sa.append((sa[-1] + a) % K)
d = {0: 1}
ans = 0
for i in range(1, N+1):
    v = d.get(sa[i], 0)
    ans += v
    d[sa[i]] = v + 1
    if i >= K-1:
        d[sa[i-(K-1)]] -= 1
print(ans)

Failing test case input:
10 1
27 9 111 26 22 89 1 19 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))
sa = [0]
for a in A:
    sa.append((sa[-1] + a) % K)
d = {0: 1}
ans = 0
for i in range(1, N+1):
    if i >= K:
        d[sa[i-K]] -= 1
    v = d.get(sa[i], 0)
    ans += v
    d[sa[i]] = v + 1
print(ans)

Problem: p02851
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    S = [0] * (N + 1)  
    for i in range(1, N + 1):
        S[i] = S[i - 1] + A[i - 1]
    T = [(s - i) % K for i, s in enumerate(S)]
    counter = defaultdict(int)
    counter[0] = 1
    ans = 0
    for j in range(1, N + 1):
        ans += counter[T[j]]
        counter[T[j]] += 1
        if j - K + 1 >= 0:
            counter[T[j - K + 1]] -= 1
    print(ans)


if __name__ == '__main__':
    main()

Failing test case input:
10 1
27 9 110 26 22 89 1 19 30 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import defaultdict


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    S = [0] * (N + 1)  
    for i in range(1, N + 1):
        S[i] = S[i - 1] + A[i - 1]
    T = [(s - i) % K for i, s in enumerate(S)]
    counter = defaultdict(int)
    ans = 0
    for j in range(N + 1):
        if j >= K:
            counter[T[j - K]] -= 1
        ans += counter[T[j]]
        counter[T[j]] += 1
    print(ans)


if __name__ == '__main__':
    main()
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def nC2(n):
    if n == 0:
        return 0
    return n*(n-1)


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

A_acc = [0]+list(accumulate(A))


D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    D[t] += 1
print(D)

ans = 0
for i in range(K):
    ans += nC2(D[i])
print(ans)


Failing test case input:
10 7
14 15 92 65 35 89 79 32 38 46

Expected output:
8

Actual output:
defaultdict(<class 'int'>, {0: 3, 6: 4, 3: 1, 4: 1, 2: 1, 5: 1})
18


Fixed submission (verdict: Accepted):
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A_acc = [0]+list(accumulate(A))


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    if l>=K:
      r = (A_acc[l-K]-(l-K))
      D[r%K]-=1
    ans += D[t]
    D[t] += 1


print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x-1 ,a))
s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
s=list(map(lambda x:x%k,s))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0

for i in range(1,n+1):
    ans+=d[s[i]]
    d[s[i]]+=1
    if i>=k-1:
        d[s[i-k+1]]-=1
print(ans)


Failing test case input:
10 1
27 9 110 26 22 89 1 19 40 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x-1 ,a))

if k==1:
    print(0)
    exit()
s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
s=list(map(lambda x:x%k,s))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0

for i in range(1,n+1):
    ans+=d[s[i]]
    d[s[i]]+=1
    if i>=k-1:
        d[s[i-k+1]]-=1
print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = (cumA[i - 1] + A[i - 1]) % K

ans = 0
cnt = defaultdict(int)

for i, c in enumerate(cumA):
    diff = i - c % K
    ans += cnt[diff]
    cnt[diff] += 1

print(ans)

Failing test case input:
10 7
14 15 92 65 35 89 79 32 38 46

Expected output:
8

Actual output:
7


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
que = deque([])
ans = 0

for i, c in enumerate(cumA):
    while que and que[0][0] <= i - K:
        cnt[que.popleft()[1]] -= 1
    diff = (i - c) % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append((i, diff))
print(ans)
Problem: p02851
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

values = dict()
valuelist = [0]*(n+1)
values[0] = 1
s = 0
ans = 0

for i in range(n):
  s += a[i]-1
  s %= k
  if s in values:
    ans += values[s]
    values[s] += 1
  else:
    values[s] = 1
  
  valuelist[i+1] = s
  if i >= k-2:
    values[valuelist[i-k+2]] -= 1

print(ans)

Failing test case input:
10 1
14 26 111 26 22 89 0 36 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
import sys

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

values = dict()
valuelist = [0]*(n+1)
values[0] = 1
s = 0
ans = 0
if k == 1:
  print(0)
  sys.exit()

for i in range(n):
  s += a[i]-1
  s %= k
  if s in values:
    ans += values[s]
    values[s] += 1
  else:
    values[s] = 1
  
  valuelist[i+1] = s
  if i >= k-2:
    values[valuelist[i-k+2]] -= 1

print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = [int(a) - 1 for a in input().split()]
B = [0] + A
for i in range(1, N+1):
    B[i] += B[i-1]
    B[i] %= K

D = {0: 1}
s = 0
t = 0
ans = 0
for i in range(1, N+1):
    s = B[i]
    if s in D:
        ans += D[s]
        D[s] += 1
    else:
        D[s] = 1
    if i >= K - 1:
        t = B[i-K+1]
        D[t] -= 1
print(ans)

Failing test case input:
10 1
14 26 111 26 13 89 55 32 38 66

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = [0] + [int(a) - 1 for a in input().split()]
for i in range(1, N+1):
    A[i] = (A[i] + A[i-1]) % K

D = {0: 1}
ans = 0
for i in range(1, N+1):
    if i >= K:
        D[A[i-K]] -= 1
    a = A[i]
    if a not in D: D[a] = 0
    ans += D[a]
    D[a] += 1
print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

ans = 0
cnt = defaultdict(int)
cnt[0] += 1
que = deque([])

for i, c in enumerate(cumA[1:], start=1):
    if i > K:
        cnt[que.popleft()] -= 1

    diff = i - c % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append(diff)

print(ans)

Failing test case input:
10 2
40 2 100 26 22 15 2 19 8 46

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
que = deque([])
ans = 0

for i, c in enumerate(cumA):
    while que and que[0][0] <= i - K:
        cnt[que.popleft()[1]] -= 1
    diff = (i - c) % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append((i, diff))
print(ans)
Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[(A[0]-1)%k]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  
  if i+1>=k:
    d[AA[i-k]]-=1
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)


Failing test case input:
10 8
14 26 101 65 35 89 95 32 38 42

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[(A[0]-1)%k]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  if i+1==k:
    d[0]-=1
  elif i+1>=k:
    d[AA[i-k]]=max(0,d[AA[i-k]]-1)
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n, k = map(int, input().split()) 
nums = [int(i) for i in input().split()] 

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i + 1] + nums[i])
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1):
        left = nums[i - 1]
        right = nums[j]
        c = j - i
        if (right - left) % k == c and c < k:
            ans += 1
print(ans)


Failing test case input:
5 1
1 4 2 4 5

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):

from collections import defaultdict
n, k = map(int, input().split()) 
nums = [int(i) for i in input().split()] 

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i] + nums[i + 1] + k - 1) % k
ans = 0
d = defaultdict(int)
for i in range(n + 1):
    ans += d[nums[i]]
    d[nums[i]] += 1
    if i - (k - 1) >= 0:
        d[nums[i - (k - 1)]] -= 1
print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import sys

m=10**9 + 7
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split()))

B = list( map(lambda x: x % K, A))
C = [0]
x = 0
for b in B:
    x = (x + b ) % K
    C.append(x)



ans=0
for i in range(N):
    for j in range(i,N):
        
        
        if (C[j+1]-C[i]) % K == j-i:
            ans = ans + 1
print(ans)

exit(0)

Failing test case input:
8 4
4 4 4 2 4 2 4 2

Expected output:
5


Actual output:
8


Fixed submission (verdict: Accepted):
import math
import sys
import bisect
import array

m=10**9 + 7 
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split())) 

B = list( map(lambda x: x % K, A))
C = [0]
x = 0
i = 0 
for b in B:
    x = (x + b ) % K 
    C.append((x-i-1) % K) 
    i += 1 
    


E={}


ans=0
for i in range(N+1):
    if C[i] in E:
        ans += E[C[i]]
        E[C[i]] = E[C[i]] + 1
    else:
        E[C[i]] = 1
    if i >= K-1:
        E[C[i-K+1]] = E[C[i-K+1]] - 1
        if E[C[i-K+1]] == 0:
             E.pop(C[i-K+1])

print(ans)
exit(0)
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
dict = {}

for i in range(N):
    S[i+1]=S[i]+A[i]
    S[i+1]-=i+1
    S[i+1]%=K

ans =0
for i in range(N+1):
    if dict.get(S[i],0):
        ans += dict[S[i]]
        print(i,ans)
    dict[S[i]]=dict.get(S[i],0)+1
    if i >=K:
        dict[S[i-K]]-=1

print(ans)

Failing test case input:
10 3
4 26 111 26 35 89 95 32 38 46

Expected output:
4


Actual output:
1 1
2 3
3 6
5 7
6 8
7 10
8 12
9 13
10 14
14


Fixed submission (verdict: Accepted):
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
S2 = [0]*(N+1)
dict = {}

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)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split())) 

B = list( map(lambda x: x % K, A))
C = [0]
x = 0
for b in B:
    x = (x + b ) % K 
    C.append(x)
    


ans=0
for i in range(N-1):
    for j in range(i,N):
        
        
        if (C[j+1]-C[i]) % K == j-i:
            ans = ans + 1 
print(ans)

exit(0)

Failing test case input:
10 1
40 9 110 26 22 15 2 19 40 46

Expected output:
0


Actual output:
9


Fixed submission (verdict: Accepted):
import math
import sys
import bisect
import array

m=10**9 + 7 
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split())) 

B = list( map(lambda x: x % K, A))
C = [0]
x = 0
i = 0 
for b in B:
    x = (x + b ) % K 
    C.append((x-i-1) % K) 
    i += 1 
    


E={}


ans=0
for i in range(N+1):
    if C[i] in E:
        ans += E[C[i]]
        E[C[i]] = E[C[i]] + 1
    else:
        E[C[i]] = 1
    if i >= K-1:
        E[C[i-K+1]] = E[C[i-K+1]] - 1
        if E[C[i-K+1]] == 0:
             E.pop(C[i-K+1])

print(ans)
exit(0)
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))

lst=[0]
for i in range(0,N):
    lst.append((A[i]%K+lst[-1])%K)
for i in range(len(lst)):
    lst[i]-=i
    lst[i]%=K

dic={0:1}
count=0
for i in range(1,len(lst)):
    if lst[i] in dic:
        count+=dic[lst[i]]
        dic[lst[i]]+=1
    else:
        dic.update({lst[i]:1})
    a=i-K+1
    if a>=0:
        dic[lst[a]]-=1
print(count)


Failing test case input:
10 1
27 9 110 26 22 15 1 19 40 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))

lst=[0]
for i in range(0,N):
    lst.append((A[i]%K+lst[i])%K)
for i in range(len(lst)):
    lst[i]-=i
    lst[i]%=K

dic={}
count=0
for i in range(0,len(lst)):
    if lst[i] in dic:
        count+=dic[lst[i]]
        dic[lst[i]]+=1
    else:
        dic.update({lst[i]:1})
    a=i-K+1
    if a>=0:
        dic[lst[a]]-=1
print(count)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=[0]
for i in range(N):
    A.append((A[-1]+a[i]-1)%K)


D={}
D[0]=1
ans=0

for i in range(1,N+1):
    if A[i] in D:
        ans+=D[A[i]]
        D[A[i]]+=1
    else:
        D[A[i]]=1
    if i-K+1>=0:
        D[A[i-K+1]]-=1

print(ans)
        

Failing test case input:
10 1
27 9 110 26 22 15 1 19 40 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=[0]
for i in range(N):
    A.append((A[-1]+a[i]-1))
for i in range(len(A)):
    A[i]%=K


D={}
D[0]=1
ans=0

for i in range(1,N+1):
    if A[i] in D:
        ans+=D[A[i]]
        D[A[i]]+=1
    else:
        D[A[i]]=1
    if i-K+1>=0:
        D[A[i-K+1]]-=1

if K==1:
    print(0)
else:
    print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = (cumA[i - 1] + A[i - 1]) % K

ans = 0
cnt = defaultdict(int)
cnt[0] += 1
que = deque([])

for i, c in enumerate(cumA[1:], start=1):
    if i > K:
        cnt[que.popleft()] -= 1
    ans += cnt[c % K - i]
    cnt[-(-c % K) - i] += 1
    que.append(-(-c % K) - i)

print(ans)

Failing test case input:
10 7
18 15 92 65 35 89 79 12 38 46

Expected output:
9


Actual output:
5


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
que = deque([])
ans = 0

for i, c in enumerate(cumA):
    while que and que[0][0] <= i - K:
        cnt[que.popleft()[1]] -= 1
    diff = (i - c) % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append((i, diff))
print(ans)
Problem: p02851
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N,K=map(int,input().split())
A=list(map(int,input().split()))
DP=dict()
if K==1:
  print(0)
  exit()
DP[0]=1
P=0
Y=[0]*(N+1)
for i in range(N):
  Y[i+1]=(Y[i]+A[i]-1)%K
  P+=DP.get(Y[i+1],0)
  DP[Y[i+1]]=DP.get(Y[i+1],0)+1
  if i>=K-2:
    DP[Y[i-K+2]]-=1

Failing test case input:
10 7
14 15 101 65 35 89 79 18 38 46

Expected output:
5


Actual output:

Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
A=list(map(int,input().split()))
DP=dict()
if K==1:
  print(0)
  exit()
DP[0]=1
P=0
Y=[0]*(N+1)
for i in range(N):
  Y[i+1]=(Y[i]+A[i]-1)%K
  P+=DP.get(Y[i+1],0)
  DP[Y[i+1]]=DP.get(Y[i+1],0)+1
  if i>=K-2:
    DP[Y[i-K+2]]-=1
print(P)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=[0]
for i in range(N):
    A.append((A[-1]+a[i]-1))
for i in range(len(A)):
    A[i]%=K


D={}
D[0]=1
ans=0

for i in range(1,N+1):
    if A[i] in D:
        ans+=D[A[i]]
        D[A[i]]+=1
    else:
        D[A[i]]=1
    if i-K+1>=0:
        D[A[i-K+1]]-=1

print(ans)
        

Failing test case input:
10 1
27 9 111 26 22 89 1 19 30 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=[0]
for i in range(N):
    A.append((A[-1]+a[i]-1))
for i in range(len(A)):
    A[i]%=K


D={}
D[0]=1
ans=0

for i in range(1,N+1):
    if A[i] in D:
        ans+=D[A[i]]
        D[A[i]]+=1
    else:
        D[A[i]]=1
    if i-K+1>=0:
        D[A[i-K+1]]-=1

if K==1:
    print(0)
else:
    print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(n)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        ans+=f*(f-1)
        s=e
        f=0
    else:
        if p[s][1]+k-2>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f-1
            f-=1
            s+=1
print(ans+f)

Failing test case input:
4 1
14 26 111 26 35 89 95 32 38 46

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(0)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        ans+=f*(f-1)
        s=e
        f=0
    else:
        if p[s][1]+k-1>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f-1
            f-=1
            s+=1
print(ans+f*(f-1)
Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[(A[0]-1)%k]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  
  if i+1>=k:
    d[AA[i-k]]=max(0,d[AA[i-k]]-1)
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)


Failing test case input:
10 6
1 7 92 130 3 89 79 12 11 46

Expected output:
11


Actual output:
8


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[(A[0]-1)%k]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  if i+1==k:
    d[0]-=1
  elif i+1>=k:
    d[AA[i-k]]=max(0,d[AA[i-k]]-1)
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
  a[i] -= 1
  a[i] %= k

b = [0]
for i in range(n):
  b.append((b[-1]+a[i])%k)


ans = 0
now = {0:1}
for i in range(1,n+1):
  if b[i] in now:
    ans += now[b[i]]
    now[b[i]] += 1
  else:
    now[b[i]] = 1
  if i - k + 1 >= 0:
    now[b[i-k+1]] -= 1
  
print(ans)

Failing test case input:
10 1
14 26 111 26 36 89 0 36 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
  a[i] -= 1
  a[i] %= k

b = [0]
for i in range(n):
  b.append((b[-1]+a[i])%k)


ans = 0
now = {}
for i in range(n+1):
  if b[i] in now:
    ans += now[b[i]]
    now[b[i]] += 1
  else:
    now[b[i]] = 1
  if i - k + 1 >= 0:
    now[b[i-k+1]] -= 1
  
print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
for i, c in enumerate(cumA):
    cnt[i - c % K] += 1

ans = 0
for c in cnt.values():
    ans += c * (c - 1) 
print(ans)


Failing test case input:
10 7
18 15 92 65 35 89 79 12 38 46

Expected output:
9


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
que = deque([])
ans = 0

for i, c in enumerate(cumA):
    while que and que[0][0] <= i - K:
        cnt[que.popleft()[1]] -= 1
    diff = (i - c) % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append((i, diff))
print(ans)
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int, input().split())
l = list(map(int, input().split()))

l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
cum = [c%m for c in cum]

d = {}
ans = 0
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
print(ans)

Failing test case input:
10 1
14 26 111 26 22 89 55 36 38 46

Expected output:
0


Actual output:
55


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
l = list(map(int, input().split()))

l = [c-1 for c in l]
 
l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
cum = [c%k for c in cum]

from collections import deque
ans = 0
d = {}
q = deque()
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
  q.append(cum[i])
  if len(q) == k:
    rem = q.popleft()
    d[rem] -= 1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict

n,k = map(int, input().split())
a = list(map(int, input().split()))
s = [0]
for i in a:
    s.append((s[-1]+i-1)%k)

d = defaultdict(int)
d[0] = 1
ans = 0
for r in range(1, n+1):
    sr = s[r]
    if d[sr]:
        ans += d[sr]
    d[sr] += 1
    l = r-k+1
    if l >= 0:
        d[s[l]] -= 1
print(ans)

Failing test case input:
1 1
-1 8 1 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import defaultdict

n,k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
    print(0)
    exit()
s = [0]
for i in a:
    s.append((s[-1]+i-1)%k)

d = defaultdict(int)
d[0] = 1
ans = 0
for r in range(1, n+1):
    sr = s[r]
    if d[sr]>0:
        ans += d[sr]
    d[sr] += 1
    l = r-k+1
    if l >= 0:
        d[s[l]] -= 1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))

lst=[0]
for i in range(0,N):
    lst.append((A[i]%K+lst[i])%K)
for i in range(len(lst)):
    lst[i]-=i
    lst[i]%=K

dic={0:1}
count=0
for i in range(1,len(lst)):
    if lst[i] in dic:
        count+=dic[lst[i]]
        dic[lst[i]]+=1
    else:
        dic.update({lst[i]:1})
    a=i-K+1
    if a>=0:
        dic[lst[a]]-=1
print(count)


Failing test case input:
10 1
14 26 111 26 22 89 55 36 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))

lst=[0]
for i in range(0,N):
    lst.append((A[i]%K+lst[i])%K)
for i in range(len(lst)):
    lst[i]-=i
    lst[i]%=K

dic={}
count=0
for i in range(0,len(lst)):
    if lst[i] in dic:
        count+=dic[lst[i]]
        dic[lst[i]]+=1
    else:
        dic.update({lst[i]:1})
    a=i-K+1
    if a>=0:
        dic[lst[a]]-=1
print(count)
Problem: p02851
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque

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

val_cnt = {}
val_cnt[0] = 1
val_q = deque([0])

ans = 0
curr_sum = 0
for i in range(n):
    curr_sum += al[i]
    curr_sum %= k
    val = (curr_sum - (i+1))%k
    val_cnt.setdefault(val,0)
    ans += val_cnt[val]
    val_cnt[val] += 1
    val_q.append(val)
    if len(val_q) >= k:
        poped = val_q.popleft()
        val_cnt[poped] -= 1

print(ans)

Failing test case input:
10 1
14 26 111 26 22 89 55 32 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import deque

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

val_cnt = {}
val_cnt[0] = 1
val_q = deque([0])
if k == 1:
    print(0)
    exit()

ans = 0
curr_sum = 0
for i in range(n):
    curr_sum += al[i]
    curr_sum %= k
    val = (curr_sum - (i+1))%k
    val_cnt.setdefault(val,0)
    ans += val_cnt[val]
    val_cnt[val] += 1
    val_q.append(val)
    if len(val_q) >= k:
        poped = val_q.popleft()
        val_cnt[poped] -= 1

print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(n)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        ans+=f*(f-1)
        s=e
        f=0
    else:
        if p[s][1]+k-2>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f
            f-=1
            s+=1
print(ans)

Failing test case input:
10 3
14 26 111 65 35 89 184 32 38 46

Expected output:
4


Actual output:
10


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(0)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        ans+=f*(f-1)
        s=e
        f=0
    else:
        if p[s][1]+k-1>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f-1
            f-=1
            s+=1
print(ans+f*(f-1)
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))

S, LUT, ans = [0], {0: 1}, 0
for a in A:
    S.append(S[-1] + a)

for i in range(1, N + 1):
    p = (S[i] - i) % K
    ans += LUT[p] if p in LUT else 0
    if p in LUT:
        LUT[p] += 1
    else:
        LUT[p] = 1
    if i - K + 1 >= 0:
        LUT[(S[i - K + 1] - i + K - 1) % K] -= 1

print(ans)

Failing test case input:
10 1
14 11 111 26 22 89 1 19 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K == 1:
    print(0)
else:
    S, LUT, ans = [0], {0: 1}, 0
    for a in A:
        S.append(S[-1] + a)
    for i in range(1, N + 1):
        p = (S[i] - i) % K
        ans += LUT.get(p, 0)
        LUT[p] = LUT.get(p, 0) + 1
        if i - K + 1 >= 0:
            LUT[(S[i - K + 1] - i + K - 1) % K] -= 1
    print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def nC2(n):
    if n == 0:
        return 0
    return n*(n-1)


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

A_acc = [0]+list(accumulate(A))


D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    D[t] += 1

ans = 0
for i in range(K):
    ans += nC2(D[i])
print(ans)


Failing test case input:
10 1
40 2 100 26 22 15 2 19 13 46

Expected output:
0


Actual output:
110


Fixed submission (verdict: Accepted):
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A_acc = [0]+list(accumulate(A))


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    if l>=K:
      r = (A_acc[l-K]-(l-K))
      D[r%K]-=1
    ans += D[t]
    D[t] += 1


print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0]

for i in range(N):
    S.append(S[-1] + A[i] - (i+1))
    S[-1] %= K
    
B = dd(int)  
cnt = 0
for j in range(1,N):
    if j > K:
        B[S[j - 1 - K]] -= 1
    B[S[j]] += 1
    cnt += B[(-S[j]) % K]
print(cnt)

Failing test case input:
10 8
14 26 101 65 35 89 95 32 38 46

Expected output:
5


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)

for i in range(1, N + 1):
    S[i] = S[i - 1] + A[i - 1] - 1
    S[i] %= K
        
B = dd(int)  
cnt = 0
for j in range(1, N + 1):
    B[S[j - 1]] += 1
    if j - K >= 0:
        B[S[j - K]] -= 1
    cnt += B[S[j]]

print(cnt)
Problem: p02851
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque

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

val_cnt = {}
val_cnt[0] = 1
val_q = deque([0])
if k == 1:
    val_q.popleft()

ans = 0
curr_sum = 0
for i in range(n):
    curr_sum += al[i]
    curr_sum %= k
    val = (curr_sum - (i+1))%k
    val_cnt.setdefault(val,0)
    ans += val_cnt[val]
    val_cnt[val] += 1
    val_q.append(val)
    if len(val_q) >= k:
        poped = val_q.popleft()
        val_cnt[poped] -= 1

print(ans)

Failing test case input:
10 1
40 2 100 26 22 15 2 19 8 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import deque

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

val_cnt = {}
val_cnt[0] = 1
val_q = deque([0])
if k == 1:
    print(0)
    exit()

ans = 0
curr_sum = 0
for i in range(n):
    curr_sum += al[i]
    curr_sum %= k
    val = (curr_sum - (i+1))%k
    val_cnt.setdefault(val,0)
    ans += val_cnt[val]
    val_cnt[val] += 1
    val_q.append(val)
    if len(val_q) >= k:
        poped = val_q.popleft()
        val_cnt[poped] -= 1

print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A_acc = [0]+list(accumulate(A))


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    ans += D[t]
    D[t] += 1


print(ans)


Failing test case input:
10 1
14 9 111 26 22 89 1 36 38 46

Expected output:
0


Actual output:
55


Fixed submission (verdict: Accepted):
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A_acc = [0]+list(accumulate(A))


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    if l>=K:
      r = (A_acc[l-K]-(l-K))
      D[r%K]-=1
    ans += D[t]
    D[t] += 1


print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n, k = map(int, input().split()) 
nums = [int(i) for i in input().split()] 

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i + 1] + nums[i])
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1):
        left = nums[i - 1]
        right = nums[j]
        c = j - i
        if (right - left) % k == c:
            ans += 1
print(ans)


Failing test case input:
10 1
14 26 111 26 22 89 55 32 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):

from collections import defaultdict
n, k = map(int, input().split()) 
nums = [int(i) for i in input().split()] 

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i] + nums[i + 1] + k - 1) % k
ans = 0
d = defaultdict(int)
for i in range(n + 1):
    ans += d[nums[i]]
    d[nums[i]] += 1
    if i - (k - 1) >= 0:
        d[nums[i - (k - 1)]] -= 1
print(ans)
Problem: p02851
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict
n, k = map(int, input().split())


a = list(map(lambda x: int(x) - 1, input().split()))
s = [0] * (n + 1)
for i in range(n):
	s[i + 1] = (s[i] + a[i]) % k

mp = defaultdict(int)

print(s)
ans = 0
for i in range(n + 1):
	ans += mp[s[i]]
	mp[s[i]] += 1
	if i >= k - 1:
		mp[s[i - k + 1]] -= 1
print(ans)


Failing test case input:
0 1
0 1 0 6 3

Expected output:
0


Actual output:
[0]
0


Fixed submission (verdict: Accepted):
from collections import defaultdict
n, k = map(int, input().split())

a = list(map(lambda x: int(x) - 1, input().split()))
s = [0] * (n + 1)
for i in range(n):
	s[i + 1] = (s[i] + a[i]) % k

mp = defaultdict(int)

ans = 0
for i in range(n + 1):
	ans += mp[s[i]]
	mp[s[i]] += 1
	if i >= k - 1:
		mp[s[i - k + 1]] -= 1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
R=[0]
for i in range(1,N+1):
    R.append(R[-1]+A[i])
I=[i for i in range(N+1)]

ans=0
for i in range(N):
    for j in range(1,N):
        if i+j>=N:
            break
        if (R[i+j]-R[i])%K==(j):
            ans+=1
print(ans)

Failing test case input:
5 4
1 4 2 3 5

Expected output:
4

Actual output:
3


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=[0]
for i in range(N):
    A.append((A[-1]+a[i]-1))
for i in range(len(A)):
    A[i]%=K


D={}
D[0]=1
ans=0

for i in range(1,N+1):
    if A[i] in D:
        ans+=D[A[i]]
        D[A[i]]+=1
    else:
        D[A[i]]=1
    if i-K+1>=0:
        D[A[i-K+1]]-=1

if K==1:
    print(0)
else:
    print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(n)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        s=e
        f=0
    else:
        if p[s][1]+k-2>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f
            f-=1
            s+=1
print(ans)


Failing test case input:
1 1
-1 15 1 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
    print(0)
    exit()
nl=[]
for i in range(n):
    nl.append((l[i]-1)%k)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=(r[i]+nl[i])%k
p=[]
for i in range(n+1):
    p.append([r[i],i])
p.sort()
s=0
e=0
ans=0
f=0
while e<n+1:
    if p[s][0]!=p[e][0]:
        ans+=f*(f-1)
        s=e
        f=0
    else:
        if p[s][1]+k-1>=p[e][1]:
            f+=1
            e+=1
        else:
            ans+=f-1
            f-=1
            s+=1
print(ans+f*(f-1)
Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
  a[i] -= 1
  a[i + 1] += a[i]
a[n - 1] -= 1

memo = {0 : []}
for i in range(n):
  if a[i] % k not in memo.keys():
    memo[a[i] % k] = [i]
  else:
    memo[a[i] % k].append(i)

ans = bisect.bisect_left(memo[0], k - 1)

for i in memo.keys():
  for j in range(len(memo[i]) - 1):
    ans += bisect.bisect_left(memo[i], memo[i][j] + k) - 1 - j

print(memo)
print(ans)

Failing test case input:
8 4
4 1 4 2 4 2 4 2

Expected output:
7


Actual output:
{0: [], 3: [0, 1, 3, 5, 7], 2: [2, 4, 6]}
7


Fixed submission (verdict: Accepted):
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
  a[i] -= 1
  a[i + 1] += a[i]
a[n - 1] -= 1

memo = {0 : []}
for i in range(n):
  if a[i] % k not in memo.keys():
    memo[a[i] % k] = [i]
  else:
    memo[a[i] % k].append(i)

ans = bisect.bisect_left(memo[0], k - 1)

for i in memo.keys():
  for j in range(len(memo[i]) - 1):
    ans += bisect.bisect_left(memo[i], memo[i][j] + k) - 1 - j

print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict as d
from itertools import accumulate as ac
n,k=map(int,input().split())
a=[0]+list(ac(list(map(int,input().split()))))
b=d(int)
c=0
for i in range(n+1):
    p=(a[i]-i)%k
    c+=b[p]
    b[p]+=1
    if i-k>=0:
        b[(a[i-k]-i+k)%k]-=1
print(c)

Failing test case input:
10 1
14 9 111 26 22 89 0 36 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import defaultdict as d
from itertools import accumulate as ac
n,k=map(int,input().split())
a=[0]+list(ac(list(map(int,input().split()))))
b=d(int)
c=0
for i in range(n+1):
    p=(a[i]-i)%k
    c+=b[p]
    b[p]+=1
    if i-k+1>=0:
        b[(a[i-k+1]-i+k-1)%k]-=1
print(c)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

n, k = map(int, input().split()) 
nums = [int(i) for i in input().split()] 

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i + 1] + nums[i]) % k
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1):
        left = nums[i - 1]
        right = nums[j]
        c = j - i
        if (right - left) % k == c:
            ans += 1
print(ans)


Failing test case input:
10 8
14 15 101 65 35 89 79 32 38 46

Expected output:
5


Actual output:
8


Fixed submission (verdict: Accepted):

from collections import defaultdict
n, k = map(int, input().split()) 
nums = [int(i) for i in input().split()] 

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i] + nums[i + 1] + k - 1) % k
ans = 0
d = defaultdict(int)
for i in range(n + 1):
    ans += d[nums[i]]
    d[nums[i]] += 1
    if i - (k - 1) >= 0:
        d[nums[i - (k - 1)]] -= 1
print(ans)
Problem: p02851
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = defaultdict(int)
sa = [0] * (n + 1)
d[0] = 1
for i in range(n):
    sa[i + 1] = sa[i] + a[i]
    sa[i + 1] %= k
ans = 0
for i in range(1, n + 1):
    v = sa[i] - i
    v %= k
    ans += d[v]
    d[v] += 1
    if 0 <= i - k + 1:
        vv = sa[i - k + 1] - (i - k + 1)
        vv %= k
        d[vv] -= 1
print(ans)


Failing test case input:
10 1
14 9 101 26 22 89 1 36 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = defaultdict(int)
sa = [0] * (n + 1)
d[0] = 1
if k == 1:
    print(0)
    exit()
for i in range(n):
    sa[i + 1] = sa[i] + a[i]
    sa[i + 1] %= k
ans = 0
for i in range(1, n + 1):
    v = sa[i] - i
    v %= k
    ans += d[v]
    d[v] += 1
    if 0 <= i - k + 1:
        vv = sa[i - k + 1] - (i - k + 1)
        vv %= k
        d[vv] -= 1
print(ans)

Problem: p02851
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[A[0]-1]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  
  if i+1>=k:
    d[AA[i-k]]-=1
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)


Failing test case input:
10 3
14 26 111 65 35 89 95 32 38 46

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
AA=[(A[0]-1)%k]
for i in range(1,n):
  AA.append((AA[-1]+A[i]-1)%k)
import collections
d=collections.defaultdict(int)
d[0]+=1
for i in range(n):
  if i+1==k:
    d[0]-=1
  elif i+1>=k:
    d[AA[i-k]]=max(0,d[AA[i-k]]-1)
  ans+=d[AA[i]]
  d[AA[i]]+=1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import collections
def main():

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

    prefix = [0]
    d = collections.defaultdict(int)
    ans = 0
    for i in range(N):
        v = (prefix[-1]+A[i]) % K
        prefix.append(v)
        ans += d[v]
        d[(i + v) % K] += 1
        

    
    
    

    return ans - 1

    
    
    
    

if __name__ == '__main__':
    print(main())

Failing test case input:
0 1
0 15 1 2 1

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
import collections
def main():

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

    d = collections.defaultdict(int)

    prefix = [0]
    for i in range(N):
        prefix.append(prefix[-1] + A[i])

    ans = 0
    for j in range(N+1):
        v = (prefix[j] - j) % K
        ans += d[v]
        d[v] += 1
        if j >= K-1:
            d[(prefix[j-K+1] - (j-K+1)) % K] -= 1
        
    return ans



if __name__ == '__main__':
    print(main())
Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline



N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0] + list(itertools.accumulate(A))


if K == 0:
    print(0)
    exit()

d = defaultdict(int)
d[(S[0] - 0) % K] = 1

ans = 0
for j in range(1, N + 1):
    x = (S[j] - j) % K
    ans += d[x]
    d[x] += 1
    if j - K >= -1:
        y = (S[j - K + 1] - (j - K + 1)) % K
        d[y] -= 1

print(ans)

Failing test case input:
10 1
14 26 111 26 36 89 0 36 38 46

Expected output:
0


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline



N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0] + list(itertools.accumulate(A))


if K == 1:
    print(0)
    exit()

d = defaultdict(int)
d[(S[0] - 0) % K] = 1

ans = 0
for j in range(1, N + 1):
    x = (S[j] - j) % K
    ans += d[x]
    d[x] += 1
    if j - K >= -1:
        y = (S[j - K + 1] - (j - K + 1)) % K
        d[y] -= 1

print(ans)

Problem: p02851
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x-1 ,a))

if k==1:
    print(0)
s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
s=list(map(lambda x:x%k,s))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0

for i in range(1,n+1):
    ans+=d[s[i]]
    d[s[i]]+=1
    if i>=k-1:
        d[s[i-k+1]]-=1
print(ans)


Failing test case input:
10 1
40 9 110 26 22 15 2 19 40 46

Expected output:
0


Actual output:
0
10


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x-1 ,a))

if k==1:
    print(0)
    exit()
s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
s=list(map(lambda x:x%k,s))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0

for i in range(1,n+1):
    ans+=d[s[i]]
    d[s[i]]+=1
    if i>=k-1:
        d[s[i-k+1]]-=1
print(ans)

Problem: p02851
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
current=0
dic={}
dic[0]=1
for i in range(n):
  current=(current+a[i]-1)%k
  if current in dic:
    dic[current]+=1
  else:
    dic[current]=1
ans=0
for i in dic:
  ans+=(dic[i]*(dic[i]-1))
print(ans)

Failing test case input:
10 7
18 15 92 65 35 89 79 32 38 46

Expected output:
8


Actual output:
16


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
current=[0]
dic={}
dic[0]=1
ans=0
for i in range(n):
  current.append((current[-1]+a[i]-1)%k)
  if i>=k-1:
    dic[current[-k-1]]-=1
  if current[-1] in dic:
    ans+=dic[current[-1]]
    dic[current[-1]]+=1
  else:
    dic[current[-1]]=1
print(ans)