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

Fixed submission:
n = int(input())

import math
ans = []
for i in range(1,int(math.sqrt(n))+1):
  if n % i == 0:
    b = int(n/i)
    ans.append(i+b-2)
print(min(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())

import math
ans = []
for i in range(1,int(math.sqrt(n))):
  if n % i == 0:
    b = int(n/i)
    ans.append(i+b-2)
print(min(ans))
Problem p02580 (python)

Fixed submission:
h, w, m = map(int, input().split())
hw = []
h_cnt = [0] * h
w_cnt = [0] * w
hw = []
hw_set = set()
for _ in range(m):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    h_cnt[r] += 1
    w_cnt[c] += 1
    hw.append((r, c))
    hw_set.add((r, c))
mh = max(h_cnt)
mw = max(w_cnt)
cand_r = []
for i in range(h):
    if h_cnt[i] == mh:
        cand_r.append(i)
cand_c = []
for j in range(w):
    if w_cnt[j] == mw:
        cand_c.append(j)
ans = mh + mw
for i in cand_r:
    for j in cand_c:
        if not (i, j) in hw_set:
            print(ans)
            exit()
print(ans - 1)

Buggy submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
x = [0] * m
y = [0] * m
for i in range(m):
    x[i], y[i] = map(int, input().split())


def compress(arr1):
    from bisect import bisect_left
    vals = []
    for i in range(len(arr1)):
        for d in range(2):
            v1 = arr1[i] + d
            vals.append(v1)
    unique_elems = sorted(set(vals))
    for i in range(len(arr1)):
        arr1[i] = bisect_left(unique_elems, arr1[i])
    return unique_elems


def main():
    all_x = compress(x)
    all_y = compress(y)
    matrix = [[0] * len(all_x) for _ in range(len(all_y))]
    for i in range(m):
        matrix[x[i]][y[i]] += 1
    lr = len(matrix)
    lc = len(matrix[0])
    r_cnt = [0] * lr
    c_cnt = [0] * lc
    for r in range(lr):
        for c in range(lc):
            if matrix[r][c] == 1:
                r_cnt[r] += 1
                c_cnt[c] += 1
    ans = 0
    for r in range(lr):
        for c in range(lc):
            temp = r_cnt[r] + c_cnt[c]
            if matrix[r][c] == 1:
                temp -= 1
            ans = max(ans, temp)
    print(ans)


if __name__ == '__main__':
    main()
Problem p02661 (python)

Fixed submission:
N = int(input())
import numpy as np
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int,input().split())
na = np.median(A)
nb = np.median(B)
if N%2 == 1:
    ans = int(nb - na + 1)
    print(ans)
    exit()
else:
    ans = int(2*(nb - na)) + 1
    print(ans)
    exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
import numpy as np
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int,input().split())
na = np.median(A)
nb = np.median(B)
if N%2 == 1:
    ans = int(nb - na + 1)
    print(ans)
    exit()
else:
    ans = 2*int(nb - na) + 1
    print(ans)
    exit()
Problem p02834 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, a, b = map(int, input().split())
D = [[0]*2 for _ in range(101010)]
E = [[] for _ in range(n)]


def dfs(cur, pre, d, id):
    D[cur][id] = d
    for nv in E[cur]:
        if nv != pre:
            dfs(nv, cur, d+1, id)


a -= 1
b -= 1
for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
dfs(a, a, 0, 0)
dfs(b, b, 0, 1)
max_d = 0
for i in range(n):
    if D[i][0] < D[i][1]:
        max_d = max(max_d, D[i][1]-1)
print(max_d)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
D = [[0]*2 for _ in range(101010)]
E = [[] for _ in range(n)]


def dfs(cur, pre, d, id):
    D[cur][id] = d
    for nv in E[cur]:
        if nv != pre:
            dfs(nv, cur, d+1, id)


a -= 1
b -= 1
for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
dfs(a, a, 0, 0)
dfs(b, b, 0, 1)
max_d = 0
for i in range(n):
    if D[i][0] < D[i][1]:
        max_d = max(max_d, D[i][1]-1)
