Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
d=list(map(int,input().split()))
c=list(input())

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d)	
for com in c:
	roll(com)
print(dice1.d[0])

Fixed submission:
d=list(map(int,input().split()))
c=list(input())

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d)	
for com in c:
	dice1.roll(com)
print(dice1.d[0])
Buggy python submission (verdict: Runtime Error):
d1=list(map(int,input().split()))
d2=list(map(int,input().split()))

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d1)
dice2=dice(d2)

if sorted(d1)!=sorted(d2):
	print("No")
else:
	c=["E","W","S","N"]
	import random
	for i in l:
		n=0
		while n<10**5:
			if dice1.d==dice2.d:
				break 
			else:
				dice1.roll(c[random.randint(1,2)])
			n+=1
		if n>10**5:
			print("No")
		else:
			print("Yes")

Fixed submission:
d1=list(map(int,input().split()))
d2=list(map(int,input().split()))

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d1)
dice2=dice(d2)

if sorted(d1)!=sorted(d2):
	print("No")
else:
	c=["E","W","S","N"]
	import random
	n=0
	while n<10**5:
		if dice1.d==dice2.d:
			break 
		else:
			dice1.roll(c[random.randint(1,2)])
		n+=1
	if n==10**5:
		print("No")
	else:
		print("Yes")
Buggy python submission (verdict: Runtime Error):
a=input()
print(a*a*a)

Fixed submission:
a=int(input())
print(a*a*a)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(a*b+" "+(a+b)*2)

Fixed submission:
a,b=map(int,input().split())
print(a*b,(a+b)*2)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a>b:
	print(a,">",b)
else if a==b:
	print(a,"==",b)
else if a<b:
	print(a,"<",b)

Fixed submission:
a,b=map(int,input().split())
if a>b:
	print("a",">","b")
elif a==b:
	print("a","==","b")
elif a<b:
	print("a","<","b")
Buggy python submission (verdict: Runtime Error):
a,b,c,d,r=map(int,input().split())
a-=r*2
b-=r*2
c-=r
d-=r

if 0<c and 0<d and 0<a and 0<b:
	print("Yes")
elif:
	print("No")

Fixed submission:
a,b,c,d,r=map(int,input().split())

if a>0:
	if c<0:
		print("No")
		exit()

if a<0:
	if c>0:
		print("No")
		exit()		

if b>0:
	if d<0:
		print("No")
		exit()

if b>0:
	if d<0:
		print("No")
		exit()

a=abs(a)
b=abs(b)
c=abs(c)
d=abs(d)

a-=r*2
b-=r*2
c-=r
d-=r

if 0<=c and 0<=d and 0<=a and 0<=b and c<=a and d<=b:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
a=0
while(True):
	b=input()
	if b="0":
		break
	print("Case",a,end="")
	a+=1

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Buggy python submission (verdict: Runtime Error):
a = []
for line in sys.stdin:
    a.append(int(line))

for i in range(len(a)):
	print("Case ",i+1,": ",a[i],end="")

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Buggy python submission (verdict: Runtime Error):
a = []
for line in sys.stdin:
    a.append(int(line))

for i in range(len(a)):
	print("Case ",i+1,": ",a[i],end="")

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Buggy python submission (verdict: Runtime Error):
a = []
for line in sys.stdin:
    a.append(int(line))

for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Buggy python submission (verdict: Runtime Error):
a = []
for line in sys.stdin:
	if line="0"
    a.append(int(line))

for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Buggy python submission (verdict: Runtime Error):
a = []
for line in sys.stdin:
	if line="0"
    a.append(int(line))

for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Buggy python submission (verdict: Runtime Error):
a = []
for line in sys.stdin:
	if line="0"
    a.append(int(line))
    if len(a>10000):
    	break

for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")

Fixed submission:
a = []
while True:
    n = input()
    if n == "0":
        break
    a.append(n)


for i in range(len(a)):
	print("Case ",i+1,": ",a[i],sep="")
Buggy python submission (verdict: Runtime Error):
a = []
while True:
    b = list(map(int,input().split()))
    if b[0] == "0" and b[1]=="0":
        break
    a.append(b.sort())


