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

Fixed submission:
a = list(map(int, input().split()))
a.sort()
print(0+abs(a[1]-a[0])+abs(a[2]-a[1]))

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a.sort()
print(0+abs(a[2]-a[1])+abs(a[3]-a[2]))
Problem p03415 (python)

Fixed submission:
c1, c2, c3 = map(list,map(str, [input() for i in range(3)]))
print(c1[0]+c2[1]+c3[2])

Buggy submission (verdict: Runtime Error):
c1, c2, c3 = map(list,map(int, [input() for i in range(3)]))
print(c1[0]+c2[1]+c3[2])
Problem p03425 (python)

Fixed submission:
n = int(input())
march = ['M','A','R','C','H']
counter = [0]*5
for i in range(n):
	s = input()
	if s[0] in march:
		counter[march.index(s[0])] += 1

ans = 0
for i in range(3):
	for j in range(1+i,4):
		for k in range(1+j,5):
			ans += counter[i]*counter[j]*counter[k]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
march = ['M','A','R','C','H']
counter = [0]*5
for i in range(n):
	s = input()
	if s[0] in march:
		counter[march.index(s[0])] += 1

ans = 0

while 0 in counter:
	counter.pop(counter.index(0))

if len(counter) <= 2:
	ans = 0
elif len(counter) == 3:
	ans = counter[0]*counter[1]*counter[2]
elif len(counter) == 4:
	ans = counter[0]*counter[1]*counter[2] + counter[0]*counter[1]*counter[3] + counter[0]*counter[2]*counter[3] + counter[1]*counter[2]*counter[3]
elif len(counter) == 5:
	ans = counter[0]*counter[1]*counter[2] + counter[0]*counter[1]*counter[3] + counter[0]*counter[1]*counter[4] + counter[0]*counter[2]*counter[3] + counter[0]*counter[2]*counter[4] + counter[0]*counter[3]*counter[4] + counter[1]*counter[2]*counter[3] + counter[1]*counter[2]*counter[4] + counter[1]*counter[3]*counter[4] + counter[3]*counter[4]*counter[5]

print(ans)
Problem p03433 (python)

Fixed submission:
n = int(input())
a = int(input())
if n%500 <= a:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n,a = map(int, [input() for i range(2)])
if n%500 <= a:
  print('Yes')
else:
  print('No')
Problem p03485 (python)

Fixed submission:
import math
a,b = map(int,input().split())
print(math.ceil((a+b)/2))

Buggy submission (verdict: Runtime Error):
import math
a,b = int(input())
print(math.ceil(a+b/2))
Problem p03555 (python)

Fixed submission:
c1 = input()
c2 = input()
print('YES' if c1 == c2[::-1] else 'NO')

Buggy submission (verdict: Runtime Error):
#二分探索...ソートした配列を二つに分けて、どちらに入るか調べることで高速化
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

#リストを整列する
a.sort()
b.sort()
c.sort()

#二分探索で、それぞれのbについて、a<bになるaの個数を調べる
#二分探索で、それぞれのbについて、c>bになるcの個数を調べる
ans = 0
for i in range(n):
	ab = bisect.bisect_left(a,b[i])	#a==bの場合を除外する
	tmpbc = bisect.bisect_right(c,b[i])#b==cの場合を一度含んでおく
	bc = n-tmpbc
	
	ans += ab*bc
	
print(ans)
Problem p03597 (python)

Fixed submission:
n = int(input())
a = int(input())

print((n**2)-a)

Buggy submission (verdict: Runtime Error):

n = input()
a = input()

print(n**n-a)
Problem p02787 (python)

Fixed submission:
import math
import time


t = time.time()
def iip():
    return [int(i) for i in input().split()]

def main():
    H, N = iip()
    mp_for_damage = [10**9 for i in range(H+1)]
    mp_for_damage[0] = 0
    ab = []

    for i in range(N):
        ab.append(iip())

    ab= sorted(ab, key=lambda x:x[0]/x[1], reverse=True)

    for i in range(N):
        a, b = ab[i]

        for k in range(1, min(a, H) + 1):
            mp_for_damage[k] = min(mp_for_damage[k], b)
            # print(k, b)

        if a >= H:
            mp_for_damage[H] = min(mp_for_damage[H], b)
            continue

        if a < H and mp_for_damage[a] < b:
            continue

        for j in range(H-a+1):
            mp_for_damage[j+a] = min(mp_for_damage[j+a], mp_for_damage[j] + b)

    #print(mp_for_damage)
    #print(mp_for_damage)
    print(mp_for_damage[H])

    #print(time.time() - t)

