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

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,(cost + j[1])%2 )
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,(cost + j[1])%2 )
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost%2 == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,cost + j[1])
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])
Problem p03076 (python)

Fixed submission:
lis = []
for _ in range(5):
  lis.append(int(input()))
mod = []
for i in lis:
  mod.append(i%10)
if mod == [0,0,0,0,0]:
  print(sum(lis))
else:
  k = min(mod) if min(mod) != 0 else sorted(set(mod))[1]
  ans = 0
  for i in range(5):
    if i == mod.index(k):
      ans += lis[i]
    else:
      ans += ((lis[i]+9)//10)*10
  print(ans)

Buggy submission (verdict: Runtime Error):
lis = []
for _ in range(5):
  lis.append(int(input()))
mod = []
for i in lis:
  mod.append(i%10)
k = min(mod) if min(mod) != 0 else sorted(set(mod))[1]
ans = 0
for i in range(5):
  if i == mod.index(k):
    ans += lis[i]
  else:
    ans += ((lis[i]+9)//10)*10
print(ans)
Problem p03085 (python)

Fixed submission:
b = input()
b_dic = {"A":"T","T":"A","C":"G","G":"C"}
print(b_dic[b])

Buggy submission (verdict: Runtime Error):
b = input()
b_dic = {"A":"T","T":"A","C":"G","G":"c"}
print(b-dic[b])
Problem p03086 (python)

Fixed submission:
s = input()
cnt = [0]*(len(s))
for i in range(len(s)):
  for j in range(i,len(s)):
    if s[j] in ["A","C","G","T"]:
      cnt[i] += 1
    else:
      break

print(max(cnt))

Buggy submission (verdict: Runtime Error):
S = input()
atcg = ["A","T","C","G"]
num_lis =[]
for idx,s in enumerate(S):
  if s in atcg:
    num_lis.append(idx)

ans_lis =[]
x = 0

for i in range(len(S)):
  if i in num_lis:
    x += 1
  else:
    ans_lis.append(x)
    x = 0
    
print(max(ans_lis))
Problem p03103 (python)

Fixed submission:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
  while ab[i][1] > 0 and m> 0:
    m -= 1
    ab[i][1] -= 1
    ans += ab[i][0]
    
print(ans)

Buggy submission (verdict: Runtime Error):
zn,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
  while ab[i][1] > 0 and m> 0:
    m -= 1
    ab[i][1] -= 1
    ans += ab[i][0]
    
print(ans)
Problem p03210 (python)

Fixed submission:
x = int(input())
if x in [3,5,7]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
x - int(input())
if x in [3,5,7]:
  print('YES')
else:
  print('NO')
Problem p03238 (python)

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

Buggy submission (verdict: Runtime Error):
import math

n,m = map(int,input().split())
m_div = []
for i in range(1,math.ceil(math.sqrt(m)+1)):
  if m%i ==0:
    m_div.extend([i,m//i])
m_div = list(set(m_div))
m_div.sort(reverse = True)
for div in m_div:
  if div >= n:
    ans = m//div
  else:
    break
print(ans)
Problem p03424 (python)

Fixed submission:
input()
n = len(set(input().split()))
print("Three" if n == 3 else "Four")

Buggy submission (verdict: Runtime Error):
input()
print(len(set([input().split()]))
Problem p03469 (python)

Fixed submission:
s = input()
print("2018"+s[4:])

Buggy submission (verdict: Runtime Error):
s = input()
s[3] = '8'
print(s)
Problem p03477 (python)

Fixed submission:
W = list(map(int,input().split()))
if sum(W[:2]) < sum(W[2:]):
  print("Right")
elif sum(W[:2]) > sum(W[2:]):
  print("Left")
else:
  print("Balanced")

Buggy submission (verdict: Runtime Error):
W = map(int,input().split())
if sum(W[:2]) < sum(W[2:]):
  print("Right")
elif sum(W[:2]) > sum(W[2:]):
  print("Left")
else:
  print("Balanced")
Problem p03501 (python)

Fixed submission:
n,a,b = map(int,input().split())
print(min(n*a,b))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
print(min(n＊a,b))
Problem p03588 (python)

Fixed submission:
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)]))

Buggy submission (verdict: Runtime Error):
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)])

Buggy submission (verdict: Runtime Error):
N = int(input())
print(min(sum(list(map(int,input().split())))))