for i in a:
	print(i[0],i[1])

Fixed submission:
a = []
while True:
	b = list(map(int,input().split()))
	if b[0] == 0 and b[1]==0:
		break
	b.sort()
	a.append(b)

for i in a:
	print(i[0],i[1])

Buggy python submission (verdict: Runtime Error):
a = []
while True:
	b = list(map(int,input().split()))
	if b[0] == "0" and b[1]=="0":
		break
	b.sort()
	a.append(b)


for i in a:
	print(i[0],i[1])

Fixed submission:
a = []
while True:
	b = list(map(int,input().split()))
	if b[0] == 0 and b[1]==0:
		break
	b.sort()
	a.append(b)

for i in a:
	print(i[0],i[1])
Buggy python submission (verdict: Runtime Error):
a=input()
a=int(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.9f' % b,'%03.9f' % c)

Fixed submission:
import math
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.7f' % b,'%03.7f' % c)

Buggy python submission (verdict: Runtime Error):
a=input()
a=int(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.9f' % b,'%03.9f' % c)

Fixed submission:
import math
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.7f' % b,'%03.7f' % c)

Buggy python submission (verdict: Runtime Error):
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.9f' % b,'%03.9f' % c)

Fixed submission:
import math
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.7f' % b,'%03.7f' % c)

Buggy python submission (verdict: Runtime Error):
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.9f' % b,'%03.9f' % c)

Fixed submission:
import math
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.7f' % b,'%03.7f' % c)

Buggy python submission (verdict: Runtime Error):
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.7f' % b,'%03.7f' % c)

Fixed submission:
import math
a=input()
a=float(a)

p=math.pi

b= a*a*p
c= a*2*p
print('%03.7f' % b,'%03.7f' % c)
Buggy python submission (verdict: Runtime Error):
import time,sys,io,pprint,math

a = []
while True:
    m,n,o = input()
    m=int(m)
    o=int(o)
    if n == "?":
        break
    if n=="+":
    	a.append(m+o)
    elif n=="-":
    	a.append(m-o)
    elif n=="*":
    	a.append(m*o)
    elif n=="/":
    	a.append(m/o)

for i in a:
	print(a)

Fixed submission:
a = []
while True:
    m,n,o = input().split()
    m=int(m)
    o=int(o)
    if n == "?":
        break
    if n=="+":
    	a.append(m+o)
    elif n=="-":
    	a.append(m-o)
    elif n=="*":
    	a.append(m*o)
    elif n=="/":
    	a.append(int(m/o))
 

for i in a:
	print(i)

Buggy python submission (verdict: Runtime Error):

a = []
while True:
    m,n,o = input()
    m=int(m)
    o=int(o)
    if n == "?":
        break
    if n=="+":
    	a.append(m+o)
    elif n=="-":
    	a.append(m-o)
    elif n=="*":
    	a.append(m*o)
    elif n=="/":
    	a.append(m/o)

for i in a:
	print(a)

Fixed submission:
a = []
while True:
    m,n,o = input().split()
    m=int(m)
    o=int(o)
    if n == "?":
        break
    if n=="+":
    	a.append(m+o)
    elif n=="-":
    	a.append(m-o)
    elif n=="*":
    	a.append(m*o)
    elif n=="/":
    	a.append(int(m/o))
 

for i in a:
	print(i)
Buggy python submission (verdict: Runtime Error):
InputData=[]
while True:
	H,W = map(int,raw_input().split())      # Python3
	if W==0 and H==0 : break
	if (H-3)*(H-100)> 0 : continue
	if (W-3)*(W-100)> 0 : continue
	InputData.append([H,W])
	


for i in range(len(InputData)):
	H,W = InputData[i]
	print("#" * W)
	print(("#"+"#"*(W-2)+"#"+"\n")*(H-2),end="")    # Python3
	print("#" * W)
	print("")

Fixed submission:
a = []
while True:
    l = list(map(int,input().split()))
    if l == [0,0]:
        break
    a.append(l)


for i in range(len(a)):
	H,W = a[i]
	for i in range(H):
		print("#"*W)
	print("")

Buggy python submission (verdict: Runtime Error):
a = []
while True:
    l = list(input().split)
    if l == [0,0]:
        break
    a.append(l)
	

for i in range(len(a)):
	H,W = a[i]
	print("#" * W)
	print(("#"+"#"*(W-2)+"#"+"\n")*(H-2),end="")    # Python3
	print("#" * W)
	print("")

Fixed submission:
a = []
while True:
    l = list(map(int,input().split()))
    if l == [0,0]:
        break
    a.append(l)


for i in range(len(a)):
	H,W = a[i]
	for i in range(H):
		print("#"*W)
	print("")

Buggy python submission (verdict: Runtime Error):
a = []
while True:
    l = input().split
    if l == [0,0]:
        break
    a.append(l)
	

for i in range(len(a)):
	H,W = a[i]
	print("#" * W)
	print(("#"+"#"*(W-2)+"#"+"\n")*(H-2),end="")    # Python3
	print("#" * W)
	print("")

Fixed submission:
a = []
while True:
    l = list(map(int,input().split()))
    if l == [0,0]:
        break
    a.append(l)


for i in range(len(a)):
	H,W = a[i]
	for i in range(H):
		print("#"*W)
	print("")
Buggy python submission (verdict: Runtime Error):
while(True):
	H,W=list(map(int,input().split()))
	if H==0 and W==0:
		break
	l1=""
	for i in range(W):
		if i%2==0:
			l1+="#"
		else:
			l1+="."
	l1+="\n"
	l2=""
	for i in range(W):
		if i%2==0:
			l2+="."
		else:
			l2+="#"
	l2+="\n"

	l=""
	for i in range(N):
		if i%2==0:
			l+=l1
		else:
			l+=l2

	print(l)

Fixed submission:
while(True):
	H,W=list(map(int,input().split()))
	if H==0 and W==0:
		break
	l1=""
	for i in range(W):
		if i%2==0:
			l1+="#"
		else:
			l1+="."
	l1+="\n"
	l2=""
	for i in range(W):
		if i%2==0:
			l2+="."
		else:
			l2+="#"
	l2+="\n"

	l=""
	for i in range(H):
		if i%2==0:
			l+=l1
		else:
			l+=l2

	print(l)
Buggy python submission (verdict: Runtime Error):
l=[]
for mark in ["S","H","C","D"]:
	for i in range(1,14):
		l.append(mark+" "+str(i))
n=input()
for i in range(n):
	l.remove(input())
for i in l:
	print(i)

Fixed submission:
l=[]
for mark in ["S","H","C","D"]:
	for i in range(1,14):
		l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
	l.remove(input())
for i in l:
	print(i)

Buggy python submission (verdict: Runtime Error):
l=[]
for mark in ["S","H","C","D"]:
	for i in range(1,14):
		l.append(mark+" "+str(i))
n=input()
for i in range(n):
	l.remove(input())
for i in l:
	print(i)

Fixed submission:
l=[]
for mark in ["S","H","C","D"]:
	for i in range(1,14):
		l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
	l.remove(input())
for i in l:
	print(i)

Buggy python submission (verdict: Runtime Error):
l=[]
for mark in ["S","H","C","D"]:
	for i in range(1,14):
		l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
	l.remove(input())
for i in l[:-1]:
	print(i)
print(l[-1])

Fixed submission:
l=[]
for mark in ["S","H","C","D"]:
	for i in range(1,14):
		l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
	l.remove(input())
for i in l:
	print(i)
Buggy python submission (verdict: Runtime Error):
l=[[[0 for i in range(10)] for i in range(3)] for i in range(4)]
n=int(input())
for i in range(n):
	a,b,c,d=list(map(int,input().split()))
	l[a-1][b-1][c-1]=d 
for i in l:
	for j in i:
		print(" ".join(j))
	if not i==l[-1]:
		print("####################")

Fixed submission:
l=[[[0 for i in range(10)] for i in range(3)] for i in range(4)]
n=int(input())
for i in range(n):
	a,b,c,d=list(map(int,input().split()))
	l[a-1][b-1][c-1]+=d
for i in l[:-1]:
	for j in i:
		print(" "+" ".join(list(map(str,j))))
	print("####################")

for j in l[-1]:
	print(" "+" ".join(list(map(str,j))))

Buggy python submission (verdict: Runtime Error):
l=[[["0" for i in range(10)] for i in range(3)] for i in range(4)]
n=int(input())
for i in range(n):
	a,b,c,d=list(map(int,input().split()))
	l[a-1][b-1][c-1]=str(d)zzzzzzzzzz
for i in l:
	for j in i:
		print(" ".join(j))
	if not i==l[-1]:
		print("####################")

Fixed submission:
l=[[[0 for i in range(10)] for i in range(3)] for i in range(4)]
n=int(input())
for i in range(n):
	a,b,c,d=list(map(int,input().split()))
	l[a-1][b-1][c-1]+=d
for i in l[:-1]:
	for j in i:
		print(" "+" ".join(list(map(str,j))))
	print("####################")

for j in l[-1]:
	print(" "+" ".join(list(map(str,j))))
Buggy python submission (verdict: Runtime Error):
while(True)
	m,f,r=list(map(int,input().split()))
	if m==-1 and f==-1 and r==-1:
		break
	if m==-1 or f==-1:
		print("F")
	elif m+f>=80:
		print("A")
	elif m+f>=65:
		print("B")
	elif m+f>=50:
		print("C")
	elif m+f>=30:
		if r>=50:
			print("C")
		else:
			print("D")
	else:
		print("F")

Fixed submission:
while(True):
	m,f,r=list(map(int,input().split()))
	if m==-1 and f==-1 and r==-1:
		break
	if m==-1 or f==-1:
		print("F")
	elif m+f>=80:
		print("A")
	elif m+f>=65:
		print("B")
	elif m+f>=50:
		print("C")
	elif m+f>=30:
		if r>=50:
			print("C")
		else:
			print("D")
	else:
		print("F")
Buggy python submission (verdict: Runtime Error):
r,c=list(map(int,input().split()))
l=[]
for i in range(r):
	a=list(map(int,input().split()))
	a.append(sum(a))
	l.append(a)
b=[]
for i in range(c+1):
	c=0
	for j in range(r):
		c+=l[j][i]
	b.append(c)
l.append(b)

for i in l:
	print(" ".join(map(str,i)))

Fixed submission:
while(True):
	a,b=list(map(int,input().split()))
	if a==0 and b==0:
		break
	c=0
	for i in range(1,a+1):
		for j in range(1,i):
			for k in range(1,j):
				if i+j+k==b:
					c+=1
	print(c)

Buggy python submission (verdict: Runtime Error):
r,c=list(map(int,input().split()))
l=[]
for i in range(r):
	a=list(map(int,input().split()))
	a.append(sum(a))
	l.append(a)
b=[]
for i in range(c+1):
	c=0
	for j in range(r):
		c+=l[j][i]
	b.append(c)
l.append(b)

for i in l:
	print(" ".join(list(map(str,i))))

Fixed submission:
while(True):
	a,b=list(map(int,input().split()))
	if a==0 and b==0:
		break
	c=0
	for i in range(1,a+1):
		for j in range(1,i):
			for k in range(1,j):
				if i+j+k==b:
					c+=1
	print(c)
Buggy python submission (verdict: Runtime Error):
r,c=list(map(int,input().split()))
l=[]
for i in range(r):
	a=list(map(int,input().split()))
	l.append(a.append(sum(a)))
b=[]
for i in range(c+1):
	c=0
	for j in range(r):
		c+=l[j][i]
	b.append(c)
l.append(b)

for i in l:
	print(" ".join(i))

Fixed submission:
r,c=list(map(int,input().split()))
l=[]
for i in range(r):
	a=list(map(int,input().split()))
	a.append(sum(a))
	l.append(a)
b=[]
for i in range(c+1):
	c=0
	for j in range(r):
		c+=l[j][i]
	b.append(c)
l.append(b)

for i in l:
	print(" ".join(list(map(str,i))))
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)):
	if s[i].islower():
		s[i]=s[i].upper()
	elif s[i].isupper():
		s[i]=s[i].lower()