print(max_d)
Problem p02862 (python)

Fixed submission:
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

X, Y = map(int, input().split())
if (X+Y) % 3 != 0 or not (X <= 2*Y and Y <= 2*X):
    print(0)
    exit()

n = (X+Y) // 3
r = Y - n
#print(n, r)
print(combination(n, r))

Buggy submission (verdict: Runtime Error):
from math import factorial
X, Y = map(int,input().split())

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    N = int((X+Y)/3)

    if X >= Y:
        #K = N - (X - Y) + 1
        K = N/2 - (X - Y) + 1

    else:
        K = N/2 + (Y - X) + 1

    #ans = factorial(N-1)/(factorial(N-K)*factorial(K-1))
    # ans = factorial(N+1-1)/(factorial(N-K+1)*factorial(K-1))
    # ans %= MOD
    bunsi = factorial(N)%MOD
    bunbo = (factorial(N-K+1)*factorial(K-1))%MOD
    ans = int(bunsi/bunbo)


#print(N)
#print(K)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial
X, Y = map(int,input().split())

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    N = int((X+Y)/3)

    if X >= Y:
        #K = N - (X - Y) + 1
        K = N/2 - (X - Y) + 1

    else:
        K = N - (Y - X) + 1

    #ans = factorial(N-1)/(factorial(N-K)*factorial(K-1))
    ans = factorial(N+1-1)/(factorial(N-K+1)*factorial(K-1))
    ans %= MOD


#print(N)
#print(K)
print(ans)
Problem p02897 (python)

Fixed submission:
N = int(input())
if N%2:
    print((N+1)/(2*N))
else:
    print(0.5)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N%2:
    print((N+1)/(2*N))
else:
    print(0.5)N = int(input())
if N%2:
    print((N+1)/(2*N))
else:
    print(0.5)
Problem p03013 (python)

Fixed submission:
N, M = map(int,input().split())
dp = [0]*(N+1)
broke = [0]*(N+1)
dp[0] = 1
dp[1] = 1

for _ in range(M):
    a = int(input())
    broke[a] = -1

for i in range(N-1):
    if broke[i] != -1 and broke[i+1] != -1:
        dp[i+2] = dp[i+1] + dp[i]
    elif broke[i] == -1and broke[i+1] != -1:
        dp[i+2] = dp[i+1]
    elif broke[i+1] == -1and broke[i] != -1:
        dp[i+2] = dp[i]
    else:
        print(0)
        exit()
# print(broke)
# print(dp)
MOD = 10**9+7
print(dp[N]%MOD)

Buggy submission (verdict: Runtime Error):
import numpy as np
BIG_NUM = 10**9+7
def stairs_n(n):
    if n <= 3:
        return n
    else:
        return stairs_n(n-1)+stairs_n(n-2)

#print(stairs_n(30))

n,m = map(int,input().split())

if m == 0:
    print(stairs_n(n)%BIG_NUM)
else:


    a_list = [int(input()) for _ in range(m)]
    a_list.append(n)
    a_list.insert(0,1)
    a_np = np.array(a_list)
    diff_a_np = np.diff(a_np)-1
    ans = 1
    # print(a_np)
    # print(diff_a_np)
    for num in diff_a_np:
        ans *= stairs_n(num)

    print(ans%BIG_NUM)

Buggy submission (verdict: Runtime Error):
import numpy as np
BIG_NUM = 10**9+7
def stairs_n(n):
    if n <= 3:
        return n
    else:
        return stairs_n(n-1)+stairs_n(n-2)

#print(stairs_n(30))

n,m = map(int,input().split())

if m == 0:
    print(stairs_n(n)%BIG_NUM)
else:


    a_list = [int(input()) for _ in range(m)]
    a_list.append(n)
    a_np = np.array(a_list)
    diff_a_np = np.diff(a_np)-1
    ans = 1
    # print(a_np)
    # print(diff_a_np-1)
    ans *= (a_list[0])
    for num in diff_a_np:
        ans *= stairs_n(num)

    print(ans%BIG_NUM)
Problem p03038 (python)

