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

Fixed submission:
# 写経
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, u, v = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

graph = [[] for _ in range(n + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


def dfs(v):
    dist = [-1] * (n + 1)
    # 初期化
    stack = [v]
    # 初期位置を記憶
    dist[v] = 0
    # 初期位置の距離を0に
    while stack:
        # stackの中身がなくなるまで頑張る
        v = stack.pop()
        # stackから1つ要素を取り出す
        dw = dist[v] + 1
        # その要素の周りを考えるので、距離としてはその要素の距離に1を加えたものを考える
        for w in graph[v]:
            # 考えている要素に対して隣接している点に対して
            if dist[w] >= 0:
                # もし今まで訪れたことがあったら無視
                continue
            dist[w] = dw
            # 訪れたことがなかったら距離を更新
            stack.append(w)
            # 訪れたことがないところだったらstackに訪れる点リストとして保存
    return dist


answer = 0
du, dv = dfs(u), dfs(v)
for u, v in zip(du[1:], dv[1:]):
    if v - u > 0:
        x = v - 1
        if answer < x:
            answer = x
print(answer)

Buggy submission (verdict: Runtime Error):
# nlognの実装。駄目。
import numpy as np
from scipy.sparse.csgraph import dijkstra


def calc(d):
    if d == 1 or d == 0:
        return 0
    else:
        return int(d - 1)


delta = []
n, u, v = map(int, input().split())
Gn = np.full((n, n), float("inf"))
for i in range(n - 1):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    Gn[a][b] = 1
    Gn[b][a] = 1
    Gn[i][i] = 0
minimum_u = dijkstra(Gn, indices=u - 1)
minimum_v = dijkstra(Gn, indices=v - 1)
for i in range(n):
    if minimum_v[i] - minimum_u[i] > 0 and i != u - 1 and i != v - 1:
        delta.append([i, minimum_v[i]])
if delta != []:
    delta_sorted = sorted(delta, key=lambda x: x[1])
    p = delta_sorted[-1][0]
    d = int(minimum_v[p])
    print(calc(d))
else:
    print(calc(minimum_u[v - 1]))

Buggy submission (verdict: Runtime Error):
# nlognの実装。駄目。
import numpy as np
from scipy.sparse.csgraph import dijkstra

inf = 10 ** 9


def calc(d):
    if d == 1 or d == 0:
        return 0
    else:
        return int(d - 1)


delta = []
n, u, v = map(int, input().split())
Gn = np.full((n, n), inf)
for i in range(n - 1):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    Gn[a][b] = 1
    Gn[b][a] = 1
    Gn[i][i] = 0
minimum_u = dijkstra(Gn, indices=u - 1)
minimum_v = dijkstra(Gn, indices=v - 1)
for i in range(n):
    if minimum_v[i] - minimum_u[i] > 0 and i != u - 1 and i != v - 1:
        delta.append([i, minimum_v[i]])
if delta != []:
    delta_sorted = sorted(delta, key=lambda x: x[1])
    p = delta_sorted[-1][0]
    d = int(minimum_v[p])
    print(calc(d))
else:
    print(calc(minimum_u[v - 1]))
Problem p02912 (python)

Fixed submission:
n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if Ld==deque([]):
        if Ad==deque([]):
            break
        else:
            if Ad[-1]!=0:
                x=Ad.pop()//2
                if x>=Ad[-1]:
                    Ad.append(x)
                else:
                    Ad.insert(0,x)
            else:
                break
    else:
        if Ld[-1] >=Ad[-1]:
            x=Ld.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
        else:
            x=Ad.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
print(sum(list(Ld))+sum(list(Ad)))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if Ld==deque([]):
        if Ad==deque([]):
            break
        else:
            if Ad[-1]!=0:
                x=Ad.pop()//2
                if x>=Ad[-1]:
                    Ad.append(x)
                else:
                    Ad.insert(0,x)
            else:
                break
    else:
        if Ld[-1] >=Ad[-1]:
            x=Ld.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
        else:
            x=Ad.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
print(sum(list(Ld))+sum(list(Ad)))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if L[-1] >=A[-1]:
        x=L.pop()//2
        if x>=A[-1]:
            A.append(x)
        else:
            A.insert(0,x)
    else:
        x=A.pop()//2
        if x>=A[-1]:
            A.append(x)
        else:
            A.insert(0,x)
print(sum(L)+sum(A))
Problem p02959 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<remain:
        ans1+=B[i]
        remain=A[i+1]
    else:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
print(ans1)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<=remain:
        ans1+=B[i]
        remain=A[i+1]
    if B[i]>remain:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
rA=reversed(A)
rB=reversed(B)
remain=rA[0]
ans2=0
for i in range(n):
    if rB[i]<=remain:
        ans2+=rB[i]
        remain=rA[i+1]
    if rB[i]>remain:
        ans2+=remain
        yoryoku=rB[i]-remain
        if yoryoku>rA[i+1]:
            ans2+=rA[i+1]
            remain=0
        else:
            ans2+=yoryoku
            remain=rA[i+1]-yoryoku
print(max(ans1,ans2))
Problem p03011 (python)

Fixed submission:
a,b,c=map(int,input().split())
A=[a,b,c]
print(sum(A)-max(A))

Buggy submission (verdict: Runtime Error):
p, q, r = map(int, input().split())
print(sum(p, q, r) - max(p, q, r))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
A=list(a,b,c)
print(sum(A)-max(A))
Problem p03045 (python)

Fixed submission:
# union-findで行けそう。

n, m = map(int, input().split())
par = [-1] * (n + 1)


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


def unite(a, b):
    a = find(a)
    b = find(b)
    if a == b:
        return False
    else:
        if par[a] < par[b]:
            a, b = b, a
        par[a] += par[b]
        par[b] = a
        return True


for i in range(m):
    x, y, z = map(int, input().split())
    unite(x, y)
cnt = 0
for i in range(n):
    if par[i + 1] < 0:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
# union-findで行けそう。

n, m = map(int, input().split())
par = [-1] * (n + 1)


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


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


for i in range(m):
    x, y, z = map(int, input().split())
    unite(x, y)
cnt = 0
for i in range(n):
    if par[i + 1] < 0:
        cnt += 1
print(cnt)
Problem p03077 (python)

Fixed submission:
import math
n=int(input())
A=[int(input()) for i in range(5)]
m=min(A)
print(math.ceil(n/m)+4)

Buggy submission (verdict: Runtime Error):
N,*A=map(int,input().split())
print(max((N//min(A)+4),5))
Problem p03107 (python)

Fixed submission:
s=input()
ans=[]
for i in s:
    if ans==[]:
        ans.append(i)
    elif ans[-1]!=i:
        ans.pop()
    else:
        ans.append(i)
print(len(s)-len(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque
s=input()
d=deque(s)
ans=deque([])
ans.append(d[0])
c=0
for i in range(len(s)):
    if ans==[]:
        ans.append(d[i])
    elif ans[-1]==d[i]:
        ans.append(d[i])
    else:
        ans.pop()
        c+=2
print(c)
Problem p03209 (python)

Fixed submission:
n,x=map(int,input().split())
len_l=[0]*(n+1)
len_l[0]=1
num_p=[0]*(n+1)
num_p[0]=1
for i in range(n):
    len_l[i+1]=3+2*len_l[i]
    num_p[i+1]=2*num_p[i]+1
def calc(a,b):
    if a==0:
        return 1
    if b<=0:
        return 0
    else:
        nagasa=len_l[a]
        if b==1:
            return 0
        elif b<=len_l[a-1]+1:
            return calc(a-1,b-1)
        elif b==len_l[a-1]+2:
            return num_p[a-1]+1
        elif b<=2*len_l[a-1]+2:
            return num_p[a-1]+1+calc(a-1, b-(len_l[a-1]+2))
        elif b==2*len_l[a-1]+3:
            return 2*num_p[a-1]+1
        else:
            print('okasi')
            return None
print(calc(n,x))

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
L=['']*51
L[0]='P'
for i in range(n+1):
    L[i+1]='B'+L[i]+'P'+L[i]+'B'
print(L[n][0:x].count('P'))
Problem p03806 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401-a):
        for k in range(401-b):
            ni=i+1
            nj=j+a
            nk=k+b
            dp[ni][j][k]=min(dp[ni][j][k], dp[i][j][k])
            dp[ni][nj][nk]=min(dp[i][j][k]+c,dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>400:
        break
    if mb*i>400:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401-a):
        for k in range(401-b):
            ni=i+1
            dp[ni][j][k]=min(dp[ni][j][k], dp[i][j][k])
            dp[ni][nj][nk]=min(dp[i][j][k]+c,dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>400:
        break
    if mb*i>400:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)

Buggy submission (verdict: Runtime Error):
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401):
        for k in range(401):
            ni=i+1
            nj=j+a
            nk=k+b
            dp[ni][nj][nk]=min(dp[ni][nj][nk], dp[i][j][k])
            if nj>400:
                continue
            if nk>400:
                continue
            dp[ni][nj][nk]=min(dp[i][j][k]+c, dp[i][nj][nk], dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>100:
        break
    if mb*i>100:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)
Problem p02753 (python)

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

Buggy submission (verdict: Runtime Error):
str=imput()
if(str[0]!=atr[1]||str[1]!=str[2]):
  print("Yes")
else:
  print("No")
Problem p03634 (python)

Fixed submission:
N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    G[a].append([b,c])
    G[b].append([a,c])
Q,K=map(int,input().split())
K-=1
dist=[-1 for _ in range(N)]
dist[K]=0
q=[K]
while len(q)>0:
    v=q.pop()
    for p in G[v]:
        nv=p[0]
        if dist[nv]!=-1:
            continue
        dist[nv]=dist[v]+p[1]
        q.append(nv)
for _ in range(Q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])

Buggy submission (verdict: Runtime Error):
N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    G[a].append([b,c])
    G[b].append([a,c])
Q,K=map(int,input().split())
K-=1
dist=[-1 for _ in range(N)]
dist[K]=0
def dfs(G,x,dist):
    for p in G[x]:
        if dist[p[0]]!=-1:
            continue
        dist[p[0]]=dist[x]+p[1]
        dfs(G,p[0],dist)

dfs(G,K,dist)
for _ in range(Q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])
Problem p02880 (python)

Fixed submission:
n = int(input())
for a in range(1, 10):
    for b in range(1, 10):
        if n == a * b:
            print('Yes')
            exit()
print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
for a in range(1, 10):
    for b in range(1, 10):
        if n == a * b:
            print('Yes')
            return
print('No')
Problem p02897 (python)

Fixed submission:
import math
n = int(input())
print(math.ceil(n / 2) / n)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(math.ceil(n / 2) / n)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(ceil(n / 2) / n)
Problem p02951 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(max(c - (a - b), 0))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(max(c - (a - b)), 0)
Problem p02557 (python)

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))


    C = [0] * (N+1)
    D = [0] * (N+1)
    for i in range(N):
        C[A[i]] += 1
        D[B[i]] += 1
    for i in range(N+1):
        if C[i] + D[i] > N:
            print("No")
            return
    for i in range(N):
        C[i+1] += C[i]
        D[i+1] += D[i]
    
    x = 0
    for i in range(1, N+1):
        if x < C[i] - D[i-1]:
            x = C[i] - D[i-1]
    

    print("Yes")
    for i in range(N):
        if i != 0:
            print(" ", end="")
        print(B[(i+N-x)%N], end="")
    print("")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))


    C = [0] * N
    D = [0] * N
    for i in range(N):
        C[A[i]-1] += 1
        D[A[i]-1] += 1
    for i in range(N-1):
        C[i+1] += C[i]
        D[i+1] += D[i]
    
    s = -INF
    for i in range(1,N):
        if s < C[i] - D[i-1]:
            s = C[i] - D[i-1]
    
    ans = " ".join(map(str, B[s+1:] + B[:s+1]))
    print(ans)


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