print(s)

Fixed submission:
s=list(input())
for i in range(len(s)):
	if s[i].isalnum():
		if s[i].islower():
			s[i]=s[i].upper()
		elif s[i].isupper():
			s[i]=s[i].lower()
print("".join(s))
Buggy python submission (verdict: Runtime Error):
s=list(input())
res=[0 for i in range(26)]
for i in s:
	if i.isalnum():
		i=i.lower()
		res[ord(s)-ord("a")]+=1

for i in range(26):
	s=chr(ord(i)+ord("a"))+" : "+str(res[i])
	print(s)

Fixed submission:
s=""
import fileinput
a=fileinput.input()
for i in a:
	s+=i
s=list(s)
res=[0 for i in range(26)]
for i in s:
	if i.isalpha():
		i=i.lower()
		res[ord(i)-ord("a")]+=1

for i in range(26):
	s=chr(i+ord("a"))+" : "+str(res[i])
	print(s)

Buggy python submission (verdict: Runtime Error):
s=list(input())
res=[0 for i in range(26)]
for i in s:
	if i.isalnum():
		i=i.lower()
		res[ord(s)-ord("a")]+=1

for i in range(26):
	s=chr(ord(i)+ord("a"))+" : "+str(res[i])
	print(s)

Fixed submission:
s=""
import fileinput
a=fileinput.input()
for i in a:
	s+=i
