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

Fixed submission:
# -*- coding: utf-8 -*-
X = int(input())

ans = ""
for i in range(10 ** 4):
    for j in range(-70, i, 1):
        if i ** 5 - j ** 5 == X:
            ans = "{} {}".format(i, j)
            break
    if ans != "":
        break

if ans != "":
    print(ans)
else:
    print(aaa)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
X = int(input())

ans = ""
for i in range(70):
    for j in range(-70, i, 1):
        if i ** 5 - j ** 5 == X:
            ans = "{} {}".format(i, j)
            break
    if ans != "":
        break

if ans != "":
    print(ans)
else:
    print(aaa)
Problem p02742 (python)

Fixed submission:
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
if H > 1 and W > 1:
    print((H * W) // 2 + (H * W) % 2)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
if H > 1 and W > 1:
    print((H * W) // 2 + (H * W) % 2)
else
    print(1)
Problem p02747 (python)

Fixed submission:
# -*- coding: utf-8 -*-
S = str(input())

print("Yes" if len(S.replace("hi", "")) == 0 else "No")

Buggy submission (verdict: Runtime Error):
print('Yes' if !input().replace('hi','') else 'No')
Problem p02756 (python)

Fixed submission:
# -*- coding: utf-8 -*-
S = str(input())
Q = int(input())

rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[1] == "1" else -1
        h_or_t_flag *= rev_flag
        
        if h_or_t_flag == 1:
            head_str = query[2] + head_str
        else:
            tail_str += query[2]

ans = head_str + S + tail_str
print(ans if rev_flag == 1 else ans[::-1])

Buggy submission (verdict: Runtime Error):
resolve()
def resolve():
    S = str(input())
    Q = int(input())

    rev_flag = 1
    head_str = ""
    tail_str = ""
    for _ in range(Q):
        query = input() # contains spaces
        if query[0] == "1":
            rev_flag *= -1
        else:
            h_or_t_flag = 1 if query[2] == "1" else -1
            h_or_t_flag *= rev_flag

            if h_or_t_flag == 1:
                head_str += query[4]
            else:
                tail_str += query[4]

    ans = head_str[::-1] + S + tail_str
    print(ans if rev_flag == 1 else ans[::-1])
Problem p02803 (python)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

H, W = map(int, input().split())

graph_list = []
for i in range(H):
    temp_graph_str = str(input())
    temp_list = [1 if i == "." else 0 for i in temp_graph_str]
    graph_list.append(temp_list)

graph_tree_list = []
for i in range(H):
    for j in range(W):
        temp_list = [0 for x in range(H * W)]
        if graph_list[i][j] == 1:
            if i > 0:
                if graph_list[i - 1][j] == 1:
                    temp_list[(i - 1) * W + j] = 1
            if i < H - 1:
                if graph_list[i + 1][j] == 1:
                    temp_list[(i + 1) * W + j] = 1
            if j > 0:
                if graph_list[i][j - 1] == 1:
                    temp_list[i * W + (j - 1)] = 1
            if j < W - 1:
                if graph_list[i][j + 1] == 1:
                    temp_list[i * W + (j + 1)] = 1
        graph_tree_list.append(temp_list)

graph_tree_array = np.array(graph_tree_list)

sp = shortest_path(graph_tree_array, directed=False, unweighted=True)

# print(sp)
sp[np.isinf(sp)] = 0
print(int(np.max(sp)))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

H, W = map(int, input().split())

graph_list = []
for i in range(H):
    temp_graph_str = str(input())
    temp_list = [1 if i == "." else 0 for i in temp_graph_str]
    graph_list.append(temp_list)

graph_tree_list = []
for i in range(H):
    for j in range(W):
        temp_list = [0 for x in range(H * W)]
        if graph_list[i][j] == 1:
            if i > 0:
                if graph_list[i - 1][j] == 1:
                    temp_list[(i - 1) * W + j] = 1
            if i < H - 1:
                if graph_list[i + 1][j] == 1:
                    temp_list[(i + 1) * W + j] = 1
            if j > 0:
                if graph_list[i][j - 1] == 1:
                    temp_list[i * W + (j - 1)] = 1
            if j < H - 1:
                if graph_list[i][j + 1] == 1:
                    temp_list[i * W + (j + 1)] = 1
        graph_tree_list.append(temp_list)

graph_tree_array = np.array(graph_tree_list)

sp = shortest_path(graph_tree_array, directed=False, unweighted=True)

# print(sp)
sp[np.isinf(sp)] = 0
print(int(np.max(sp)))
Problem p02854 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))
 