Fixed submission:
from operator import mul
from functools import reduce
import sys
input = sys.stdin.readline


def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

    for i in range(1, K+1):
        # a: 青いボールを i グループに分割する組合せ
        a = cmb(K-1, i-1)
        # b: 各グループを赤いボールの間(端もOK)に挿入する組合せ
        b = cmb(N-K+1, i)

        print(a*b % 1000000007)

 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
import sys
input = sys.stdin.readline


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

    for i in range(1, K+1):
        # a: 青いボールを i グループに分割する組合せ
        a = cmb(K-1, i-1)
        # b: 各グループを赤いボールの間(端もOK)に挿入する組合せ
        b = cmb(N-K+1, i)

        print(a*b % 1000000007)

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

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

	dp = [0]*(N+1)
	for _ in range(M):
		a = int(input())
		dp[a] = -1

	dp[0] = 1
	if dp[1]==-1:
		dp[1] = 0
	else:
		dp[1] = 1

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

	print(dp[N]%1000000007)

solve()

Buggy submission (verdict: Runtime Error):
def fib(n):
	if n<0:
		return 0
	if n in [0, 1]:
		return 1
	return fib(n-1) + fib(n-2)

N, M = map(int, input().split())
if M==0:
	ans = fib(N)
else:
	A = [int(input()) for _ in range(M)]
	A.append(N+1)
	ans = fib(A[0]-1)
	for i in range(M):
		ans = ans * fib(A[i+1]-A[i]-2)