Buggy submission (verdict: Runtime Error):
N = int(input())
print(min(sum(*map(int,input().split()))))

Buggy submission (verdict: Runtime Error):
N = int(input())
print(min(sum(map(int,input().split()))))
Problem p03591 (python)

Fixed submission:
S = input()
if(len(S) >= 4 and S[:4] == "YAKI"):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S = input()
if(len(S) >= 4 and A[:4] == "YAKI"):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S = input()
if(A[:4] == "YAKI"):
    print("Yes")
else:
    print("No")
Problem p03759 (python)

Fixed submission:
a,b,c = map(int,input().split())
if b-a == c-b:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input())
if b-a == c-b:
  print("YeS")
else:
  print("NO")
Problem p03840 (python)

Fixed submission:
A = [int(i) for i in input().split()]
B = [A[1],A[0],A[3],A[4]]
ans = 0
ans += B[0]
if min(B[1:]) == 0:
	for b in B[1:]:
		ans += b//2*2
elif not sum([i%2 for i in B[1:]])%3:
	ans += sum(B[1:])
else:
	ans += sum(B[1:])-1
print(ans)

Buggy submission (verdict: Runtime Error):
A = [int(i) for i in input().split()]

ans = 0
ans += B[0]
if min(B[1:]) == 0:
	for b in B[1:]:
		if b%2 == 0:
			ans += 2
elif not sum([i%2 for i in B[1:]])%3:
	ans += sum(B[1:])
else:
	ans += sum(B[1:])-1
print(ans)
Problem p03864 (python)

Fixed submission:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
	if a[i] + a[i+1] > x:
		d = a[i] + a[i+1] - x
		if d <= a[i+1]:
			a[i+1] -= d
			ans += d
		else:
			a[i] -= d - a[i+1]
			a[i+1] = 0
			ans += d
print(ans)

Buggy submission (verdict: Runtime Error):
from math import hypot
def dijkstra(matrix):
    from heapq import heappush, heappop
    n = len(matrix)
    inf = 10**10
    hq = []
    ans = [inf]*n
    ans[0] = 0
    heappush(hq, (0, 0))
    while hq:
        d, p = heappop(hq)
        for i in range(n):
            if ans[p] == d and p != i and d + matrix[p][i] < ans[i]:
                ans[i] = d + matrix[p][i]
                heappush(hq, (ans[i], i))
    return ans[n-1]

x_s, y_s, x_t, y_t = map(int, input().split())
N = int(input())
xyr = [(x_s,y_s,0)]
for i in range(N):
    xyr.append(tuple(int(i) for i in input().split()))
xyr.append((x_t,y_t,0))
graph = [[0]*(N+2) for j in range(N+2)]

for i in range(N+2):
    for j in range(i,N+2):
        graph[i][j] = max(hypot((xyr[i][1]-xyr[j][1]), (xyr[i][0]-xyr[j][0])) - xyr[i][2] - xyr[j][2], 0)
        graph[j][i] = graph[i][j]

print(dijkstra(graph))

Buggy submission (verdict: Runtime Error):
from math import sqrt
inf = 10**10
x_s, y_s, x_t, y_t = map(int, input().split())
N = int(input())
xyr = []
for i in range(N):
	x_i, y_i, r_i = map(int, input().split())
	xyr.append((x_i, y_i, r_i))
p = (x_s, y_s)
goal = (x_t, y_t)
ans = 0
while p != goal and xyr:
	D = inf
	for i in range(N):
		x, y, r = xyr[i]
		d = sqrt((x-p[0])**2+(y-p[1])**2) - 2*r
		if d < D:
			j = i
			D = d
	d = sqrt((goal[0]-p[0])**2+(goal[1]-p[1])**2)
	if d < D:
		ans += d
		p = goal
	else:
		x, y, r = xyr.pop(j)
		p = (x, y)
		N -= 1
		ans += D

if p != goal:
	d = sqrt((goal[0]-p[0])**2+(goal[1]-p[1])**2)
	ans += d

print(max(0, ans))
Problem p03937 (python)

Fixed submission:
h, w = map(int, input().split())
ans = 0
for i in range(h):
	a = input()
	ans += a.count("#")
if ans == h + w - 1:
	print("Possible")
else:
	print("Impossible")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
ans = 0
for i in range(h):
	a = imput()
	ans += a.count("#")
if ans == h + w - 1:
	print("Possible")