Fixed submission:
N,M = map(int,input().split())
*A, = map(int,input().split())
BC=[list(map(int,input().split())) for _ in [0]*M]
A.sort()
BC.sort(key=lambda x:-x[1])
i = 0
for B,C in BC:
    for j in range(i,min(N,i+B)):
        if A[j]<C:A[j]=C
    i = i+B
print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M =map(int,input().split())
cards = list(map(int,input().split()))
card_pool = [list(map(int,input().split())) for _ in range(M)]
cards.sort()
#print(cards)
card_pool.sort(key=lambda x:x[1],reverse=True)
#print(card_pool)


ruisekiwa = 0
idx = 0
for i in range(M):
    for j in range(card_pool[i][0]):
        if card_pool[i][1] <= cards[idx]:
            print(sum(cards[idx:]) + ruisekiwa)
            break
        ruisekiwa += card_pool[i][1]
        idx += 1
        if idx == N:
            print(ruisekiwa)
            break
#print(sum(cards[idx:])+ruisekiwa)

Buggy submission (verdict: Runtime Error):
N, M =map(int,input().split())
cards = list(map(int,input().split()))
card_pool = [list(map(int,input().split())) for _ in range(M)]
cards.sort()
#print(cards)
card_pool.sort(key=lambda x:x[1],reverse=True)
#print(card_pool)


ruisekiwa = 0
idx = 0
for i in range(M):
    for j in range(card_pool[i][0]):
        if card_pool[i][1] <= cards[idx]:
            break
        ruisekiwa += card_pool[i][1]
        idx += 1
        if idx == N-1:
            break
print(sum(cards[idx:])+ruisekiwa)

Buggy submission (verdict: Runtime Error):
N, M =map(int,input().split())
cards = list(map(int,input().split()))
card_pool = [list(map(int,input().split())) for _ in range(M)]
cards.sort()
#print(cards)
card_pool.sort(key=lambda x:x[1],reverse=True)
#print(card_pool)


ruisekiwa = 0
idx = 0
for i in range(M):
    for j in range(card_pool[i][0]):
        if card_pool[i][1] <= cards[idx]:
            break
        ruisekiwa += card_pool[i][1]
        idx += 1
        if idx == N:
            break
print(sum(cards[idx:])+ruisekiwa)

Buggy submission (verdict: Runtime Error):
N, M =map(int,input().split())
cards = list(map(int,input().split()))
card_pool = [list(map(int,input().split())) for _ in range(M)]
cards.sort()
#print(cards)
card_pool.sort(key=lambda x:x[1],reverse=True)
#print(card_pool)


ruisekiwa = 0
idx = 0
for i in range(M):
    for j in range(card_pool[i][0]):
        if card_pool[i][1] < cards[idx]:
            break
        ruisekiwa += card_pool[i][1]
        idx += 1
        if idx == N:
            break
print(sum(cards[idx:])+ruisekiwa)

Buggy submission (verdict: Runtime Error):
N, M =map(int,input().split())
cards = list(map(int,input().split()))
card_pool = [list(map(int,input().split())) for _ in range(M)]
cards.sort()
#print(cards)
card_pool.sort(key=lambda x:x[1],reverse=True)
#print(card_pool)


ruisekiwa = 0
idx = 0
for i in range(M):
    for j in range(card_pool[i][0]):
        if card_pool[i][1] < cards[idx]:
            break
        ruisekiwa += card_pool[i][1]
        idx += 1
print(sum(cards[idx:])+ruisekiwa)
Problem p03045 (python)

Fixed submission:
N,M = map(int,input().split())

par = [-1]*(N+1)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


def same(x,y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]

for i in range(M):
    x,y,z = map(int,input().split())
    unite(x,y)

ans = 0
counted = [False] * (N+1)
for i in range(1,N+1):
    root = find(i)
    if not counted[root]:
        ans += 1
        counted[root] = True
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
G = [[] for _ in range(N)]

for _ in range(M):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

seen = [False]*(N)
ans = 0
def dfs(v):
    if seen[v]:
        return
    seen[v] = True
    for nv in G[v]:
        dfs(nv)

