Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03013 (python)

Fixed submission:
from collections import defaultdict

stairs = []
steps = []
MOD = 1000000007

n, m = map(int, input().split())
stairs = {int(input()):True for _ in range(m)}

step = defaultdict(int)
step[0] = 1

for i in range(n):
    if i in stairs.keys():
        step[i] = 0
    else:
        step[i+1] = (step[i] + step[i+1]) % MOD
        step[i+2] = (step[i] + step[i+2]) % MOD

print(step[n])

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

stairs = []
steps = []
MOD = 1000000007

n, m = int(input()), int((input()))
stairs = {int(input()):True for i in range(m)}

step = defaultdict(int)
step[0] = 1

for i in range(n):
    if i in stairs.keys():
        step[i] = 0
    else:
        step[i+1] = (step[i] + step[i+1]) % MOD
        step[i+2] = (step[i] + step[i+2]) % MOD

print(step[n])
Problem p02624 (python)

Fixed submission:
n=int(input())
t=0
k=0
for i in range(1,n+1):
   k=n//i
   t+=i*k*(k+1)//2

print(t)

Buggy submission (verdict: Runtime Error):
import sympy

n=int(input())
t=0
for i in range(1,n+1):
    t=t+(sympy.divisor_count(i)*i)

print(t)
Problem p02624 (python)

Fixed submission:
import numpy as np

N = int(input())

ans = 0

for i in range(1, N+1):
	n = int(N/i)
	ans += n * (n + 1) / 2 * i

print(int(ans))

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

N = int(input())

ans = np.zeros((N, N))
A = np.arange(1, N + 1)

ans[0, :] = A
ans[1, :] = A[A%2 == 0]
ans[2, :] = A[A%3 == 0]
ans[3, :] = A[A%4 == 0]

print(np.sum(ans))
Problem p02793 (python)

Fixed submission:
from sys import stdin
from collections import defaultdict

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = defaultdict(int)

for i in range(N):
    tmp = 1
    a = A[i]
    while tmp <= A[i] ** 0.5:
        cnt = 0
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            cnt += 1
        if cnt > 0:
            g[tmp] = max(g[tmp], cnt)
        tmp += 1
    if a > 1:
        if a not in g:
            g[a] = 1

l = 1
ans = 0
for i in g:
    l *= pow(i, g[i], mod)
    l %= mod
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = 1
ans = 0

for i in range(N):
    d = math.gcd(A[i], g)
    g *= A[i]
    g //= d

for i in range(N):
    ans += (g * pow(A[i], mod - 2, mod)) % mod

print(ans % mod)
Problem p02891 (python)

Fixed submission:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

cnt = 1
ans = 0
begin = 0
end = 0