main()

Buggy submission (verdict: Runtime Error):
import math
import time

t = time.time()
def iip():
    return [int(i) for i in input().split()]

H, N = iip()
mp_for_damage = [10**9 for i in range(H+1)]
mp_for_damage[0] = 0

for i in range(N):
    a, b = iip()
    for j in range(H+1):
        if mp_for_damage[a] < b:
            continue

        for k in range(1, a):
            if k > H:
                break
            mp_for_damage[k] = min(mp_for_damage[k], b)

        if j + a > H:
            break
        mp_for_damage[j+a] = min(mp_for_damage[j+a], mp_for_damage[j] + b)

#print(mp_for_damage)
print(mp_for_damage[H])

#print(time.time() - t)

Buggy submission (verdict: Runtime Error):
import math
import time

t = time.time()
def iip():
    return [int(i) for i in input().split()]

H, N = iip()
mp_for_damage = [10**9 for i in range(H+1)]
mp_for_damage[0] = 0

for i in range(N):
    a, b = iip()
    for j in range(H+1):
        for k in range(1, a):
            mp_for_damage[k] = min(mp_for_damage[k], b)

        if j + a > H:
            break
        mp_for_damage[j+a] = min(mp_for_damage[j+a], mp_for_damage[j] + b)

#print(mp_for_damage)
print(mp_for_damage[H])

#print(time.time() - t)
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)

inp = list(map(lambda x: int(x), input().split(" ")))
N = inp[0]
M = inp[1]

dp = [-1]*N

g = {}

def path(x):
    if dp[x-1]!=-1:
        return dp[x-1]
    if g[x] == []:
        return 0
    else:
        ret = 0
        for k in g[x]:
            if ret<path(k)+1:
                ret = path(k)+1
        dp[x-1] = ret
        return ret

for i in range(1,N+1):
    g[i] = []

for i in range(M):
    inp = list(map(lambda x: int(x), input().split(" ")))
    x = inp[0]
    y = inp[1]
    g[x].append(y)

ret = 0
for i in range(1,N+1):
    if ret<path(i):
        ret = path(i)

print(ret)

Buggy submission (verdict: Runtime Error):
inp = list(map(lambda x: int(x), input().split(" ")))
N = inp[0]
M = inp[1]

dp = [-1]*N

g = {}

def path(x):
    if dp[x-1]!=-1:
        return dp[x-1]
    if g[x] == []:
        return 0
    else:
        ret = 0
        for k in g[x]:
            if ret<path(k)+1:
                ret = path(k)+1
        dp[x-1] = ret
        return ret

for i in range(1,N+1):
    g[i] = []

for i in range(M):
    inp = list(map(lambda x: int(x), input().split(" ")))
    x = inp[0]
    y = inp[1]
    g[x].append(y)

ret = 0
for i in range(1,N+1):
    if ret<path(i):
        ret = path(i)

print(ret)
Problem p03125 (python)

Fixed submission:
A, B = map( int, input().split() )

if B % A == 0: print( A+B )
else: print( B-A )

Buggy submission (verdict: Runtime Error):
N, M = map( int, input().split() )
A = list( map( int, input().split() ) )


# 桁数の一番大きいものが最大。そのあと数を大きい順に並べればいい
dp = [0]*(N+1)       # dp[i]: i 本のマッチで条件を満たす整数の最大桁数
cost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]  # 各数字に必要なマッチ棒の数(逆順)

for num_match in range( 2, N+1 ):
    for Aj in A:
        if num_match >= cost[Aj]:
            dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )


# 求めた桁数 dp[N] を用いて順序を求める
ans = ""
digit = dp[N]

A.sort( reverse=True )
while N > 0:
    for Ai in A:
        if N-cost[Ai] >=0 and dp[N-cost[Ai]] == digit-1:
            ans += str(Ai)
            N -= cost[Ai]
            digit -= 1
            break

print( ans )
Problem p03128 (python)

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