for v in range(N):
    if not seen[v]:
        dfs(v)
        ans += 1
print(ans)
Problem p03326 (python)

Fixed submission:
import numpy as np
import itertools
N, M = map(int, input().split())
x = [0] * N
y = [0] * N
z = [0] * N
for i in range(N):
    x[i], y[i], z[i] = map(int, input().split())

x = np.array(x)
y = np.array(y)
z = np.array(z)

ans = 0
vals = []
for op1,op2,op3 in itertools.product([-1,1],repeat=3):
    #print(op1,op2,op3)
    s = x*op1 + y*op2 + z*op3
    #print(s)
    s.sort()
    vals.append(s[N-M:].sum())


print(max(vals))

Buggy submission (verdict: Runtime Error):
import numpy as np
import itertools
N, M = map(int, input().split())
x = [0] * N
y = [0] * N
z = [0] * N
for i in range(N):
    x[i], y[i], z[i] = map(int, input().split())

x = np.array(x)
y = np.array(y)
z = np.array(z)

ans = 0
vals = []
for op1,op2,op3 in itertools.product([-1,1],repeat=3):
    #print(op1,op2,op3)
    s = x*op1 + y*op2 + z*op3
    #print(s)
    s.sort()
    vals.append(s[-M:].sum())


print(max(vals))
Problem p03724 (python)

Fixed submission:
N, M = map(int,input().split())
freq = [True]*N
for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
freq = [True]*M
for i in range(N):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
freq = [True]*M
for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if freq[a]:
        freq[a] = False
    else:
        freq[a] = True

    if freq[b]:
        freq[b] = False
    else:
        freq[b] = True

ans = all(freq)
if ans:
    print('YES')
else:
    print('NO')
Problem p03806 (python)

Fixed submission:
N, ma, mb = map(int, input().split())
a = [0]*N
b = [0]*N
c = [0]*N
NMAX = 40
ABMAX = 10
INF = 1000000
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
dp = [[[INF]*(NMAX*ABMAX+1)for _ in range(NMAX*ABMAX+1)]for _ in range(N+1)]
dp[0][0][0] = 0
for i in range(N):
    for ca in range(NMAX*ABMAX+1):
        for cb in range(NMAX*ABMAX+1):
            if dp[i][ca][cb] == INF:
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]
                             ] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])
ans = INF
for ca in range(1, NMAX*ABMAX+1):
    for cb in range(1, NMAX*ABMAX+1):
        if ca * mb == cb * ma:
            ans = min(ans, dp[N][ca][cb])
print(ans if ans != INF else -1)

Buggy submission (verdict: Runtime Error):
N, ma, mb = map(int, input().split())
a = [0]*N
b = [0]*N
c = [0]*N
NMAX = 10
ABMAX = 10
INF = 100000
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
dp = [[[INF]*(NMAX*ABMAX+1)for _ in range(NMAX*ABMAX+1)]for _ in range(N+1)]
dp[0][0][0] = 0
for i in range(N):
    for ca in range(NMAX*ABMAX+1):
        for cb in range(NMAX*ABMAX+1):
            if dp[i][ca][cb] == INF:
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]
                             ] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])
ans = INF
for ca in range(1, NMAX*ABMAX+1):
    for cb in range(1, NMAX*ABMAX+1):
        if ca * mb == cb * ma:
            ans = min(ans, dp[N][ca][cb])
print(ans if ans != INF else -1)
Problem p02659 (python)