start = 0
for i in range(1, len(S)):
    if S[i - 1] != S[i]:
        if start == 0:
            begin += cnt
        else:
            if cnt >= 2:
                ans += cnt // 2
        cnt = 1
        start = i
    else:
        cnt += 1
    if i == len(S) - 1:
        if start == 0:
            print((cnt * K) // 2)
            exit()
        end += cnt
        break

if S[0] != S[-1]:
    print(ans * K + (begin // 2) * K + (end // 2) * K)
else:
    print(ans * K + begin // 2 + end // 2 + ((begin + end) // 2) * (K - 1))

Buggy submission (verdict: Runtime Error):
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_odd[i - 1]:
        ans_odd += 1
        changed_odd[i] = True

if S[0] == S[len(S) - 1] and not changed_odd[len(S) - 1]:
    ans_odd += 1
    changed_even[0] = True

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_even[i - 1]:
        ans_even += 1
        changed_even[i] = True

if K % 2 == 0:
    print((ans_odd + ans_even) * (K // 2))
else:
    print((ans_odd + ans_even) * (K // 2) + ans_even)
Problem p02948 (python)

Fixed submission:
from sys import stdin
from collections import deque
import heapq


N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
available_work = []
while day <= M:
    for w in work[day]:
        heapq.heappush(available_work, -w)
    if len(available_work) > 0:
        ans += heapq.heappop(available_work)
    day += 1

print(-ans)

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

N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
max_work = np.array([])
while day <= M:
    w = 0
    tmp = 0
    max_work = max_work.tolist()
    if len(work[day]) > 0:
        max_work.append(work[day][0])
    else:
        max_work.append(-1)
    max_work = np.asarray(max_work)
    a = np.argmax(max_work) + 1
    if max_work[a - 1] > 0:
        ans += max_work[a - 1]
        work[a].popleft()
        if len(work[a]) > 0:
            max_work[a - 1] = work[a][0]
        else:
            max_work[a - 1] = -1
    day += 1

print(ans)
Problem p02984 (python)

Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = sum(A)
ans = [0 for _ in range(N)]
s = 0
for k in range(int((N - 1) / 2)):
    s += A[2 * k + 1] * 2
ans[0] = S - s
for k in range(1, N):
    ans[k] = A[k - 1] * 2 - ans[k - 1]
print(*ans)

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

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = np.zeros((N, N))
T = np.zeros(N)
for n in range(N):
    if n < N - 1:
        S[n][n] = 1
        S[n][n + 1] = 1
        T[n] = A[n] * 2
    else:
        S[n][n] = 1
        S[n][0] = 1
        T[n] = A[n] * 2

X = np.linalg.solve(S, T)
print(*[int(x) for x in X])

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

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = np.zeros((N, N))
T = np.zeros(N)
for n in range(N):
    if n < N - 1:
        S[n][n] = 1
        S[n][n + 1] = 1
        T[n] = A[n] * 2
    else:
        S[n][n] = 1
        S[n][0] = 1
        T[n] = A[n] * 2

X = np.linalg.solve(S, T)
print(*[int(x) for x in X])

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

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = np.zeros((N, N))
T = np.zeros(N)
for n in range(N):
    if n < N - 1:
        S[n][n] = 1
        S[n][n + 1] = 1
        T[n] = A[n] * 2
    else:
        S[n][n] = 1
        S[n][0] = 1
        T[n] = A[n] * 2

X = np.linalg.solve(S, T)
for x in X:
    print(int(x), end=" ")
Problem p03013 (python)

Fixed submission:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(stdin.readline().rstrip()) for _ in range(M)]
fib = [1, 1]
for k in range(N):
    fib.append((fib[-1] + fib[-2]) % 1000000007)
if M == 0:
    print(fib[N])
    exit()
ans = fib[a[0] - 1]
for l in range(M - 1):
    if a[l + 1] - a[l] == 1:
        print(0)
        exit()
    ans = ans * fib[a[l + 1] - a[l] - 2]
ans = ans * fib[N - a[-1] - 1]
print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(stdin.readline().rstrip()) for _ in range(M)]
fib = [1, 1]
for k in range(N):
    fib.append((fib[-1] + fib[-2]) % 1000000007)
ans = fib[a[0] - 1]
for l in range(M - 1):
    if a[l + 1] - a[l] == 1:
        print(0)
        exit()
    ans = ans * fib[a[l + 1] - a[l] - 2]
ans = ans * fib[N - a[-1] - 1]
print(ans % 1000000007)
Problem p03053 (python)

Fixed submission:
from sys import stdin
from collections import deque

H, W = [int(x) for x in stdin.readline().rstrip().split()]
B = [list(stdin.readline().rstrip()) for _ in range(H)]

q = deque([])

for k in range(H):
    for l in range(W):
        if B[k][l] == '#':
            q.append((k, l, 0))

while len(q) > 0:
    h, w, t = q.popleft()
    if h > 0:
        if B[h - 1][w] == '.':
            B[h - 1][w] = '#'
            q.append((h - 1, w, t + 1))
    if h < H - 1:
        if B[h + 1][w] == '.':
            B[h + 1][w] = '#'
            q.append((h + 1, w, t + 1))
    if w > 0:
        if B[h][w - 1] == '.':
            B[h][w - 1] = '#'
            q.append((h, w - 1, t + 1))
    if w < W - 1:
        if B[h][w + 1] == '.':
            B[h][w + 1] = '#'
            q.append((h, w + 1, t + 1))
    if len(q) == 0:
        print(t)

Buggy submission (verdict: Runtime Error):
from sys import stdin

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = [stdin.readline().rstrip() for _ in range(H)]
B = [[A[x][y] for x in range(H)] for y in range(W)]
queue = []

for k in range(H):
    for l in range(W):
        if A[k][l] == '#':
            queue.append((k, l, 0))


while len(queue) > 0:
    h, w, t = queue.pop(0)
    if h > 0:
        if B[h - 1][w] == '.':
            B[h - 1][w] = '#'
            queue.append((h - 1, w, t + 1))
    if h < H - 1:
        if B[h + 1][w] == '.':
            B[h + 1][w] = '#'
            queue.append((h + 1, w, t + 1))
    if w > 0:
        if B[h][w - 1] == '.':
            B[h][w - 1] = '#'
            queue.append((h, w - 1, t + 1))
    if w < W - 1:
        if B[h][w + 1] == '.':
            B[h][w + 1] = '#'
            queue.append((h, w + 1, t + 1))
    if len(queue) == 0:
        print(t)
Problem p03127 (python)

Fixed submission:
from sys import stdin
import fractions
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = A[0]
for k in range(N)[1:]:
    ans = fractions.gcd(ans, A[k])
print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = A[0]
for k in range(N)[1:]:
    ans = math.gcd(ans, A[k])
print(ans)
Problem p03272 (python)

Fixed submission:
from sys import stdin
 
N, i = [int(x) for x in stdin.readline().rstrip().split()]
 
print(N + 1 - i)

Buggy submission (verdict: Runtime Error):
from sys import stdin

H, W = [int(x) for x in stdin.readline().rstrip().split()]

A = [list(stdin.readline().rstrip()) for _ in range(H)]
result = A

delete_column = []
delete_row = []

for k in range(W):
    cnt = 0
    for l in A[k]:
        if l == '.':
            cnt += 1
    if cnt == len(A[k]):
        delete_row.append(k)

for k in range(W):
    cnt = 0
    for l in range(H):
        if A[l][k] == '.':
            cnt += 1
    if cnt == H:
        delete_column.append(k)

for x in delete_row:
    del result[x]

for x in delete_column:
    for y in range(len(A)):
        del result[y][x]

for x in result:
    print(''.join(x))

Buggy submission (verdict: Runtime Error):
rom sys import stdin

N, i = [int(x) for x in stdin.readline().rstrip().split()]

print(N + 1 - i)
Problem p03307 (python)

Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())

if N % 2 == 0:
    print(N)
else:
    print(2 * N)

Buggy submission (verdict: Runtime Error):
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    print(min(get_pity_sum(int((N - 1) / 2)), get_pity_sum(int((N - 1) / 2 - 1)), get_pity_sum(int((N - 1) / 2 + 1))))
else:
    print(min(get_pity_sum(int(N / 2)), get_pity_sum(int(N / 2 - 1))))
Problem p03038 (python)

Fixed submission:
import collections
n,m = map(int,input().split())
a = list(map(int,input().split()))
col = collections.Counter(a)
 
for i in range(m):
  b,c = map(int,input().split())
  col[c] += b
col = sorted(col.items(), key=lambda x:x[0],reverse=True)
 
ans=0
for k,v in col:
  if n <= v:
    ans += k*n
    break
  else:
    ans += k*v
    n -= v
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n,m = map(int,input().split())
a = list(map(int,input().split()))
col = collections.Counter(a)
 
for i in range(m):
  b,c = map(int,input().split())
  col[c] += b
col = sorted(col.items(), key=lambda x:x[0],reverse=True)
 
ans=0
for k,v in col:
  if n <= v:
    ans += k*n
    break
  else:
    ans += k*v
    n -= v
print(ans)
Problem p03232 (python)

Fixed submission:
#!/usr/bin/env python3

# import sys
# sys.setrecursionlimit(200000)  # ttk

MOD = 1000000007
fact = []
q = []

def main():
    n = int(input())
    an = list(map(int, input().split()))
    init_fact(100000)
    init_q(100000, n)
    res = 0
    for j, a in enumerate(an):
        res += a * (q[n - j] + q[j + 1] - q[1])
        res %= MOD
    print(res)

def init_q(maxn, n):
    assert len(q) == 0
    assert len(fact) == maxn + 1
    q.append(0)
    for l in range(1, maxn + 1):
        dq = fact[n] * inv(l)
        q.append((q[-1] + dq) % MOD)

def init_fact(maxn):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % MOD)

def inv(n):
    return pow(n, MOD - 2)

def pow(n, p):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2)
        return (x * x) % MOD
    else:
        x = pow(n, p - 1)
        return (x * n) % MOD

main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

# import sys
# sys.setrecursionlimit(200000)  # ttk

MOD = 1000000007
fact = []

def main():
    n = int(input())
    an = list(map(int, input().split()))
    init_fact(100000)
    c, w = cost_ways(an)
    print(c)

def cost_ways(a):  # ttk: memoization
    l = len(a)
    sum_cost = 0
    sum_ways = 0
    for ip in range(l):
        local_cost = sum(a)  # ttk: ruiseki-wa
        ll = ip
        lr = l - ip - 1
        if ll >= 1:
            cl, wl = cost_ways(a[:ip])
        else:
            cl, wl = 0, 1
        if lr >= 1:
            cr, wr = cost_ways(a[ip + 1:])
        else:
            cr, wr = 0, 1
        co = combi(ll + lr, ll) if ll >= 1 and lr >= 1 else 1
        c = local_cost * co * wl * wr + cl * co * wr + cr * co * wl
        sum_cost = (sum_cost + c) % MOD
        sum_ways = (sum_ways + co * wl * wr) % MOD
    return sum_cost, sum_ways

def combi(n, k):
    numera = fact[n]
    denomi = (fact[n - k] * fact[k]) % MOD
    return (numera * inv(denomi)) % MOD

def init_fact(maxn):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % MOD)

def inv(n):
    return pow(n, MOD - 2)

def pow(n, p):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2)
        return (x * x) % MOD
    else:
        x = pow(n, p - 1)
        return (x * n) % MOD

main()
Problem p02688 (python)

Fixed submission:
n,k = map(int,input().split()) #n任 k種類
d = []
a = []
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))