div_sum_A = sum(A_list) / 2
ans = 0
calculator = 0
for i in range(N):
    calculator += A_list[i]
    if calculator >= div_sum_A:
        if calculator == div_sum_A:
            ans = 0
            break
        elif A_list[i] > div_sum_A:
            ans = 2 * A_list[i] - calculator
            break
        else:
            cand_1 = calculator - (2 * div_sum_A - calculator)
            cand_2 = abs((calculator - A_list[i]) - (2 * div_sum_A - (calculator - A_list[i])))
            ans = min(cand_1, cand_2)
            break

print(int(ans))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

div_sum_A = sum(A_list) / 2
ans = 0
calculator = 0
for i in range(N):
    calculator += A_list[i]
    if calculator >= div_sum_A:
        if calculator == div_sum_A:
            ans = 0
            break
        elif A_list[i] > div_sum_A:
            ans = 2 * A_list - calculator
            break
        else:
            cand_1 = calculator - (2 * div_sum_A - calculator)
            cand_2 = abs((calculator - A_list[i]) - (2 * div_sum_A - (calculator - A_list[i])))
            ans = min(cand_1, cand_2)
            break

print(int(ans))
Problem p02921 (python)

Fixed submission:
# -*- coding: utf-8 -*-
S = str(input())
T = str(input())

counter = 0
for i in range(len(S)):
    if S[i] == T[i]:
        counter += 1

print(counter)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
S = str(input())
T = str(input())

counter = 0
for i in range(S):
    if S[i] == T[i]:
        counter += 1

print(counter)
Problem p02973 (python)

Fixed submission:
# -*- coding: utf-8 -*-
from bisect import bisect_right, bisect_left
N = int(input())
a_list = [int(input()) for _ in range(N)]

color_list = [1]
for a in a_list:
    a *= -1
    index = bisect_right(color_list, a)
    if index < len(color_list):
        color_list[index] = a
    else:
        color_list.append(a)
#     print(color_list, a)
print(len(color_list))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
a_list = []
for i in range(N):
    a_list.append(int(input()))
color_counter = 0
for i in range(N):
    color_counter += 1
    compare_a = a_list[0]
    next_a_list = []
    for i in range(N):
        if compare_a < a_list[i]:
            compare_a = a_list[i]
        else:
            next_a_list.append(a_list[i])
    if len(next_a_list) == 0:
        break
    else:
        a_list = next_a_list
print(color_counter)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
a_list = []
for i in range(N):
    a_list.append(int(input()))
color_counter = 0
for i in range(N):
    color_counter += 1
    compare_a = a_list.pop(0)
    for idx, ite in enumerate(a_list[:]):
        if compare_a < ite:
            compare_a = a_list.pop(idx)
    if len(a_list) == 0:
        break
print(color_counter)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
a_list = []
for i in range(N):
    a_list.append(int(input()))
color_counter = 0
while len(a_list) > 0:
    color_counter += 1
    compare_a = a_list.pop(0)
    for idx, ite in enumerate(a_list[:]):
        if compare_a < ite:
            compare_a = a_list.pop(idx)
    
print(color_counter)
Problem p02813 (python)

Fixed submission:
import itertools
a=int(input())
z=tuple(map(int,input().split()))
x=tuple(map(int,input().split()))
y=list(itertools.permutations(z))
y.sort()
ans1=y.index(z)+1
ans2=y.index(x)+1
print(abs(ans1-ans2))

Buggy submission (verdict: Runtime Error):
a=int(input())
A=[]
B=[]
C=[0,1,2,6,24,120,720,5040,40320]
d=0
e=0
for p in range(a):
  s=int(input())
  A.append(s)
for q in range(a):
  b=int(input())
  B.append(b)
for i in range(a,1,-1):
  d1=C[i-1]*(A[a-i]-1)
  e1=C[i-1]*(B[a-i]-1)
  d=d+d1
  e=e+e1
print(abs(d-e))
Problem p02830 (python)

Fixed submission:
a=int(input())
s,d=input().split()
z=""
for i in range(a):
  z+=s[i]
  z+=d[i]
print(z)

Buggy submission (verdict: Runtime Error):
a=int(input())
s=input()
d=input()
z=""
for i in range(a):
  z+=s[i]
  z+=d[i]