# 桁数の一番大きいものが最大。そのあと数を大きい順に並べればいい
dp = [0] + [-float('inf')] * (N+1)       # dp[i]: i 本のマッチで条件を満たす整数の最大桁数
cost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]  # 各数字に必要なマッチ棒の数(逆順)

for num_match in range( 2, N+1 ):
    for Aj in A:
        if num_match >= cost[Aj]:
            dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )


ans = ""
digit = dp[N]

A.sort( reverse=True )
while N > 0:
    for Ai in A:
        if N-cost[Ai] >=0 and dp[N-cost[Ai]] == digit-1:
            ans += str(Ai)
            N -= cost[Ai]
            digit -= 1
            break

print( ans )

Buggy submission (verdict: Runtime Error):
N, M = map( int, input().split() )
A = list( map( int, input().split() ) )


# 桁数の一番大きいものが最大。そのあと数を大きい順に並べればいい
dp = [-float('inf')] * (N+1)             # dp[i]: i 本のマッチで条件を満たす整数の最大桁数
cost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]  # 各数字に必要なマッチ棒の数(逆順)

dp[0] = 0
for num_match in range( 2, N+1 ):
    for Aj in A:
        if num_match >= cost[Aj]:
            dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )

ans = ""
digit = dp[N]

A.sort( reverse=True )
while N > 0:
    for Ai in A:
        if dp[N-cost[Ai]] == digit-1 :
            ans += str(Ai)
            N -= cost[Ai]
            digit -= 1
            break

print( int(ans) )

Buggy submission (verdict: Runtime Error):
N, M = map( int, input().split() )
A = list( map( int, input().split() ) )


# 桁数の一番大きいものが最大。そのあと数を大きい順に並べればいい
dp = [-float('inf')] * (N+1)             # dp[i]: i 本のマッチで条件を満たす整数の最大桁数
cost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]  # 各数字に必要なマッチ棒の数(逆順)

dp[0] = 0
for num_match in range( 2, N+1 ):
    for Aj in A:
        if num_match >= cost[Aj]:
            dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )

ans = ""
digit = dp[N]

A.sort( reverse=True )
while N > 0:
    for Ai in A:
        if dp[N-cost[Ai]] == digit-1 :
            ans += str(Ai)
            N -= cost[Ai]
            digit -= 1
            break

print( ans )

Buggy submission (verdict: Runtime Error):
N, M = map( int, input().split() )
A = list( map( int, input().split() ) )


# 桁数の一番大きいものが最大。そのあと数を大きい順に並べればいい
dp = [-float('inf')] * (N+1)             # dp[i]: i 本のマッチで条件を満たす整数の最大桁数
cost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]  # 各数字に必要なマッチ棒の数(逆順)

dp[0] = 0
for num_match in range( 2, N+1 ):
    for Aj in A:
        if num_match >= cost[Aj]:
            dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )


print( dp )

ans = ""
digit = dp[N]

A.sort( reverse=True )
while N > 0:
    for Ai in A:
        if dp[N-cost[Ai]] == digit-1 :
            ans += str(Ai)
            N -= cost[Ai]
            digit -= 1
            break

print( ans )
Problem p03155 (python)

Fixed submission:
N = int( input() )
H = int( input() )
W = int( input() )

print( (N-H+1)*(N-W+1) )

Buggy submission (verdict: Runtime Error):
H, W = map( int, input().split() )
S = [ list( input() ) for _ in range(H) ]

isVisited = [ [False]*W for _ in range(H) ]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
# (x, y) から行けるペアの数
def dfs( x, y ):
    ans = 0
    isVisited[x][y] = True
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if S[x][y] == '#':
            if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
                if S[nx][ny] == '.': ans += dfs( nx, ny )+1
        else:
            if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
                if S[nx][ny] == '#': ans += dfs( nx, ny )+1
    return ans


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#' and not isVisited:
          ans += dfs( i, j )

print( ans )
Problem p03495 (python)

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

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

print( sum( numAppeared[i] for i in range(K,N) ) )

Buggy submission (verdict: Runtime Error):
N, K = map( int, input().split() )
A = list( map( int, input().split() ) )

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

# print( sum( numAppeared[i] for i in range(K,N) ) )
print( sum( numAppeared( range(K,N) ) ) )
Problem p03556 (python)

Fixed submission:
N = int( input() )

ans = 0
for i in range( int(N**0.5)+1 ):
    ans = max( ans, i*i )

