Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N+1):
    if i not in A:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[N])

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = set(int(input()) for _ in range(m)) #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = [int(input()) for _ in range(m)] #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = set(int(input()) for _ in range(m)) #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n,m = map(int,input().split())
A = [int(input()) for _ in range(m)] #壊れた階段

pos = 0
count = 1
dp = [0] * (n+1)
dp[0] = 1 #dp[i] i段目の時点での場合の数 dp[n]まで

for i in range(n):
    # dp[i] %= 1000000007
    if (i+1) in A and (i+2) in A:
        print(0)
        exit()
    if (i+1) not in A:
        dp[i+1] += dp[i]
    if (i+2) not in A and (i+2) <= n:
        dp[i+2] += dp[i]

print(dp[n] % 1000000007)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = set(int(input()) for _ in range(m)) #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n,m = map(int,input().split())
A = [int(input()) for _ in range(m)] #壊れた階段

pos = 0
count = 1
dp = [0] * (n+1)
dp[0] = 1

for i in range(N+1):
    if (i+1) in A and (i+2) in A:
        print(0)
        exit()
    if (i+1) not in A:
        dp[i+1] += dp[i]
    if (i+2) not in A:
        dp[i+2] += dp[i]

print(dp[n])

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = set(int(input()) for _ in range(m)) #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])
Buggy python submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])=='.'

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * S[i]
    D[-i-1] = (D[-i] + 1) * S[-i-1]

for i in range(W):
    L[:, i] = (L[:, i-1] + 1) * S[:, i]
    R[:, -i-1] = (R[:, -i] + 1) * S[-i-1]

print(np.max(R+L+U+D) - 3)

Fixed submission:
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])=='.'

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * S[i]
    D[-i-1] = (D[-i] + 1) * S[-i-1]

for i in range(W):
    L[:, i] = (L[:, i-1] + 1) * S[:, i]
    R[:, -i-1] = (R[:, -i] + 1) * S[:, -i-1]

print(np.max(R+L+U+D) - 3)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) + ['_'] for _ in range(H)]
S.append(['_'] * (W+1))

x_seq = [[0] * W for _ in range(H)]
y_seq = [[0] * W for _ in range(H)]

for k in range(H):
    left = 0
    right = 0
    seq = 0
    for i in range(W+1):
        if S[k][i] == '.':
            seq += 1
            right = i+1
        else:
            for j in range(left, right):
                x_seq[k][j] = seq
            seq = 0
            left = i+1
            right = i+1

for k in range(W):
    up = 0
    down = 0
    seq = 0
    for i in range(H+1):
        if S[i][k] == '.':
            seq += 1
            down = i+1
        else:
            for j in range(up, down):
                y_seq[j][k] = seq
            seq = 0
            up = down = i+1

grid = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        grid[i][j] = x_seq[i][j] + y_seq[i][j]
print(max([max(x) for x in grid]) - 1)


Fixed submission:
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])=='.'

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * S[i]
    D[-i-1] = (D[-i] + 1) * S[-i-1]

for i in range(W):
    L[:, i] = (L[:, i-1] + 1) * S[:, i]
    R[:, -i-1] = (R[:, -i] + 1) * S[:, -i-1]

print(np.max(R+L+U+D) - 3)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys

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

# 桁DP, Lを超えないものと保留のもの
MOD = 10 ** 9 + 7
L = sr()
dp = (1, 2)
length = len(L)
for i in range(1, length):
    prev = dp[:]
    if L[i] == '1':
        dp[0] = prev[0] * 3 + prev[1]
        dp[1] = prev[1] * 2
    else:
        dp[0] = prev[0] * 3
        dp[1] = prev[1]

answer = sum(dp)
print(answer%MOD)


Fixed submission:
import sys

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

L = list(sr())
MOD = 10 ** 9 + 7
bit_len = len(L)

dp_any = 1 # 1桁目が(0, 0)の組み合わせ, dp_any はi+1桁目がどんな数字でも条件を満たす
dp_spe = 2
for i in range(1, bit_len):
    x, y = dp_any, dp_spe
    if L[i] == '1':
        dp_any = x * 3 + y
        dp_spe = y * 2
    else:
        dp_any = x * 3
        dp_spe = y
    dp_any %= MOD
    dp_spe %= MOD

answer = (dp_any + dp_spe) % MOD
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