else:
	print("Impossible")
Problem p03943 (python)

Fixed submission:
a, b, c = [int(i) for i in input().split()]
if(max([a,b,c])*2 == sum([a,b,c])):
 print("Yes")
else:
 print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]
if(max(a,b,c)*2 == sum(a,b,c)):
 print("Yes")
else:
 print("No")
Problem p03962 (python)

Fixed submission:
print(len(set([int(i) for i in input().split()])))

Buggy submission (verdict: Runtime Error):
print(len(set([int(i) in input().split()])))
Problem p03995 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

R, C = map(int, input().split())
N = int(input())
VectorSet = set()
Grid = defaultdict(list)
for i in range(N):
	r, c, a = map(int, input().split())
	Grid[("R", r)].append((("C", c), a))
	Grid[("C", c)].append((("R", r), a))
	VectorSet.add(("R", r))
	VectorSet.add(("C", c))

def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if (temp != VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v)

while VectorSet:
	vector = VectorSet.pop()
	VectorCover = dict()
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
	if minR + minC < 0:
		print("No")
		exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

R, C = map(int, input().split())
N = int(input())
r = []
c = []
a = []
for i in range(N):
	ri, ci, ai = map(int, input().split())
    	r.append(ri)
    	c.append(ci)
    	a.append(ai)
x = {}
y = {}
     
for i in range(N):
  	if r[i] in x:
   		if c[i] in y:
   			if x[r[i]] + y[c[i]] != a[i]:
   				print("No")
   				break
  		else:
   			y[c[i]] = a[i] - x[r[i]]
   	else:
   		if c[i] in y:
   			x[r[i]] = a[i] - y[c[i]]
   		else:
   			x[r[i]] = a[i]
   			y[c[i]] = 0
    
else:
   	if min(y.values()) + min(x.values()) >= 0:
   		print("Yes")
   	else:
   		print("No")
Problem p04035 (python)

Fixed submission:
N, L = map(int, input().split())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(N-1):
	if a[i] + a[i+1] >= L:
		print("Possible")
		b = 1
		c = i
		break
else:
	print("Impossible")
if b == 1:
	for i in range(1,c+1):
		print(i)
	for i in range(N-1, c, -1):
		print(i)

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
a = [map(int, input().split())]
b = 0
c = 0
for i in range(N-1):
	if a[i] + a[i+1] >= L:
		print("Possible")
		b = 1
		c = i
		break
else:
	print("Impossible")
if b = 1:
	for i in range(c+1):
		print(i+1)
	for i in range(N, c+1, -1):
		print(i+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
x = []
y = []
for i in range(1,M+1):
	z = list(map(int,input().split()))
	x.append(z[0])
	y.append(z[1])
a = [0]
b = [1]*N
for i in range(M):
	b[x[i]-1] -= 1
	b[y[i]-1] += 1
	if x[i]-1 in a:
		a.append(y[i]-1)
		if b[x[i]-1] == 0:
			a.remove(x[i]-1)
c = 0
for i in range(len(a)):
	if b[a[i]] != 0:
		c += 1
print(c)
Problem p03547 (python)

Fixed submission:
from sys import stdin
import math

a=input()
if (a[0]<a[2]):
    print("<")
elif(a[0]==a[2]):
    print("=")
else:
    print(">")

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

a=input()
if (a[0]<a[2]):
    print("<")
elif(a[0]==a[2])
    print("=")
else:
    print(">")
Problem p03385 (python)

Fixed submission:
S = sorted(input())
if S == ["a", "b", "c"]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = input()
if S.couut("a") == S.count("b") == S.count("c"):
  print("Yes")
else:
  print("No")
Problem p02975 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
  if 0 in count and count[0] == N: return True
  if len(A) % 3 != 0: return False    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
  if count[0] == N: return True
  if len(A) % 3 != 0: return False    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')
Problem p03369 (python)

Fixed submission:
S=input()
ans=700
for i in range(3):
  if S[i]=='o': ans += 100
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
ans=700
for i in range(3):
  ans+=100 if S[i]=='o'
print(ans)
Problem p03416 (python)

Fixed submission:
A,B = map(int,input().split())
ans = 0
for n in range(A,B+1):
  s = str(n)
  if s == s[::-1]: ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input())
ans = 0
for n in range(A,B+1):
  s = str(A)
  if s == s[::-1]: ans += 1