print( ans )

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

for i in range( int(N**0.5)+1 ):
    ans = max( ans, i*i )

print( ans )
Problem p03633 (python)

Fixed submission:
import fractions
import functools

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

def lcm( x, y ):
    return x * y // fractions.gcd( x, y )

def lcm_list( numbers ):
    return functools.reduce( lcm, numbers, 1 )

if N == 1: print( T[0] )
else     : print( lcm_list(T) )

Buggy submission (verdict: Runtime Error):
N = int( input() )
T = [ int( input() ) for _ in range(N) ]


# 最小公倍数を求めたい
# aとbの最小公倍数 = a*b / aとbの最大公約数
# 最大公約数 (Greatest Common Divisor)
def GCD( a, b ):
    if b == 0: return a
    return GCD(b, a%b)

# 最小公倍数 (Least Common Multiple)
def LCM( a, b ):
    return a*b // GCD(a,b)


ans = LCM( T[0], T[1] )
for i in range(2,N): ans = LCM( ans, T[i] )
print( ans )

Buggy submission (verdict: Runtime Error):
N = int( input() )
T = [ int( input() ) for _ in range(N) ]


# 最小公倍数を求めたい
# aとbの最小公倍数 = a*b / aとbの最大公約数
# 最大公約数 (Greatest Common Divisor)
def GCD( a, b ):
    if b == 0: return a
    return GCD(b, a%b)

# 最小公倍数 (Least Common Multiple)
def LCM( a, b ):
    return a*b // GCD(a,b)


ans = LCM( T[0], T[1] )
for i in range(2,N): ans = LCM( ans, T[i] )
print( int(ans) )

Buggy submission (verdict: Runtime Error):
N = int( input() )
T = [ int( input() ) for _ in range(N) ]


# 最小公倍数を求めたい
# aとbの最小公倍数 = a*b / aとbの最大公約数
# 最大公約数 (Greatest Common Divisor)
def GCD( a, b ):
    if b == 0: return a
    return GCD(b, a%b)

# 最小公倍数 (Least Common Multiple)
def LCM( a, b ):
    return a*b / GCD(a,b)


ans = LCM( T[0], T[1] )
for i in range(2,N):
    ans = LCM( ans, T[i] )
print( int(ans) )

Buggy submission (verdict: Runtime Error):
N = int( input() )
T = [ int( input() ) for _ in range(N) ]


# 最小公倍数を求めたい
# aとbの最小公倍数 = a*b / aとbの最大公約数
# 最大公約数 (Greatest Common Divisor)
def GCD( a, b ):
    if b == 0: return a
    return GCD(b, a%b)

# 最小公倍数 (Least Common Multiple)
def LCM( a, b ):
    return a*b / GCD(a,b)


ans = LCM( T[0], T[1] )
for i in range(2,N):
    ans = LCM( ans, T[i] )
print( ans )

Buggy submission (verdict: Runtime Error):
import math
import functools

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

def lcm( x, y ):
    return x * y // math.gcd( x, y )

def lcm_list( numbers ):
    return functools.reduce( lcm, numbers, 1 )

if N == 1: print( T[0] )
else     : print( lcm_list(T) )
Problem p02995 (python)

Fixed submission:
def lcm(x, y):
    return (x * y) // gcd(x, y)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