print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
def fib(n):
	if n<0:
		return 0
	if n in [0, 1]:
		return 1
	return fib(n-1) + fib(n-2)

N, M = map(int, input().split())
if M==0:
	ans = fib(N)
else:
	A = [int(input()) for _ in range(M)]
	A.append(N+1)
	ans = fib(A[0]-1)
	for i in range(M):
		ans = ans * fib(A[i+1]-A[i]-2)

print(ans%1000000007)
Problem p03045 (python)

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


def dfs(v, visited, G):
    visited[v] = True
    for nv in G[v]:
        if visited[nv]==False:
            dfs(nv, visited, G)


def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        x, y, z = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    
    nodes = list(range(N))
    visited = [False]*N
    ans = 0
    while len(nodes)!=0:
        v = nodes.pop()
        if visited[v]==True:
            continue
        ans += 1
        dfs(v, visited, G)
        # print(visited)
        # print(nodes)
    
    print(ans)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import heapq
import sys
input = sys.stdin.readline


def dfs(v, visited, G):
    visited[v] = True
    for nv in G[v]:
        if visited[nv]==False:
            dfs(nv, visited, G)


def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        x, y, z = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    
    nodes = list(range(N))
    visited = [False]*N
    ans = 0
    while len(nodes)!=0:
        v = nodes.pop()
        if visited[v]==True:
            continue
        ans += 1
        dfs(v, visited, G)
        # print(visited)
        # print(nodes)
    
    print(ans)



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