s=list(s)
res=[0 for i in range(26)]
for i in s:
	if i.isalpha():
		i=i.lower()
		res[ord(i)-ord("a")]+=1

for i in range(26):
	s=chr(i+ord("a"))+" : "+str(res[i])
	print(s)
Buggy python submission (verdict: Runtime Error):
s=list(input())
n=int(input())
for i in range(n):
	l=input().split()
	if l[0]=="replace":
		a=int(l[1])
		b=int(l[2])
		s[a:b+1]=list(l[3])
	elif l[0]=="reverse":
		a=int(l[1])
		b=int(l[2])
		c=s[a:b+1][::-1]
		s[a:b+1]=c
	else:
		a=int(l[1])
		b=int(l[2])
		print("".join(s[a:b+1]))

Fixed submission:
n=int(input())
A=0
B=0
for i in range(n):
	a,b=input().split()
	if a>b:
		A+=3
	elif a==b:
		A+=1
		B+=1
	else:
		B+=3
print(A,B)
Buggy python submission (verdict: Runtime Error):
def search(s, t):
    global g
    node = g[s]
    node[1] = 1
    if s == t:
        return True
    else:
        for i in node[0]:
            ch = g[i]
            if ch[1] == 0:
                result = search(i, t)
                if result:
                    return result
        return False

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