A,B,C,D=map(int,input().split())
abc=B//C-A//C
abd=B//D-A//D
abcd=(B//(lcm(C,D)))-(A//(lcm(C,D)))
if A%C==0:
    abc+=1
if A%D==0:
    abd+=1
if A%(lcm(C,D))==0:
    abcd+=1



#print(B-A+1)
#print(abc,abd,abcd)
print(B-A+1-(abc+abd-abcd))

Buggy submission (verdict: Runtime Error):
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

import math
A,B,C,D=map(int,input().split())
abc=B//C-A//C
abd=B//D-A//D
abcd=(B//(lcm(C,D)))-(A//(lcm(C,D)))
if A%C==0:
    abc+=1
if A%D==0:
    abd+=1
if A%(lcm(C,D))==0:
    abcd+=1



#print(B-A+1)
#print(abc,abd,abcd)
print(B-A+1-(abc+abd-abcd))
Problem p03029 (python)

Fixed submission:
A,P=map(int,input().split())
ap=A*3+P
print(ap//2)

Buggy submission (verdict: Runtime Error):
A,P=map(int,input().split())
ap=A*3+P
print(ap//P)
Problem p03086 (python)

Fixed submission:
a=list(input())
count=0
kekka=[]
for i in range(len(a)):
    if a[i]=="A" or a[i]=="T" or a[i]=="C" or a[i]=="G":
        count+=1
    else:
        count=0
    kekka.append(count)
        
print(max(kekka))

Buggy submission (verdict: Runtime Error):
a=list(input())
count=0
kekka=[]
for i in range(len(a)):
    if a[i]=="A" or a[i]=="T" or a[i]=="C" or a[i]=="G":
        count+=1
    else:
        kekka.append(count)
        count=0
print(max(kekka))
Problem p03146 (python)

Fixed submission:
a=int(input())
count=1
if a==1:
  count+=3
elif a==2:
  count+=3
else:
  count+=1
  while a!=1:
    if a%2==0:
        a=a/2
        count+=1
    else:
        a=3*a+1
        count+=1
print(count)

Buggy submission (verdict: Runtime Error):
s=int(input())
if s==1 or s==4 or s==2:
    print(4)
else:
    count=1
    while s!=4:
        if s%2==0:
            s=s/2
            count+=1
        else:
            s=3*s+1
            count+=1
print(count+3)
Problem p03238 (python)

Fixed submission:
a=int(input())
if a==1:
     print("Hello World")
else:
     b=int(input())
     c=int(input())
     print(b+c)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
if a==1:
     print("Hello World")
else:
     print(b+c)
Problem p03243 (python)

Fixed submission:
N=int(input())
a=N%111
if a==0:
   print(N)
else:
  b=N//111
  c=b+1
  print(c*111)

Buggy submission (verdict: Runtime Error):
N=int(input)
a=N%111
if a==0:
   print(a*111)
else:
  b=N//111
  c=b+1
  print(c*111)
Problem p03493 (python)

Fixed submission:
a=input()
b=a.count("1")
print(b)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
a=str(a)
b=str(b)
c=str(c)
d=a.find("1")
e=b.find("1")
f=c.find("1")
if d+e+f=-3:
  print("0")
elif d+e+f=-2:
  print("1")
elif d+e+f=-1:
  print("2")
elif d+e+f=0:
  print("3")
Problem p02732 (python)

Fixed submission:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
cnts = Counter(a)

_sum = 0
for key,value in cnts.items():
    _sum +=  value*(value-1)//2

for ai in a:
    ans = _sum
    c = cnts[ai]
    ans -= c*(c-1)//2
    ans += (c-1)*(c-2)//2
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
cnts = Counter(a)

_sum = 0
for key,value in cnts.items():
    _sum +=  value*(value-1)//2

for ai in a:
    ans = _sum
    c = cnts.count(ai)
    ans -= c*(c-1)//2
    ans += (c-1)*(c-2)//2
    print(ans)
Problem p02850 (python)

Fixed submission:
from collections import deque

N = int(input())
edges = [[] for _ in range(N)]
edge_index = {}
ab = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N-1)]
for i, (a, b) in enumerate(ab):
    edges[a].append(b)
    edges[b].append(a)
    edge_index[(a, b)] = edge_index[(b, a)] = i
# print(edges)

max_degree = 0
root = 0
for i in range(N):
    if len(edges[i]) > max_degree:
        max_degree = len(edges[i])
        root = i

color = [-1]*(N-1)
visited = [False]*N
visited[root] = True

stack = deque()  # (vertex, color_index)
for i, to in enumerate(edges[root]):
    color[edge_index[(root, to)]] = i+1
    visited[to] = True
    stack.append((to, i+1))

while stack:
    v, v_col = stack.pop()
    color_condidate = 0
    for to in edges[v]:
        assert color_condidate <= max_degree, "hello"
        if visited[to]:
            continue
        visited[to] = True
        color_condidate += 1
        if color_condidate == v_col:
            color_condidate += 1
        idx = edge_index[(v, to)]
        color[idx] = color_condidate
        stack.append((to, color_condidate))

print(max_degree)
print(*color, sep='\n')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n-1)]