Fixed submission:
import math
A, B = input().split()
a = int(A)
b = int(float(B)*1000)
print(a*b//1000)

Buggy submission (verdict: Runtime Error):
import math
A, B = input().split()
a = int(A)
b = int(B*1000)
print(a*b//1000)
Problem p02835 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a + b + c >= 22:
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
a = map(int, input())
if sum(a) >= 22:
  print('bust')
else:
  print('win')
Problem p02726 (python)

Fixed submission:
N, X, Y = map(int, input().split())

ans = [0] * N

X -= 1
Y -= 1
for i in range(N):
    for j in range(i+1, N):
        distance = min(abs(i-j), abs(i-X) + 1 + abs(j-Y))
        ans[distance] += 1

for k in range(1, N):
    print(ans[k])

Buggy submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())

graph = [[False for _ in range(N)] for _ in range(N)]
for i in range(N-1):
    graph[i][i+1] = graph[i+1][i] = True
graph[X-1][Y-1] = graph[Y-1][X-1] = True

ans = [0] * N

def dfs(pos, goal, cnt, visited):
    ans = N
    for i in range(N):
        if not graph[pos][i]: continue
        if visited[i]: continue

        if i == goal:
            return cnt + 1

        visited[i] = True
        ret = dfs(i, goal, cnt + 1, visited)
        if ret is not None:
            ans = min(ans, ret)
        visited[i] = False

    if ans == N:
        return None
    else:
        return ans

visited = [False] * N
for i in range(N):
    for j in range(i+1, N):
        distance = dfs(i, j, 0, visited)
        if distance is not None:
            ans[distance] += 1

for k in range(1, N):
    print(ans[k])
Problem p02847 (python)

Fixed submission:
daw = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()
idx = daw.index(S)
print(7 - idx)

Buggy submission (verdict: Runtime Error):
daw = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()
ind = daw.index(S)
print(7 - idx)

Buggy submission (verdict: Runtime Error):
daw = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()
ind = daw.find(S)
print(7 - idx)

Buggy submission (verdict: Runtime Error):
daw = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()
ind = S.find(daw)
print(7 - idx)
Problem p02862 (python)

Fixed submission:
MOD = 10**9 + 7

def make_fac_tables_mod_p(n, p):
  fac = [0] * (n+1)
  fac_inv = [0] * (n+1)
  mod_inv = [0] * (n+1)
  fac[0] = fac[1] = 1
  fac_inv[0] = fac_inv[1] = 1
  mod_inv[1] = 1
  for i in range(2, n+1):
    fac[i] = (fac[i-1] * i) % p
    mod_inv[i] = p - mod_inv[p % i] * (p // i) % p
    fac_inv[i] = fac_inv[i-1] * mod_inv[i] % p
  return fac, fac_inv

def nCk_mod_p(fac, fac_inv, n, k, p):
  return ((fac[n] * fac_inv[n-k]) % p) * fac_inv[k] % p

X, Y = map(int, input().split())

ans = 0
q, r = divmod(X+Y, 3)
if r == 0 and (q <= X <= 2*q) and (q <= Y <= 2*q):
  n = q
  k = X - q
  fac, fac_inv = make_fac_tables_mod_p(n, MOD)
  ans = nCk_mod_p(fac, fac_inv, n, k, MOD)

print(ans)

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

def make_fac_tables_mod_p(n, p):
  fac = [0] * (n+1)
  fac_inv = [0] * (n+1)
  mod_inv = [0] * (n+1)
  fac[0] = fac[1] = 1
  fac_inv[0] = fac_inv[1] = 1
  mod_inv[1] = 1
  for i in range(2, n+1):
    fac[i] = (fac[i-1] * i) % p
    mod_inv[i] = p - mod_inv[p % i] * (p // i) % p
    fac_inv[i] = fac_inv[i-1] * mod_inv[i] % p
  return fac, fac_inv

def nCk_mod_p(fac, fac_inv, n, k, p):
  return ((fac[n] * fac_inv[n-k]) % p) * fac_inv[k] % p

X, Y = map(int, input().split())

ans = 0
q, r = divmod(X+Y, 3)
if r == 0:
  n = q
  k = X - q
  fac, fac_inv = make_fac_tables_mod_p(n, MOD)
  ans = nCk_mod_p(fac, fac_inv, n, k, MOD)

print(ans)
Problem p02987 (python)

Fixed submission:
S = input()
S = sorted(S)
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = input()
S = sorted(S)
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print("Yes")
else
  print("No")

Buggy submission (verdict: Runtime Error):
S = input()
S.sort()
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print("Yes")
else
  print("No")

Buggy submission (verdict: Runtime Error):
S = [i for i in input().strip().split()]
S.sort()
if (S[0] == S[1]) and (S[2] == S[3]) and (S[1] != S[2]):
  print("Yes")
else
  print("No")
Problem p03013 (python)

Fixed submission:
MOD = 10**9 + 7

N, M = [int(i) for i in input().strip().split()]
dirty_step_idxs = [0] * M
for i in range(M):
  dirty_step_idx = int(input())
  dirty_step_idxs[i] = dirty_step_idx

def fibonacci(n):
  # 0, 1, 1, 2, 3, 5, 8, ...
  a, b = 0, 1
  for i in range(n-1):
    a, b = b, a + b
  return a
  
if M == 0:
  res = fibonacci(N + 2)
else:
  res = 1
  now_step_idx = 0
  for i in range(M):
    n_step = dirty_step_idxs[i] - now_step_idx - 1
    if n_step == -1:
      res = 0
      break
    res *= fibonacci(n_step + 2)
    now_step_idx = dirty_step_idxs[i] + 1
  rest_steps = N - now_step_idx
  res *= fibonacci(rest_steps + 2) 
    
print(res % MOD)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    N, M = map(int, input().split())
    A = [0] * M
    for i in range(M):
        A[i] = int(input())

    is_ok = True
    for i in range(M - 1):
        if A[i] + 1 == A[i + 1]:
            is_ok = False
    if not is_ok:
        print(0)
        exit()

    broken = [False] * (N + 1)
    for a in A:
        broken[a] = True

    dp = [0] * (N + 1)
    dp[0] = 1
    dp[1] = 1 if A[0] != 1 else 0

    for i in range(2, N + 1):
        if broken[i]:
            dp[i] = 0
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % P
    
    ans = dp[N]
    print(ans)


if __name__ == "__main__":
    main()
Problem p03252 (python)

Fixed submission:
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()
    T = input().rstrip()

    S_table = {}
    T_table = {}
    ans = "Yes"
    for s, t in zip(S, T):
        # S
        if s in S_table:
            if S_table[s] != t:
                ans = "No"
        else:
            S_table[s] = t
        # T
        if t in T_table:
            if T_table[t] != s:
                ans = "No"
        else:
            T_table[t] = s

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

ans = "Yes"
s2t = {}
for s, t in zip([S, T]):
  if s == t:
    pass
  else:
    if s in s2t:
      if s2t[s] != t:
        ans = "No"
    else:
      s2t[s] = t

print(ans)
Problem p03724 (python)

Fixed submission:
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())

    cnt = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        cnt[a - 1] += 1
        cnt[b - 1] += 1

    ans = "YES"
    for c in cnt:
        if c % 2 != 0:
            ans = "NO"
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    count = [0] * (N + 1)
    for _ in range(N):
        a, b = map(int, input().split())
        count[a] += 1
        count[b] += 1

    if all(c % 2 == 0 for c in count):
        ans = "YES"
    else:
        ans = "NO"
    print(ans)


if __name__ == "__main__":
    main()
Problem p03805 (python)

Fixed submission:
import itertools

N, M = map(int, input().split())
ab = [0] * M
for i in range(M):
  ab[i] = list(map(int, input().split()))

perms = itertools.permutations(range(1, N+1))
ans = 0
for perm in perms:
  if perm[0] != 1:
    continue
  is_goal = True
  for i in range(N-1):
    a = perm[i]
    b = perm[i+1]
    if not a < b:
      a, b = b, a
    if not [a, b] in ab:
      is_goal = False
  if is_goal:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
# https://img.atcoder.jp/abc054/editorial.pdf

N, M = map(int, input().split())

graph = [[False for _ in range(N)] for i in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  graph[a-1][b-1] = graph[b-1][a-1] = True

def dfs(v, visited):
  all_visited = True
  for i in range(N):
    if not visited[i]:
      all_visited = False
      
  if all_visited:
    return 1
  
  ret = 0
  for i in range(N):
    if not graph[v][i]: continue
    if visited[i]: continue
    
    visited[i] = True
    ret += dfs(i, visited)
    visited[i] = False
  
  return ret

visited = [False] * N
visited[0] = True
ans = dfs(0, visited)
print(ans)