print(ans)
Problem p03605 (python)

Fixed submission:
print('Yes' if '9' in input() else 'No')

Buggy submission (verdict: Runtime Error):
c=[0]*100010
N=int(input())
for _ in range(N):
  a,b=map(int,input().split())
  c[a] += 1
  c[b+1] -= 1
for i in range(len(c)-1):
  c[i+1] += c[i]
print(sum(c))
Problem p03633 (python)

Fixed submission:

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

N=int(input())
A = [ int(input()) for _ in range(N) ]
ans = A[0]
for x in A[1:]:
  ans = ans * x // gcd(ans, x)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A = [ int(input()) for _ in range(N) ]
ans = A[0]
for x in A[1:]:
  ans = ans * x // math.gcd(ans, x)
print(ans)
Problem p03635 (python)

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
printf((n-1)*(m-1))
Problem p03651 (python)

Fixed submission:
import sys
import fractions
N,K=map(int,input().split())
A=sorted(list(set(map(int,input().split()))))
N=len(A)
if N==1:
  print("POSSIBLE" if A[0] == K else "IMPOSSIBLE")
  sys.exit(0)
g=A[1]-A[0]
for i in range(1,len(A)-1):
  g = fractions.gcd(A[i+1]-A[i], g)
if K <= A[N-1] and (K-A[0]) % g == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import sys
import fractions
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
if N==1:
  print("POSSIBLE" if A[0] == K else "IMPOSSIBLE")
  sys.exit(0)
g=A[1]-A[0]
for i in range(1,len(A)-1):
  g = fractions.gcd(A[i+1]-A[i], g)
if K <= A[N-1] and (K-A[0]) % g == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
Problem p03729 (python)

Fixed submission:
A,B,C=input().split()
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]
  ans='YES'
print(ans)
Problem p03860 (python)