sunuke =[0] * n
for i in range(k):
    #print("d[i]",d[i])
    for j in range(int(d[i])):
        temp = a[i][j] -1 
        sunuke[temp] += 1

#print(sunuke)
print(sunuke.count(0))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split()) #n任 k種類
d = []
a = []
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))


sunuke =[0] * n
for i in range(n-1):
    #print("d[i]",d[i])
    for j in range(int(d[i])):
        temp = a[i][j] -1 
        sunuke[temp] += 1

print(sunuke.count(0))
Problem p02831 (python)

Fixed submission:
from fractions import gcd
a,b = map(int,(input().split()))
print((a * b) // gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,(input().split()))
print((a * b) // math.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,(input().split()))
print((a * b) // math.gcd(a,b))
Problem p03345 (python)

Fixed submission:
a,b,c,k = list(map(int,input().split()))	
x = 10 **18
result = a - b
if result > x:
    print("Unfair")
elif k % 2 == 0:
    print(result)
elif k % 2 == 1:
    result = result * -1
    print(result)

Buggy submission (verdict: Runtime Error):
a,b,c,k = list(map(int,input().split()))	

 if result > 10 **18:
    print("Unfair")
elif k % 2 == 0:
    print(result)
elif l % 2 == 1:
    result = result * -1
    print(result)
Problem p02685 (python)

Fixed submission:
def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod
mod = 998244353
N, M, K = map(int, input().split())
x = [1]*N
for i in range(1,N):
    x[i] = Pow(i, mod-2)
cmb = [1]*N
for i in range(N-2):
    cmb[i+1] = ((cmb[i]*(N-1-i))%mod*x[i+1])%mod
ans = 0
for i in range(K+1):
    num = Pow(M-1, N-1-i)
    ans = (ans+M*num%mod*cmb[i]%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod
mod = 998244353
N, M, K = map(int, input().split())
x = [1]*N
for i in range(1,N):
    x[i] = Pow(i, mod-2)
cmb = [1]*(N-1)
for i in range(N-2):
    cmb[i+1] = ((cmb[i]*(N-1-i))%mod*x[i+1])%mod
ans = 0
for i in range(K+1):
    num = Pow(M-1, N-1-i)
    ans = (ans+M*num%mod*cmb[i]%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1
li = [False] * N
f = True
now = 0
l = []
l2 = [0] * N
i = 0
while f:
    l.append(now)
    li[now] = True
    l2[now] = i
    if li[A[now]]:
        f = False
        num = len(l) - l2[A[now]]
        n = l2[A[now]]
    i += 1
    now = A[now]
k = (K-n) % num
print(l[min(K, n+k)]+1)
Problem p02781 (python)

Fixed submission:
from math import log
def solve(N, K):
    if N == 0:
        return 0
    if N == 1:
        if K == 1:
            return 1
        return 0
    num = int(log(N, 10))
    if K == 1:
        res = 9 * num + N//(10**num)
        return res
    if K == 2:
        res = 9 ** 2 * (num*(num-1))//2 
        res += (N//(10**num) - 1)*num*9
        res += solve(N - N//(10**num)*(10**num), 1)
        return res
    if K == 3:
        res = 9 ** 3 * (num*(num-1)*(num-2))//6
        res += (N//(10**num) - 1)*(num*(num-1))*81//2
        res += solve(N - N//(10**num)*(10**num), 2)
        return res
N = int(input())
K = int(input())
print(solve(N, K))

Buggy submission (verdict: Runtime Error):
from math import log
def solve(N, K):
    if N == 1:
        if K == 1:
            return 1
        return 0
    num = int(log(N, 10))
    if K == 1:
        res = 9 * num + N//(10**num)
        return res
    if K == 2:
        res = 9 ** 2 * (num*(num-1))//2 
        res += (N//(10**num) - 1)*num*9
        res += solve(N - N//(10**num)*(10**num), 1)
        return res
    if K == 3:
        res = 9 ** 3 * (num*(num-1)*(num-2))//6
        res += (N//(10**num) - 1)*(num*(num-1))*81//2
        res += solve(N - N//(10**num)*(10**num), 2)
        return res
N = int(input())
K = int(input())
print(solve(N, K))

Buggy submission (verdict: Runtime Error):
from math import log
def solve(N, K):
    num = int(log(N, 10))
    if K == 1:
        res = 9 * num + N//(10**num)
        return res
    if K == 2:
        res = 9 ** 2 * (num*(num-1))//2 
        res += (N//(10**num) - 1)*num*9
        res += solve(N - N//(10**num)*(10**num), 1)
        return res
    if K == 3:
        res = 9 ** 3 * (num*(num-1)*(num-2))//6
        res += (N//(10**num) - 1)*(num*(num-1))*81//2
        res += solve(N - N//(10**num)*(10**num), 2)
        return res
N = int(input())
K = int(input())
print(solve(N, K))
Problem p02851 (python)

Fixed submission:
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
    S[i+1] = (S[i] + A[i])%K
    T[i+1] = (S[i+1] - (i+1))%K
rest = defaultdict(int)
for i in range(N+1):
    if i < K:
        ans += rest[T[i]]
        rest[T[i]] += 1
    else:
        rest[T[i-K]] -= 1
        ans += rest[T[i]]
        rest[T[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
    S[i+1] = (S[i] + A[i])%K
    T[i+1] = (S[i+1] - (i+1))%K
rest = [0] * K
for i in range(N+1):
    if i < K:
        ans += rest[T[i]]
        rest[T[i]] += 1
    else:
        rest[T[i-K]] -= 1
        ans += rest[T[i]]
        rest[T[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
    S[i+1] = (S[i] + A[i])%K
    T[i+1] = (S[i+1] - (i+1))%K
rest = [0] * K
if N+1 >= K:
    for i in range(K):
        rest[T[i]] += 1
    for i in range(N-K+1):
        rest[T[i]] -= 1
        ans += rest[T[i]]
        rest[T[i+K]] += 1
    for i in range(N-K+1, N+1):
        rest[T[i]] -= 1
        ans += rest[T[i]]
else:
    for i in range(N+1):
        rest[T[i]] += 1
    for i in range(N+1):
        rest[T[i]] -= 1
        ans += rest[T[i]]
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
    S[i+1] = (S[i] + A[i])%K
    T[i+1] = (S[i+1] - (i+1))%K
rest = [0] * K
if N+1 >= K:
    for i in range(K):
        rest[T[i]] += 1
    for i in range(N-K+1):
        rest[T[i]] -= 1
        ans += rest[T[i]]
        rest[T[i+K]] += 1
    for i in range(N-K+1, N+1):
        rest[T[i]] -= 1
        ans += rest[T[i]]
else:
    for i in range(N+1):
        rest[T[i]] += 1
    for i in range(N+1):
        rest[T[i]] -= 1
        ans += rest[T[i]]
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
    S[i+1] = (S[i] + A[i])%K
    T[i+1] = (S[i+1] - (i+1))%K
rest = [0] * K
for i in range(K):
    rest[T[i]] += 1 
for i in range(N-K+1):
    rest[T[i]] -= 1
    ans += rest[T[i]]
    rest[T[i+K]] += 1
for i in range(N-K+1, N+1):
    rest[T[i]] -= 1
    ans += rest[T[i]]
print(ans)
Problem p02862 (python)

Fixed submission:
mod = 10**9+7

def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod

X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (X+Y)//3
    if X < n or Y < n or X > 2*n or Y > 2*n:
        print(0)
    else:
        k = min(X-n, Y-n)
        R = [0] * (k+1)
        for i in range(1,k+1):
            R[i] = Pow(i, mod-2)
        cmb = [0]*(k+1)
        cmb[0] = 1
        for i in range(k):
            cmb[i+1] = ((cmb[i]*(n-i))%mod)*R[i+1]%mod
        print(cmb[k])

Buggy submission (verdict: Runtime Error):
mod = 10**9+7

def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod

X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (X+Y)//3
    if X < n or Y < n or X > 2*n or Y > 2*n:
        print(0)
    else:
        k = X-n
        R = [0] * n
        for i in range(1,n):
            R[i] = Pow(i, mod-2)
        cmb = [0]*n
        cmb[0] = 1
        for i in range(n-1):
            cmb[i+1] = ((cmb[i]*(n-i))%mod)*R[i+1]%mod
        print(cmb[k])