tree = {}
for i in ab:
    if tree.get(i[0],-1) == -1:
        tree[i[0]] = [i[1]]
    else:
        tree[i[0]].append(i[1])
    if tree.get(i[1],-1) == -1:
        tree[i[1]] = [i[0]]
    else:
        tree[i[1]].append(i[0])

def maxdegree(tree,n):
    a = 0
    for i in range(1,n+1):
        a = max(a,len(tree[i]))
    return a

print(maxdegree(tree,n))

abmap = [[-1]*(n+1) for i in range(n+1)]

def coloring(self_num,parent,used_color):
    global tree
    global abmap
    num = self_num
    color = 1
    nodes = tree[num]
    for i in nodes:
        if i == parent:
            continue
        else:
            if color == used_color:
                color += 1
            abmap[num][i] = color
            abmap[i][num] = color
            coloring(i,num,color)
            color += 1

coloring(1,0,0)

for i in ab:
    print(abmap[i[0]][i[1]])
Problem p02900 (python)

Fixed submission:
def factorize(a: int) -> dict:
    """素因数分解 O(sqrt(N))
    return 素因数のdict
    """
    ps = {}
    i = 2
    nokori = a
    while i*i <= nokori:
        if nokori % i == 0:
            cnt = 0
            while nokori % i == 0:
                cnt += 1
                nokori //= i
            ps[i] = cnt
        i += 1
    if nokori != 1:
        ps[nokori] = 1
    return ps


A, B = map(int, input().split())
factor_of_a = factorize(A).keys()
factor_of_b = factorize(B).keys()
ans = len(set(factor_of_a) & set(factor_of_b))
ans += 1  # 1も
print(ans)

Buggy submission (verdict: Runtime Error):
from math import sqrt


def sieve(n: int) -> list:
    """Sieve of Eratoshenes O(N loglog N)
    return the list of is_prime (0, n]
    """
    assert n >= 1, "don't input negative value"

    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            # 素数の倍数は合成数
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return is_prime


def getDivisor(a: int) -> set:
    divisors = []
    sqrt_A = int(sqrt(a))+1
    for i in range(1, sqrt_A):
        if a % i == 0:
            divisors.append(i)
            divisors.append(a//i)
    return set(divisors)


A, B = map(int, input().split())
cd = getDivisor(A) & getDivisor(B)
# print(cd)

prime_list = sieve(max(cd))
ans = 1  # 1
for cdi in cd:
    if prime_list[cdi]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from math import sqrt


def sieve(n: int) -> list:
    """Sieve of Eratoshenes O(N loglog N)
    return the list of is_prime (0, n]
    """
    assert n >= 1, "don't input negative value"

    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            # 素数の倍数は合成数
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return is_prime


def getDivisor(a: int) -> set:
    divisors = []
    sqrt_A = int(sqrt(a))+1
    for i in range(1, sqrt_A):
        if a % i == 0:
            divisors.append(i)
            divisors.append(a//i)
    return set(divisors)


A, B = map(int, input().split())
cd = getDivisor(A) & getDivisor(B)
# print(cd)

prime_list = sieve(max(cd))
ans = 1  # 1
for cdi in cd:
    if prime_list[cdi]:
        ans += 1
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**9)


def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

    cnt = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x

    visited = [False]*N
    visited[0] = True
    q = deque([0])
    while q:
        v = q.pop()
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            q.append(n)
    print(*cnt)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        edges[a].append(b)
        edges[b].append(a)

    cnt = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x

    visited = [False]*N
    visited[0] = True

    def dfs(v: int):
        nonlocal visited
        nonlocal cnt
        if all(visited):
            return
        for n in edges[v]:
            if visited[n]:
                continue
            visited[n] = True
            cnt[n] += cnt[v]
            dfs(n)
        return

    dfs(0)
    print(*cnt)


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

Fixed submission:
from itertools import combinations

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

MAX_K = (N-1)*(N-2)//2
if K > MAX_K:
    print(-1)
    exit()

M = N-1 + (MAX_K - K)
print(M)
edges = list(combinations(range(1, N+1), 2))[:M]
# print(edges)
for e in edges:
    print(*e)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N,K = map(int, input().split())
MAX_K = (N-1)*(N-2)//2
if K > MAX_K:
    print(-1);exit()
M = N-1 + MAX_K-K
print(M)
for e in combinations(range(1, N+1), 2))[:M]:
    print(*e)