g = [[[], 0] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    g[s][0].append(t)
    g[t][0].append(s)

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    result = search(s, t)
    if result:
        print("yes")
    else:
        print("no")
    for node in g:
        node[1] = 0

Fixed submission:
def dfs(u, color):
    global c
    global g
    s = [u]
    c[u] = color
    while 0 < len(s):
        ch = s.pop()
        for ch in g[ch]:
            u_c = c[ch]
            if u_c is None:
                c[ch] = color
                s.append(ch)

def colorize():
    global g
    global c
    global n
    color = 1
    for i in range(n):
        if c[i] == None:
            dfs(i, color)
            color += 1

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

g = [[] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    g[s].append(t)
    g[t].append(s)

c = [None for i in range(n)]

colorize()

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    if c[s] == c[t]:
        print("yes")
    else:
        print("no")

Buggy python submission (verdict: Runtime Error):
def search(s, t, a):
    global g
    a.add(s)
    if s == t:
        return True
    else:
        for ch in g[s]:
            if not (ch in a):
                result = search(ch, t, a)
                if result:
                    return result
        return False

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

g = [[] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    g[s].append(t)
    g[t].append(s)

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    a = set()
    result = search(s, t, a)
    if result:
        print("yes")
    else:
        print("no")
    a.clear()

Fixed submission:
def dfs(u, color):
    global c
    global g
    s = [u]
    c[u] = color
    while 0 < len(s):
        ch = s.pop()
        for ch in g[ch]:
            u_c = c[ch]
            if u_c is None:
                c[ch] = color
                s.append(ch)

def colorize():
    global g
    global c
    global n
    color = 1
    for i in range(n):
        if c[i] == None:
            dfs(i, color)
            color += 1

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

g = [[] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    g[s].append(t)
    g[t].append(s)

c = [None for i in range(n)]

colorize()

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    if c[s] == c[t]:
        print("yes")
    else:
        print("no")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hq

def relax(u, v, w):
    if D[u] + w < D[v]:
        D[v] = D[u] + w
        P[v] = u
        for h in H:
            if h[1] == v:
                h[0] = D[v]
        hq.heapify(H)

INF = float('inf')
N = int(input())
D = [INF for i in range(N)]
P = [None for i in range(N)]
D[0] = 0

G = [{} for i in range(N)]
for i in range(N):
    x = list(map(int, input().split()))
    g = x[2:]
    for j, n in enumerate(g):
        if j % 2 == 0:
            G[i][n] = g[j + 1]

H = [[D[i], i] for i in range(N)]
hq.heapify(H)
S = set()

while 0 < len(H):
    d_u, u = hq.heappop(H)
    S.add(u)
    for v, w in G[u].items():
        if not (v in S):
            relax(u, v, w)

for i, d in enumerate(D):
    print('{0} {1}'.format(i, d))

Fixed submission:
import heapq as hq

def relax(u, v, w):
    if D[u] + w < D[v]:
        D[v] = D[u] + w
        P[v] = u
        hq.heappush(H, (D[v], v))

INF = float('inf')
N = int(input())
D = [INF for i in range(N)]
P = [None for i in range(N)]
D[0] = 0

G = [{} for i in range(N)]
for i in range(N):
    x = list(map(int, input().split()))
    g = x[2:]
    for j, n in enumerate(g):
        if j % 2 == 0:
            G[i][n] = g[j + 1]

H = [(0, 0)]

while 0 < len(H):
    d_u, u = hq.heappop(H)
    for v, w in G[u].items():
        relax(u, v, w)

for i, d in enumerate(D):
    print('{0} {1}'.format(i, d))
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = []
for i in range(n):
    c = input().split()
    cmd = c[0]
    x = 0
    if 1 < len(c):
        x = int(c[1])
    if cmd == 'insert':
        y = [x] + ans
        ans = y
    elif cmd == 'delete':
        index = ans.index(x)
        ans.pop(index)
    elif cmd == 'deleteFirst':
        ans.pop(0)
    elif cmd == 'deleteLast':
        ans.pop(len(ans) - 1)

print(' '.join(map(str, ans)))

Fixed submission:
import sys
from collections import deque
n = int(sys.stdin.readline())

ans = deque()

for i in range(n):
    c = sys.stdin.readline()[:-1]
    if c[0] == 'i':
        ans.appendleft(c[7:])
    elif c[6] == ' ':
        try:
            ans.remove(c[7:])
        except:
            pass
    elif c[6] == 'F':
        ans.popleft()
    else:
        ans.pop()

print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = []
for i in range(n):
    c = input().split()
    cmd = c[0]
    x = 0
    if 1 < len(c):
        x = int(c[1])
    if cmd == 'insert':
        y = [x] + ans
        ans = y
    elif cmd == 'delete':
        try:
            index = ans.index(x)
            ans.pop(index)
        except:
            ''
    elif cmd == 'deleteFirst':
        ans.pop(0)
    elif cmd == 'deleteLast':
        ans.pop(len(ans) - 1)

print(' '.join(map(str, ans)))

Fixed submission:
import sys
from collections import deque
n = int(sys.stdin.readline())

ans = deque()

for i in range(n):
    c = sys.stdin.readline()[:-1]
    if c[0] == 'i':
        ans.appendleft(c[7:])
    elif c[6] == ' ':
        try:
            ans.remove(c[7:])
        except:
            pass
    elif c[6] == 'F':
        ans.popleft()
    else:
        ans.pop()

print(' '.join(ans))