print(z)
Problem p02848 (python)

Fixed submission:
a=int(input())
s=input()
d=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E"]
S=list(s)
for i in range(len(S)):
  z=d.index(S[i])
  S[i]=d[z+a]
print("".join(S))

Buggy submission (verdict: Runtime Error):
a=int(input())
s=input()
d=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
S=list(s)
for i in range(len(S)):
  z=S.index(S[i])
  S[i]=d[z+a]
print("".join(S))
Problem p02817 (python)

Fixed submission:
s, t = input().split()
print(t, s, sep='')

Buggy submission (verdict: Runtime Error):
s, t = input.split()
print(t, s, sep='')
Problem p02576 (python)

Fixed submission:
m,n,k = map(int,input().split())
if m%n == 0:
  print(int(k*((m//n))))
elif m%n !=0:
  print(int(k*((m//n)+1)))

Buggy submission (verdict: Runtime Error):
n = list(input())
a = 0
for i in n:
  a +=int(i)
  
if a%9==0:
  print('Yes')
else:
  print('No')
Problem p02583 (python)

Fixed submission:
import itertools
N = int(input())
a = list(map(int,input().split()))
count=0
for a in list(itertools.combinations(a,3)):
  if a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    if a[1]+a[2]>a[0] and a[0]+a[2]>a[1] and a[0]+a[1]>a[2]:
      count+=1
  
print(count)

Buggy submission (verdict: Runtime Error):
X,D,C = map(int,input().split())
count=abs(X)
a = X//C
b = X%C
if a>D:
  print(count-D*C)
elif a==D:
  print(b)
elif a<D:
  D = D-a
  if D%2==0:
    print(b)
  else:
    print(min(abs(b-C),abs(b+C)))
Problem p02641 (python)

Fixed submission:
N,M = map(int,input().split())
if M == 0:
  print(N)
else:
  c=list(map(int, input().split()))
  for i in range(N+1):
    for s in [-1,1]:
      a = N+s*i
      if c.count(a)==0:
      	print(a)
      	exit(0)

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

c.sort()
a = c[N-1]
list_c = [0]*(a+1)
for i in c:
  mal = 2
  b = i
  while i<=a:
    list_c[i]+=1
    i = b*mal
    mal+=1
count = 0
for i in c:
  if list_c[i]==1:
    count+=1
print(count)
Problem p02642 (python)

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

c.sort()
a = c[N-1]
list_c = [0]*(a+1)
for i in c:
  mal = 2
  b = i
  while i<=a:
    list_c[i]+=1
    i = b*mal
    mal+=1
count = 0
for i in c:
  if list_c[i]==1:
    count+=1
print(count)

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

count = 0
while count<len(c):
  for i,b in enumerate(c):
    if i == count:
      continue
      
    print(i,b)
    if b%c[count]==0:
      c.pop(i)
      print(c)
  count+=1

print(c)

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

@jit
def search(N,c):
  count = 0
  for i in range(N):
    b = []
    m = copy.copy(c)
    a = c[i]
    m.pop(i)
    m.sort()
    for j in range(N-1):
      if m[j]>c[i]:
        count+=1
        break
      elif c[i]%m[j]==0:
        break
      elif j == N-2:
        count+=1
      elif c[i]%m[j]!=0:
        continue
      
  return count

print(search(N,c))
Problem p02675 (python)

Fixed submission:
N = (int(input())%100)%10
if N in [2,4,5,7,9]:
  print('hon')
elif N in [0,1,6,8]:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = input()
if len(list(a)) <=N:
  print(a)
else:
  print(a[0:N]+'...')
Problem p02681 (python)

Fixed submission:
a = list(input())
b = list(input())
flag = True
for i,j in enumerate(a):
  if j !=b[i]:
    print('No')
    flag = False
    break
if flag == True:
  print('Yes')

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
a = list(map(int,input().split()))
list_a = []
list_b =[]
list_a.append(1)
count_a = 1
count_b = 0
for i in range(1,K+1):
  if i == 1:
    k = i
  if a[k-1] in list_b:
    break
  elif a[k-1] in list_a:
    list_b.append(a[k-1])
    count_b+=1
  if a[k-1] not in list_a:
    list_a.append(a[k-1])
    count_a+=1
  k = a[k-1]
#print(list_a,list_b,count_a,count_b)
if count_b != 0:
  num_k = K-(count_a-count_b)
  num_k = num_k%count_b
  if 1 in list_b and list_b[0]!=1:
    #list_b.remove(1)
    list_b.insert(0,1)
  print(list_b[num_k])
elif count_b ==0:
  print(list_a[count_a-1])
Problem p02705 (python)

Fixed submission:
N = int(input())
print(round(N*2*3.1415,2))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,(input().split())))
list_a = [0]*2*100001
for i in a:
  list_a[i] += 1
for i in range(1,N+1):
  print(list_a[i])
Problem p02761 (python)

Fixed submission:
N,M = map(int,input().split())
a = [0]*N
b = [None]*N
for i in range(M):
  s,c = map(int,input().split())
  if b[s-1] == c:
    continue
  else:
    a[s-1] +=1
    b[s-1] =c
    
count = 0
for i in range(N):
  if a[i]>=2:
    count=-1
  elif b[0]==0 and N>1:
    count =-1
  elif i==0:
    if b[i] is None:
      if N==1:
        b[i] =0
      else:
        b[i]=1
  elif i>0:
    if b[i] is None:
      b[i]=0
b.reverse()
if count == 0:
  for i in range(N):
    count+=b[i]*10**i
print(count)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = [0]*N
b = [None]*N
for i in range(M):
  s,c = map(int,input().split())
  if b[s-1] == c:
    continue
  else:
    a[s-1] +=1
    b[s-1] =c
    
count = 0
for i in range(N):
  if a[i]>=2:
    count=-1
  elif b[0]==0 and N>1:
    count =-1
  elif b[i]==0:
    if i is None:
      if N==1:
        b[i] =0
      else:
        b[i]=1
  elif i>0:
    if b[i] is None:
      b[i]=0
b.reverse()
if count == 0:
  for i in range(N):
    count+=b[i]*10**i
print(count)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = [0]*N
b = [None]*N
for i in range(M):
  s,c = map(int,input().split())
  if b[s-1] == c:
    continue
  else:
    a[s-1] +=1
    b[s-1] =c
    
count = 0
for i in range(N):
  if a[i]>=2:
    count=-1
  elif b[0]==0 and N>1:
    count =-1
  elif i==0:
    if i is None:
      if N==1:
        b[i] =0
      else:
        b[i]=1
  elif i>0:
    if b[i] is None:
      b[i]=0
b.reverse()
if count == 0:
  for i in range(N):
    count+=b[i]*10**i
print(count)
Problem p02882 (python)

Fixed submission:
import math
a,b,x = map(int,input().split())
y = (a**2)*b
h = x/(a**2)

def get_angle_from_sides(a, b, c):
    return math.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b))

def checkio(a, b, c):
    try:
        angles = [get_angle_from_sides(*abc) for abc in ((a, b, c), (b, c, a), (c, a, b))]
        result = sorted((math.degrees(a)) for a in angles)
        return [0, 0, 0] if 0 in result else result
    except ValueError:
        return [0, 0, 0]
count = 0
if y == x:
  pass
elif y/2 <=x:
  if a>=2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[0]
  elif a<2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[1]
elif y/2>x:
  z = 2*x/(a*b)
  if b>=z:
    m = checkio(b,z,math.sqrt(b**2+(z)**2))
    count = m[1]
  elif b<z:
    m = checkio(b,z,math.sqrt(b**2+(z)**2))
    count = m[0]
#print(a,2*(b-h),math.sqrt(a**2+2*(b-h)**2),m)
print(count)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
y = (a**2)*b
h = x/(a**2)

def get_angle_from_sides(a, b, c):
    return math.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b))

def checkio(a, b, c):
    try:
        angles = [get_angle_from_sides(*abc) for abc in ((a, b, c), (b, c, a), (c, a, b))]
        result = sorted((math.degrees(a)) for a in angles)
        return [0, 0, 0] if 0 in result else result
    except ValueError:
        return [0, 0, 0]
count = 0
if y/2 <=x:
  if a>=2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[0]
  elif a<2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[1]
elif y/2>x:
  z = 2*x/(a*b)
  if b>=z:
    m = checkio(b,z,math.sqrt(b**2+(z)**2))
    count = m[1]
  elif b<z:
    m = checkio(b,z,math.sqrt(b**2+(z)**2))
    count = m[0]
#print(a,2*(b-h),math.sqrt(a**2+2*(b-h)**2),m)
print(count)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
y = (a**2)*b
h = x/(a**2)

def get_angle_from_sides(a, b, c):
    return math.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b))