Fixed submission:
N = int(input())
if N<=999:
	print('ABC')
else:
	print('ABD')

Buggy submission (verdict: Runtime Error):
N = int(input())
if N<=999:
	print('ABC'
else:
	print('ABD')
Problem p03634 (python)

Fixed submission:
import heapq
import sys
input = sys.stdin.readline


def dijkstra_heap(s, n, edge):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d


def main():
    N = int(input())

    edge = [[] for i in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append([c,b])
        edge[b].append([c,a])
    
    Q, K = map(int, input().split())
    K -= 1
    D = dijkstra_heap(K, N, edge)

    for _ in range(Q):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        print(D[x]+D[y])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def dfs(v, d):
	global D
	D[v] = d
	for u,dd in G[v]:
		if D[u] is not None:
			continue
		dfs(u, d+dd)

N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
	a, b, c = map(int, input().split())
	G[a].append([b, c])
	G[b].append([a, c])

Q, K = map(int, input().split())
D = [None]*(N+1)
dfs(K, 0)
for _ in range(Q):
	x, y = map(int, input().split())
	print(D[x] + D[y])

Buggy submission (verdict: Runtime Error):
def dfs(v, p, d):
	global D
	global S
	D[v-1] = d
	for g in G[v-1]:
		if S[g[0]-1]==0:
			continue
		S[g[0]-1] = 0
		dfs(g[0], v, d+g[1])

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
	a, b, c = map(int, input().split())
	G[a-1].append([b, c])
	G[b-1].append([a, c])

S = [-1]*N
Q, K = map(int, input().split())
S[K-1] = 0
D = [0]*N
dfs(K, -1, 0)
for _ in range(Q):
	x, y = map(int, input().split())
	print(D[x-1] + D[y-1])

Buggy submission (verdict: Runtime Error):
def dfs(v, p, d):
	global D
	global G
	D[v-1] = d
	while G[v-1]!=[]:
		g = G[v-1].pop()
		if g[0]==p:
			continue
		dfs(g[0], v, d+g[1])

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
	a, b, c = map(int, input().split())
	G[a-1].append([b, c])
	G[b-1].append([a, c])

Q, K = map(int, input().split())
D = [0]*N
dfs(K, -1, 0)
for _ in range(Q):
	x, y = map(int, input().split())
	print(D[x-1] + D[y-1])
Problem p03803 (python)

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

if A==1:
	if A==B:
		print('Draw')
	else:
		print('Alice')
elif B==1:
	print('Bob')
else:
	if A==B:
		print('Draw')
	elif A>B:
		print('Alice')
	else:
		print('Bob')

Buggy submission (verdict: Runtime Error):
A, B = int(input())

if A==B:
	print('Draw')
elif A>B or A==1:
	print('Alice')
else:
	print('Bob')
Problem p02580 (python)

Fixed submission:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * H
w = [0] * W
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    item_h -= 1
    item_w -= 1
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

h_max = max(h)
w_max = max(w)
h_cnt = h.count(h_max)
w_cnt = w.count(w_max)
ans = h_max + w_max

cnt = 0
for item in item_list:
    if h[item[0]] == h_max and w[item[1]] == w_max:
        cnt += 1

x = h_cnt * w_cnt
if cnt == x:
    ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * (H * W)
w = [0] * (H * W)
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

ans = max(h) + max(w)
d =[h.index(max(h)), w.index(max(w))]
if d in item_list:
    ans -= 1


print(ans)