Fixed submission:
print('A'+input().split()[1][0]+'C')

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
a -= 1
print ((b // x) - (a // x))
Problem p03992 (python)

Fixed submission:
s = raw_input()
print s[0:4] + " " + s[4:]

Buggy submission (verdict: Runtime Error):
s = raw_input()
print s[0:4] + " " + s[4:]
Problem p02749 (python)

Fixed submission:
from collections import Counter
def main():
    N=int(input())
    AB=[list(map(int, input().split())) for _ in range(N-1)]
    G=[[]for _ in range(N)]
    cnt=[0]*N
    for a,b in AB:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        cnt[a-1]+=1
        cnt[b-1]+=1
    CI=sorted(((c,i) for i,c in enumerate(cnt)), reverse=True)
    ans=[0]*N
    C=[0]*N
    stack=[(0,-1,0)]
    while stack:
        u,p,d=stack.pop()
        for v in G[u]:
            if v!=p:
                stack.append((v,u,d^1))
                C[v]=d^1
    X=sum(C)
    if X<=N//3:
        D=[[i for i in range(1,N+1,3)]+[i for i in range(2,N+1,3)],[i for i in range(3,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[C[i]^1].pop()
    elif N-X<=N//3:
        D=[[i for i in range(3,N+1,3)],[i for i in range(1,N+1,3)]+[i for i in range(2,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[C[i]^1].pop()
    else:
        D=[[i for i in range(1,N+1,3)],[i for i in range(2,N+1,3)],[i for i in range(3,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[2].pop()
    print(*ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter
def main():
    N=int(input())
    AB=[list(map(int, input().split())) for _ in range(N-1)]
    G=[[]for _ in range(N)]
    cnt=[0]*N
    for a,b in AB:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        cnt[a-1]+=1
        cnt[b-1]+=1
    CI=sorted(((c,i) for i,c in enumerate(cnt)), reverse=True)
    ans=[0]*N
    C=[0]*N
    S=[[],[],[]]
    for i in range(N+1):
        S[i%3].append(i)
    stack=[(0,-1,0)]
    while stack:
        u,p,d=stack.pop()
        for v in G[u]:
            if v!=p:
                stack.append((v,u,d^1))
                C[v]=d
    X=sum(C)
    use=[False]*N
    for j,(c,i) in enumerate(CI[:N//3],1):
        ans[i]=j*3
        for u in G[i]:
            use[u]=True
    k=[i for i in range(1,N+1,3)]
    l=[i for i in range(2,N+1,3)]
    for i,c in enumerate(C):
        if c and not use[u]:
            if not k:
                print(-1)
                return
            ans[i]=k.pop()
            k+=3
        if not c and not use[u]:
            if not l:
                print(-1)
                return
            ans[i]=l.pop()
            l+=3
    for i in range(N):
        if ans[i]==0:
            if k:
                ans[i]=k.pop()
            elif l:
                ans[i]=l.pop()
            else:
                print(-1)
                return
    print(*ans)

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

Fixed submission:
from collections import deque
H, W = map(int, input().split())
S = [input() for _ in range(H)]
def bfs(s, t):
    dist = [[None] * W for _ in range(H)]
    que = deque([(s, t)])
    dist[s][t] = 0
    while que:
        u, v = que.popleft()
        d = dist[u][v]
        G = []
        if u > 0 and S[u-1][v] == ".":
            G.append((u-1, v))
        if u < H - 1 and S[u+1][v] == ".":
            G.append((u+1, v))
        if v > 0 and S[u][v-1] == ".":
            G.append((u, v-1))
        if v < W - 1 and S[u][v+1] == ".":
            G.append((u, v+1))
        for w, x in G:
            if dist[w][x] is None:
                dist[w][x] = d + 1
                que.append((w, x))
    return max(d if d is not None else 0 for di in dist for d in di)

print(max(bfs(i, j) for i in range(H) for j in range(W) if S[i][j] == "."))

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

H, W = map(int, input().split())
S = [input() for _ in range(H)]
def bfs(s, t):
    dist = [[None] * W for _ in range(H)]
    que = deque([(s, t)])
    dist[s][t] = 0
    while que:
        u, v = que.popleft()
        d = dist[u][v]
        G = []
        if u > 0 and S[u-1][v] == ".":
            G.append((u-1, v))
        if u < H - 1 and S[u+1][v] == ".":
            G.append((u+1, v))
        if v > 0 and S[u][v-1] == ".":
            G.append((u, v-1))
        if v < W - 1 and S[u][v+1] == ".":
            G.append((u, v+1))
        for w, x in G:
            if dist[w][x] is not None:
                continue
            dist[w][x] = d + 1
            que.append((w, x))
    return max(max((d, (i, j)) for j, d in enumerate(di) if d is not None) for i, di in enumerate(dist))

for i in range(H):
    j = S[i].find(".")
    if j >= 0:
        break


_, (u, v) = bfs(i, j)
d, _ = bfs(u, v)
print(d)

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

H, W = map(int, input().split())
S = [input() for _ in range(H)]
for i in range(H):
    j = S[i].find(".")
    if j >= 0:
        break
def bfs(s, t):
    dist = [[None] * W for _ in range(H)]
    que = deque([(s, t)])
    dist[s][t] = 0
    while que:
        u, v = que.popleft()
        d = dist[u][v]
        G = []
        if u > 0 and S[u-1][v] == ".":
            G.append((u-1, v))
        if u < H - 1 and S[u+1][v] == ".":
            G.append((u+1, v))
        if v > 0 and S[u][v-1] == ".":
            G.append((u, v-1))
        if v < W - 1 and S[u][v+1] == ".":
            G.append((u, v+1))
        for w, x in G:
            if dist[w][x] is not None:
                continue
            dist[w][x] = d + 1
            que.append((w, x))
    return max(max((d, (i, j)) for j, d in enumerate(di) if d is not None) for i, di in enumerate(dist))
_, (u, v) = bfs(i, j)
d, _ = bfs(u, v)
print(d)
Problem p02814 (python)

Fixed submission:
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = list(map(lambda x: x//2, A))
def lcm(x, y):
    return x * y // gcd(x, y)
b0 = AA[0]&-AA[0]
for a in AA[1:]:
    if b0 != a&-a:
        print(0)
        break
else:
    a = reduce(lcm, AA)
    print(M//a - M//(2*a))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
def lcm_(x, y):
    x_ = x // 2
    y_ = y // 2
    return x_ * y_ // gcd(x_, y_)
a = reduce(lcm_, A)
print(M//a - M//(2*a))
Problem p02830 (python)

Fixed submission:
N = int(input())
S, T = input().split()
print("".join(map(lambda s,t:s+t, S, T)))

Buggy submission (verdict: Runtime Error):
N = int(input())
S, T = input().split()
print("".join(map(lambda s,t:f"{s}{t}", S, T)))