S = rs()
answer = 0
while True:
    x = S.count('ABC')
    if x > 0:
        answer += x
        S = S.replace('ABC', 'BCA')
    else:
        break
print(answer)

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

S = list(rs())
cur = 'D'
answer = 0
A_cnt = 0
for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D'

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

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

for _ in range(M):
    b, c = map(int, input().split())
    index = bisect_left(A, c)
    i = min(index, b)
    A = [c] * i + A[i:]
    A.sort()

print(sum(A))



Fixed submission:
from bisect import bisect_left
from operator import itemgetter

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
X = []
for _ in range(M):
    b, c = map(int, input().split())
    X.append((b, c))

X = sorted(X, key=itemgetter(1), reverse=True)

for b, c in X:
    BC.extend([c] * b)
    if len(BC) >= N:
        break

Y = A + BC
Y.sort(reverse=True)
answer = sum(Y[:N])
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import math
import decimal

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

decimal.getcontext().prec = 12
N, K = lr()
answer = decimal.Decimal(0)
for x in range(1, N+1):
    power = 0
    while x < K:
        x *= 2
        power += 1
    answer += decimal.Decimal(.5) ** power

answer /= N
print('{:.12f}'.format(answer))


Fixed submission:
N,K = map(int,input().split())
#サイコロが出た面を１から計算
ans = 0
for i in range(1,N+1):
    num = 0
    # iに２の何乗を掛けるとKを超えるか
    j = 0
    while True:
        if i * 2 ** j >= K:
            num = j
            break
        j += 1
    ans += (1/N) * (1/2) ** num
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

N = int(input())
UVW = sorted([list(map(int, input().split())) for _ in range(N-1)], key=itemgetter(0))
graph = [[-1] * N for _ in range(N)]

for u, v, w in UVW:
    graph[u-1][v-1] = w % 2
    graph[v-1][u-1] = w % 2
d = [-1] * N
d[0] = 0
def f(i):
    next_list = []
    for j in range(N):
        if i == j:
            continue
        if d[j] == -1 and graph[i][j] != -1 :
            d[j] = (d[i] + graph[i][j]) % 2
            next_list.append(j)
    for n in next_list:
        f(n)    
f(0)
for x in d:
    print(x)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