def checkio(a, b, c):
    try:
        angles = [get_angle_from_sides(*abc) for abc in ((a, b, c), (b, c, a), (c, a, b))]
        result = sorted((math.degrees(a)) for a in angles)
        return [0, 0, 0] if 0 in result else result
    except ValueError:
        return [0, 0, 0]
count = 0
if y/2 <=x:
  if a>=2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[0]
  elif a<2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[1]
elif y/2>x:
  z = 2*x/(a*b)
  if b>=z:
    m = checkio(a,z,math.sqrt(a**2+(z)**2))
    count = m[1]
  elif b<z:
    m = checkio(a,z,math.sqrt(a**2+(z)**2))
    count = m[0]
    
print(count)
Problem p02887 (python)

Fixed submission:
N = int(input())
a = list(input())
count = 1
for i in range(N):
  if i>0:
    if a[i-1]==a[i]:
      pass
    elif a[i-1]!=a[i]:
      count+=1
      
print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n = int(input())
l = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect.bisect_left(l, l[i]+l[j]) - (j+1)
        #print(l,i,j,bisect.bisect_left(l, l[i]+l[j]))
print(ans)
Problem p02576 (python)

Fixed submission:
import math

n, x, t = map(int, input().split())
print(math.ceil(n / x) * t)