edges = [[] for _ in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    if w % 2 == 0:
        edges[u-1].append((v-1, 1))
        edges[v-1].append((u-1, 1))
    else:
        edges[u-1].append((v-1, -1))
        edges[v-1].append((u-1, -1))

colors = [None] * N
def set_color(x, c):
    colors[x] = c
    for y, sgn in edges[x]:
        if colors[y] == None:
            set_color(y, c*sgn)
set_color(0, 1)
for z in colors:
    print((z+1)//2)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

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

N, M = lr()

# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    # 根をbx(値の小さい方)に統一 
    A[by] = bx

V = [i for i in range(N)]
for i in range(M):
    x, y, z = lr()
    if find(V, x-1) != find(V, y-1):
        union(V, x-1, y-1)

answer = [find(x) for x in set(V)]
print(len(set(answer)))
# 36


Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

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

N, M = lr()

# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    # 根をbx(値の小さい方)に統一 
    A[by] = bx

V = [i for i in range(N)]
for i in range(M):
    x, y, z = lr()
    if find(V, x-1) != find(V, y-1):
        union(V, x-1, y-1)

answer = [find(V, x) for x in set(V)]
print(len(set(answer)))
# 36

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

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

N, M = lr()

# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    # 根をbx(値の小さい方)に統一 
    A[by] = bx

V = [i for i in range(N)]
for i in range(M):
    x, y, z = lr()
    if find(V, x-1) != find(V, y-1):
        union(V, x-1, y-1)

answer = [find(x) for x in set(V)]
print(len(answer))
# 36


Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

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

N, M = lr()

# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    # 根をbx(値の小さい方)に統一 
    A[by] = bx

V = [i for i in range(N)]
for i in range(M):
    x, y, z = lr()
    if find(V, x-1) != find(V, y-1):
        union(V, x-1, y-1)

answer = [find(V, x) for x in set(V)]
print(len(set(answer)))
# 36
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import itertools

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

# 0か1の連続している人数のリスト、累積和
streak = [0, 0]
N, K = lr()
S = sr() + '2'
cur = 1
for i in range(N):
    if S[i] != S[i+1]:
        streak.append(cur)
        cur = 1
    else:
        cur += 1

streak_cum = list(itertools.accumulate(streak))
streak_cum.extend([streak_cum[-1], streak_cum[-1]])
if S[0] == '0':
    start = 0
else:
    start = 1
answer = 0

for i in range(start, len(streak_cum), 2):
    result = streak_cum[i+2*K+1] - streak_cum[i]
    if result > answer:
        answer = result

print(answer)
# 52


Fixed submission:
import numpy as np

N, K = map(int, input().split())
S = np.array([int(x) for x in input()] + [2])

blocks = [] # 同じ数の塊
seq = 1
for i in range(N):
    if S[i+1] == S[i]:
        seq += 1
    else:
        blocks.append(seq)
        seq = 1
blocks = np.array(blocks)

answer = blocks[:2*K].sum()

start = 0 if S[0] == 1 else 1
for i in range(start, len(blocks), 2):
    answer = max(answer, blocks[i:i+(2*K+1)].sum())

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = list(input()) + ['2']

blocks = []
cur = 1
seq = 0
for s in S:
    if int(s) == cur:
        seq += 1
    else:
        blocks.append(seq)
        cur = 1 - cur
        seq = 1
answer = 0
for i in range(0, len(blocks), 2):
    answer = max(answer, sum(blocks[i:i+2*K+1]))
print(answer)

Fixed submission:
import numpy as np

N, K = map(int, input().split())
S = np.array([int(x) for x in input()] + [2])

blocks = [] # 同じ数の塊
seq = 1
for i in range(N):
    if S[i+1] == S[i]:
        seq += 1
    else:
        blocks.append(seq)
        seq = 1
blocks = np.array(blocks)

answer = blocks[:2*K].sum()

start = 0 if S[0] == 1 else 1
for i in range(start, len(blocks), 2):
    answer = max(answer, blocks[i:i+(2*K+1)].sum())

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0
while dp[5] < N:
    for i in range(4, -1, -1):
        if dp[i] == 0:
            continue
        dp[i+1] += min(dp[i],T[i])
        dp[i] -= min(dp[i],T[i])
    ans += 1
print(ans)


Fixed submission:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0

ans = -(-N//min(T)) + 4
# while dp[5] < N:
#     for i in range(4, -1, -1):
#         if dp[i] == 0:
#             continue
#         dp[i+1] += min(dp[i],T[i])
#         dp[i] -= min(dp[i],T[i])
#     ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0
while dp[5] < N:
    for i in range(4, -1, -1):
        dp[i+1] += min(dp[i],T[i])
        dp[i] -= min(dp[i],T[i])
    ans += 1
print(ans)


Fixed submission:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0

ans = -(-N//min(T)) + 4
# while dp[5] < N:
#     for i in range(4, -1, -1):
#         if dp[i] == 0:
#             continue
#         dp[i+1] += min(dp[i],T[i])
#         dp[i] -= min(dp[i],T[i])
#     ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for _ in range(Q)]
AC_list = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        AC_list.append(1)
    else:
        AC_list.append(0)
for a in A:
    check = AC_list[a[0]-1:a[1]-1]
    print(sum(check))


Fixed submission:
import numpy as np
N,Q = map(int,input().split())
S = np.array(list('_' + input()), dtype='U2')
A = (S == 'A')
C = (S == 'C')
AC = (A[:-1] & C[1:])
AC_cum = AC.cumsum()

for _ in range(Q):
    L,R = map(int,input().split())
    print(AC_cum[R-1] - AC_cum[L-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for _ in range(Q)]
AC_list = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        AC_list.append(1)
    else:
        AC_list.append(0)
for a in A:
    check = AC_list[a[0]-1:a[1]-1]
    print(sum(check))

Fixed submission:
import numpy as np
N,Q = map(int,input().split())
S = np.array(list('_' + input()), dtype='U2')
A = (S == 'A')
C = (S == 'C')
AC = (A[:-1] & C[1:])
AC_cum = AC.cumsum()

for _ in range(Q):
    L,R = map(int,input().split())
    print(AC_cum[R-1] - AC_cum[L-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for _ in range(Q)]
AC_list = []
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        AC_list.append(1)
    else:
        AC_list.append(0)
for a in A:
    check = AC_list[a[0]-1:a[1]-1]
    print(sum(check))

Fixed submission:
import numpy as np
N,Q = map(int,input().split())
S = np.array(list('_' + input()), dtype='U2')
A = (S == 'A')
C = (S == 'C')
AC = (A[:-1] & C[1:])
AC_cum = AC.cumsum()

for _ in range(Q):
    L,R = map(int,input().split())
    print(AC_cum[R-1] - AC_cum[L-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
B = rl()
l = []
for i in range(N):
    if i + 1 < B[i]:
        print(-1)
        exit()

while B:
    for i in range(len(B)-1, -1, -1):
        while True:
            if i + 1 == B[i]:
                if i == len(B)-1:
                    l.append(B.pop(i))
                    break
                elif B[i+1] <= i+1:
                    l.append(B.pop(i))
                else:
                    break
            else:
                break

l = l[::-1]
print(*l, sep='\n')
# 47

Fixed submission:
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
B = rl()
l = []
for i in range(N):
    if i + 1 < B[i]:
        print(-1)
        exit()

while B:
    for i in range(len(B)-1, -1, -1):
        if i + 1 == B[i]:
            l.append(B.pop(i))
            break

l = l[::-1]
print(*l, sep='\n')
# 47
Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
answer_set = {}
for i in range(1, N):
    for j in range(i+1, N+1):
        if i+j == N:
            continue
        else:
            answer_set.add((i, j))

print(len(answer_set))
for x in answer_set:
    print(*x)



Fixed submission:
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
answer_list = []
pair = N if N&1 else N+1
for i in range(1, N):
    for j in range(i+1, N+1):
        if i+j == pair:
            continue
        else:
            answer_list.append((i, j))

print(len(answer_list))
for x in answer_list:
    print(*x)
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
num = []
for i in range(1,min(A,B)):
    if A%i == 0 and B%i == 0:
        num.append(i)
print(num[-K])

Fixed submission:
A,B,K = map(int,input().split())
num = []
for i in range(1,min(A,B)+1):
    if A%i == 0 and B%i == 0:
        num.append(i)
print(num[-K])

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
num = []
for i in range(1,min(A,B)):
    if A%i == 0 and B%i == 0:
        num.append(i)
pritn(num[-K])

Fixed submission:
A,B,K = map(int,input().split())
num = []
for i in range(1,min(A,B)+1):
    if A%i == 0 and B%i == 0:
        num.append(i)
print(num[-K])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

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

N, M = lr()
AB = [lr() for _ in range(M)]
V = [x for x in range(N+1)]
total = N * (N-1) // 2

def find(A, x):
    parent = A[x]
    if parent == x: return x
    root = find(A, parent)
    A[x] = root
    return root

def union(A, x, y):
    root, second = find(A, x), find(A, y)
    if root > second:
        second, root = root, second
    A[second] = root

conv = 0
answer = []
for a, b in AB[::-1]:
    answer.append(total - conv)
    root_A = find(V, a); root_B = find(V, b)
    if root_A != root_B:
        conv += V.count(root_A) * V.count(root_B)
        union(V, a, b)
        V = [find(V, x) for x in V]

for x in answer[::-1]:
    print(x)


Fixed submission:
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for i in range(M)]
root = [i for i in range(N+1)]
comp_size = [1] * (N+1)

def find_root(x):
    a = root[x]
    if a == x:
        return x
    y = find_root(a)
    root[x] = y
    return y

def find_root(x):
  y = root[x]
  if x == y:
    return x
  z = find_root(y)
  root[x] = z
  return z

def merge(x, y):
    rx = find_root(x)
    ry = find_root(y)
    if rx == ry:
        return 0
    sx = comp_size[rx]
    sy = comp_size[ry]
    if sx >= sy:
        root[ry] = rx
        comp_size[rx] += sy
    else:
        root[rx] = ry
        comp_size[ry] += sx
    return sx * sy

result = N * (N-1) // 2
answer = []
for x, y in edges[::-1]:
    answer.append(result)
    result -= merge(x, y)

for r in answer[::-1]:
    print(r)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np

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

N = lr()
A = np.array(lr())
g = np.gcd.reduce(A)
print(g)


Fixed submission:
from functools import reduce
from fractions import gcd

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

answer = reduce(gcd, A)
print(answer)