Buggy submission (verdict: Runtime Error):
n, x, t = map(int, input().split())
print((n // x + 1) * T)
Problem p02582 (python)

Fixed submission:
s = input()
if s.count('R') == 0:
    print(0)
elif s.count('R') == 1:
    print(1)
elif s.count('R') == 2:
    if s[1] == 'R':
        print(2)
    else:
        print(1)
else:
    print(3)

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

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

l_counter = Counter(l)
l_set = sorted(list(l_counter.keys()))

length = len(l_set)
ans = 0
if n < 3:
    print(0)
else:
    for i in range(length - 2):
        for j in range(i + 1, length - 1):
            for k in range(j + 1, length):
                if l_set[k] < l_set[i] + l_set[j]:
                    ans += l_counter[l_set[i]] * l_counter[l_set[j]] * l_counter[l_set[k]]

    print(ans)
Problem p02584 (python)

Fixed submission:
x, k, d = map(int, input().split())

left = k - (abs(x) // d)

if abs(x) // d > k:
    print(abs(x) - k*d)
else:
    ans_abs = abs(x) % d
    if left % 2 == 0:
        print(ans_abs)
    else:
        print(d - ans_abs)

Buggy submission (verdict: Runtime Error):
x, k, d = map(int, input().split())

pm = x // abs(x)
left = k - (abs(x) // d)

if abs(x) // d > k:
    print(abs(x) - k*d)
else:
    ans_abs = abs(x) % d
    if left % 2 == 0:
        print(ans_abs)
    else:
        print(d - ans_abs)
Problem p02678 (python)

Fixed submission:
from collections import deque

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

class Node:
    def __init__(self, x):
        self.val = x
        self.adj = []

nodelist = [Node(0)]
for i in range(1, n+1):
  nodelist.append(Node(i))

for i in range(m):
    a, b = map(int, input().split())
    nodelist[a].adj.append(b)
    nodelist[b].adj.append(a)

q = deque()
q.append(nodelist[1])

while len(q) > 0:
    node = q.popleft()

    if node is not None:
        for i in node.adj:
            if ans_list[i] == 0:
                ans_list[i] = node.val
                q.append(nodelist[i])

print('Yes')
for j in range(2, n + 1):
    print(ans_list[j])

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

def main():
    n, m = map(int, input().split())
    ans_list = [0]*(n+1)

    class Node:
        def __init__(self, x):
            self.val = x
            self.adj = []

    nodelist = [Node(0)]
    for i in range(1, n+1):
        nodelist.append(Node(i))

    for i in range(m):
        a, b = map(int, input().split())
        nodelist[a].adj.append(b)
        nodelist[b].adj.append(a)

    q = deque()
    q.append(nodelist[1])

    while len(q) > 0:
        node = q.popleft()

        if node is not None:
            for i in node.adj:
                if ans_list[i] == 0:
                    ans_list[i] = node.val
                    q.append(nodelist[i])

    print('Yes')
    for j in range(2, n + 1):
        print(ans_list[j])

if __name__ = '__main__':
    main()