Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

import sys

sys.setrecursionlimit(100000)
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))



Fixed submission:

import sys

sys.setrecursionlimit(100000)
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))



Fixed submission:

import sys

sys.setrecursionlimit(100000)
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))
Buggy python submission (verdict: Runtime Error):
from collections import deque
import copy

def solve(idx, arr, lcur, rcur, isL):
  if len(idx) == len(arr):
    return sum([abs(arr[idx[i]]-arr[idx[i-1]]) for i in range(1, len(idx))])
  else:
    fL = copy.copy(idx)
    fR = copy.copy(idx)
    if isL:
      if lcur <= rcur:
        fL.appendleft(lcur)
        fR.append(lcur)
        lcur += 1
        if lcur <= rcur:
          fL.append(lcur)
          fR.appendleft(lcur)
          lcur += 1
    else:
      if lcur <= rcur:
        fL.appendleft(rcur)
        fR.append(rcur)
        rcur -= 1
        if lcur <= rcur:
          fL.append(rcur)
          fR.appendleft(rcur)
          rcur -= 1
    return max(solve(fL, arr, lcur, rcur, not isL), solve(fR, arr, lcur, rcur, not isL))

N = int(input())
A = sorted([int(input()) for _ in range(N)])
print(solve(deque([0]), A, 1, N-1, False)) 


Fixed submission:
N = int(input())
signs = [1, -1]
coefs = [[-1],[1]]
i = 0
while i < N-2:
  j = 0
  while j < 2:
    coefs[j].append(2*signs[j])
    signs[j] *= -1
    j += 1
  i += 1
coefs[0].append(signs[0])
coefs[1].append(signs[1])
coefs[0].sort()
coefs[1].sort()
A = sorted([int(input()) for _ in range(N)])
print(max([sum([A[i]*coef[i]  for i in range(N)]) for coef in coefs]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, K = map(int, input().split())
combs = deque()
ans = 0
a = 1
while a <= N:
  b = K - a
  while b <= N:
    if b >=  a:
      c = K - a
      while c <= N:
        if c >= b and (b+c)%K == 0 and (c+a)%K == 0:
          combs.append([a, b, c])
        c += K
    b += K
  a += 1
for (a, b, c) in combs:
  if a==b and b==c:
    ans += 1
  elif a == b or b == c or c == a:
    ans += 3
  else:
    ans += 6
print(ans)

Fixed submission:
from collections import deque
N, K = map(int, input().split())
ans = (N // K)**3
if K % 2 == 0:
  m = K // 2
  cnt = 0
  i = m
  while i <= N:
    i += K
    cnt += 1
  ans += cnt**3
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
ans = 0
a = 1
while a <= N:
  b = K - a
  while b <= N:
    if b >=  1:
      c = K - a
      while c <= N:
        if c >= 1 and (b+c)%K == 0 and (c+a)%K == 0:
          ans += 1
        c += K
    b += K
  a += 1
print(ans)

Fixed submission:
from collections import deque
N, K = map(int, input().split())
ans = (N // K)**3
if K % 2 == 0:
  m = K // 2
  cnt = 0
  i = m
  while i <= N:
    i += K
    cnt += 1
  ans += cnt**3
print(ans)
Buggy python submission (verdict: Runtime Error):
r = int(raw_input())
if r < 1200:
  print "ABC"
elif r < 2800:
  print "ARC":
else:
  print "AGC"

Fixed submission:
r = int(raw_input())
if r < 1200:
  print "ABC"
elif r < 2800:
  print "ARC"
else:
  print "AGC"
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
a = map(int, raw_input().split())
ans = 0
i = 0
while i < N-1:
  if a[i] == a[i+1]:
    if i+1 < N and a[i] == a[i+2]:
      a[i+1] = 101+ans
      i += 3
    else:
      a[i] = 101+ans
      i += 2
    ans += 1
  else:
    i += 1
print ans



Fixed submission:
N = int(raw_input())
a = map(int, raw_input().split())
ans = 0
i = 0
while i < N-1:
  if a[i] == a[i+1]:
    if i+2 < N and a[i] == a[i+2]:
      a[i+1] = 101+ans
    else:
      a[i] = 101+ans
    ans += 1
    i += 2
  else:
    i += 1
print ans
Buggy python submission (verdict: Runtime Error):
def gcd(X,Y):
  if X < Y:
    tmp = X
    X = Y
    Y = tmp
  if Y == 0:
    return 0
  while X % Y != 0:
    r = X % Y
    X = Y
    Y = r
  return Y
T = int(raw_input())
Q = [map(int, raw_input().split()) for _ in range(T)]
for q in Q:
  A,B,C,D = q
  if B > A:
    print 'No'
  elif B > D:
    print 'No'
  elif B <= C:
    print 'Yes'
  else:
    A = A%B
    D = D%B
    g = gcd(B,D)
    maximum = B-g+A%g
    if maximum > C:
      print 'No'
    else:
      print 'Yes'
     


Fixed submission:
def gcd(X,Y):
  if X < Y:
    tmp = X
    X = Y
    Y = tmp
  if Y == 0:
    return 0
  while X % Y != 0:
    r = X % Y
    X = Y
    Y = r
  return Y
T = int(raw_input())
Q = [map(int, raw_input().split()) for _ in range(T)]
for q in Q:
  A,B,C,D = q
  if B > A:
    print 'No'
  elif B > D:
    print 'No'
  elif B <= C:
    print 'Yes'
  else:
    A = A%B
    D = D%B
    g = gcd(B,D)
    maximum = A if g == 0 else B-g+A%g
    if maximum > C:
      print 'No'
    else:
      print 'Yes'

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(X,Y):
  if X < Y:
    tmp = X
    X = Y
    Y = tmp
  if Y == 0:
    return 0
  while X % Y != 0:
    r = X % Y
    X = Y
    Y = r
  return Y
T = int(raw_input())
Q = [map(int, raw_input().split()) for _ in range(T)]
for q in Q:
  A,B,C,D = q
  if B > A:
    print 'No'
  elif B > D:
    print 'No'
  elif B <= C:
    print 'Yes'
  else:
    A = A%B
    D = D%B
    g = gcd(B,D)
    maximum = A
    if g != 0:
      while maximum < B:
        maximum += g
      maximum -= g
    if maximum > C:
      print 'No'
    else:
      print 'Yes'
     


Fixed submission:
def gcd(X,Y):
  if X < Y:
    tmp = X
    X = Y
    Y = tmp
  if Y == 0:
    return 0
  while X % Y != 0:
    r = X % Y
    X = Y
    Y = r
  return Y
T = int(raw_input())
Q = [map(int, raw_input().split()) for _ in range(T)]
for q in Q:
  A,B,C,D = q
  if B > A:
    print 'No'
  elif B > D:
    print 'No'
  elif B <= C:
    print 'Yes'
  else:
    A = A%B
    D = D%B
    g = gcd(B,D)
    maximum = A if g == 0 else B-g+A%g
    if maximum > C:
      print 'No'
    else:
      print 'Yes'
Buggy python submission (verdict: Runtime Error):
S = list(raw_input())
ans = 0
for s in S:
  ans += 1 if s == '+' else '-'
print ans


Fixed submission:
S = list(raw_input())
ans = 0
for s in S:
  ans += 1 if s == '+' else -1
print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
ans = 1000000
for A in range(1, 1+N/2):
  B = N - A
  a = 0
  b = 0
  for i in range(6)[::-1]:
    ta = tA/10**i
    tb = tB/10**i
    a += ta
    b += tb
    A -= ta*(10**i)
    B -= tb*(10**i)
  ans = min(ans, a+b)
print ans


Fixed submission:
N = int(raw_input())
ans = 1000000
for A in range(1, 1+N/2):
  B = N - A
  a = 0
  b = 0
  tA = A
  tB = B
  for i in range(6)[::-1]:
    ta = tA/10**i
    tb = tB/10**i
    a += ta
    b += tb
    tA -= ta*(10**i)
    tB -= tb*(10**i)
  ans = min(ans, a+b)
print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
S = list(raw_input())
ans = 0
for n in range(N):
 B = set(S[:n])
 E = set(S[n:])
 c = 0
 for b in B:
  if b in E:
   c += 1
 if c > ans:
  ans = c
print and

Fixed submission:
N = int(raw_input())
S = list(raw_input())
ans = 0
for n in range(N):
 B = set(S[:n])
 E = set(S[n:])
 c = 0
 for b in B:
  if b in E:
   c += 1
 if c > ans:
  ans = c
print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
S = list(raw_input())
D = [[0, 0]]
W = [0] * (N+2)
E = [0] * (N+2)
for i in range(N):
 if S[i] == 'W':
  W[i+1] = W[i]+1
for i in range(N)[::-1]:
 if S[i] == 'E':
  E[i] = E[i+1]+1
ans = N+1
for w, e in zip(W, E):
  if w+e < ans:
  ans = w+e
print ans


Fixed submission:
N = int(raw_input())
S = list(raw_input())
S = ['X']+S+['X']
D = [[0, 0]]
W = [0] * (N+2)
E = [0] * (N+2)
for i in range(1,N+2):
 W[i] = W[i-1]+(1 if S[i-1]== 'W' else 0)
for i in range(N+1)[::-1]:
 E[i] = E[i+1]+(1 if S[i+1]== 'E' else 0)
ans = N
for i in range(N):
  if W[i+1]+E[i+1] < ans:
   ans = W[i+1]+E[i+1]
print ans
Buggy python submission (verdict: Time Limit Exceeded):
s = raw_input()
K = int(raw_input())
subs = set()
for i in range(len(s)):
  for j in range(i, len(s)):
    subs.add(s[i:j+1])
subs = list(subs)
subs.sort()
print subs[K-1]


Fixed submission:
s = raw_input()
K = int(raw_input())
subs = set()
for i in range(len(s)):
  for j in range(i, i+K+1):
    subs.add(s[i:j+1])
subs = list(subs)
subs.sort()
print subs[K-1]
Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
A = map(long, raw_input().split())
ans = 0
for i in range(N):
  for j in range(N+1)[i+1:]:
    if sum(A[i:j]) == 0:
      ans += 1
print ans


Fixed submission:
N = int(raw_input())
A = map(long, raw_input().split())
ans = 0
s = 0L
S = [0L]
for a in A:
  s += a
  S.append(s)
S.sort()
c = S[0]
n = 1
for s in S[1:]:
  if c == s:
    n += 1
  else:
    ans += n*(n-1)/2
    n = 1
    c = s
ans += n*(n-1)/2
#for i in range(N):
#  for j in range(N+1)[i+1:]:
#    if sum(A[i:j]) == 0:
#      ans += 1
print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  t = s[a:]+s[:a]
  t_t = list(map(list, zip(*t)))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print ans*N


Fixed submission:
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  t = S[n:]+S[:n]
  t_t = list(map(list, zip(*t)))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print ans*N

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  isSym = True
  for i in range(N):
    for j in range(i,N):
      if S[i][j] != S[j][i]:
        isSym = False
        break
    if not isSym:
      break
  ans += 1 if isSym else 0
  s = S.pop()
  S.insert(0, s)
print ans*N


Fixed submission:
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  t = S[n:]+S[:n]
  t_t = list(map(list, zip(*t)))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print ans*N

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  isSym = True
  for i in range(N):
    for j in range(i,N):
      if S[i][j] != S[j][i]:
        isSym = False
  ans += 1 if isSym else 0
  s = S.pop()
  S.insert(0, s)
print ans*N


Fixed submission:
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  t = S[n:]+S[:n]
  t_t = list(map(list, zip(*t)))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print ans*N
Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(long, raw_input().split())
Sushi  = [map(long, raw_input().split()) for i in range(N)]
Sushi_rev = []
for s in Sushi[::-1]:
  Sushi_rev.append([C-s[0], s[1]])
Sushi.insert(0L, [0L, 0L])
Sushi_rev.insert(0L, [0L, 0L])
N += 1
ans = 0
cal_clock = []
tmp = 0
for i in Sushi:
  tmp += i[1]
  cal_clock.append(tmp)
cal_anticlock = []
tmp = 0
for i in Sushi_rev:
  tmp += i[1]
  cal_anticlock.append(tmp)
ans = 0
for a in range(N):
  for b in range(N-a):
    oa = Sushi[a][0]
    ob = Sushi_rev[b][0]
    eaten = cal_clock[a]+cal_anticlock[b]
    get_cal_oab = eaten - (2 * oa +ob)
    get_cal_oba = eaten - (2 * ob +oa)
    get_cal = eaten - (oa+ob) - (oa if oa < ob else ob)
    if get_cal > ans:
      ans = get_cal
print ans


Fixed submission:
N, C = map(long, raw_input().split())
Sushi_clock  = [map(long, raw_input().split()) for i in range(N)]
Sushi_anticlock = [[C-x[0], x[1]] for x in Sushi_clock[::-1]]
Sushi_clock.insert(0, [0L, 0L])
Sushi_anticlock.insert(0, [0L, 0L])
N += 1
ans = 0
eatcal = 0
getcal_clock_max = 0
getcal_clock_max_oa = 0
getcal_clock_maxes = []
getcal_clock2_max = 0
getcal_clock2_max_oa = 0
getcal_clock2_maxes = []
for i in Sushi_clock:
  eatcal += i[1]
  getcal = eatcal-i[0]
  getcal_clock_max_oa = i[0] if getcal > getcal_clock_max else getcal_clock_max_oa
  getcal_clock_max = getcal if getcal > getcal_clock_max else getcal_clock_max
  getcal_clock_maxes.append([getcal_clock_max,getcal_clock_max_oa])
  getcal2 = eatcal-i[0]*2
  getcal_clock2_max_oa = i[0] if getcal2 > getcal_clock2_max else getcal_clock2_max_oa
  getcal_clock2_max = getcal2 if getcal2 > getcal_clock2_max else getcal_clock2_max
  getcal_clock2_maxes.append([getcal_clock2_max,getcal_clock2_max_oa])
eatcal = 0
for anti, oa, oa2 in zip(Sushi_anticlock, getcal_clock_maxes[::-1], getcal_clock2_maxes[::-1]):
  eatcal += anti[1]
  getcal_oa2 = eatcal-anti[0]+oa2[0]
  getcal_ob2 = eatcal-anti[0]*2+oa[0]
  ans = max(ans, getcal_oa2, getcal_ob2)
print ans
Buggy python submission (verdict: Runtime Error):
import itertools
N = int(input())
nums = {}
for _ in range(N):
  s = input()[0]
  if s in nums.keys():
    nums[s] += 1
  else:
    nums[s] = 1
ans = 0
for C in itertools.combinations(list("MARCH"),3):
  tmp = 1
  for c in C:
    if c in nums.keys():
      tmp *= nums[c]
    else:
      tmp = 0
  ans += tmp
print(ans)



Fixed submission:
import itertools
N = int(raw_input())
S = [raw_input() for _ in range(N)]
march = list("MARCH")
I = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in S:
  if s[0] in I.keys():
    I[s[0]] += 1
for i in march:
  if I[i] < 1:
    I.pop(i)
K = list(I.keys())
ans = long(0)
for c in list(itertools.combinations(K, 3)):
    ans += I[c[0]]*I[c[1]]*I[c[2]]
print ans
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
M = 18
left = 0
right = N-1
print(left)
l = input()
if l != "Vacant":
  print(right)
  r = input()
  if r != "Vacant":
    notOK = True
    while notOK:
      middle = (r+l)//2
      print(middle)
      s = input()
      if s == "Vacant":
        notOK = False
        break
      elif (middle-left)%2 == 0 and l != s:
        right = middle
        r = s
      elif (middle-left)%2 == 1 and l == s:
        right = middle
        r = s
      elif (right-middle)%2 == 0 and s != r:
        left=middle
        l = s
      elif (right-middle)%2 == 1 and r == s:
        left = middle
        r = s


Fixed submission:
N = int(input())
M = 18
left = 0
right = N-1
print(left)
l = input()
if l != "Vacant":
  print(right)
  r = input()
  if r != "Vacant":
    notOK = True
    while notOK:
      middle = (right+left)//2
      print(middle)
      s = input()
      if s == "Vacant":
        notOK = False
        break
      elif (middle-left)%2 == 0 and l != s:
        right = middle
        r = s
      elif (middle-left)%2 == 1 and l == s:
        right = middle
        r = s
      else:
        left=middle
        l = s
Buggy python submission (verdict: Time Limit Exceeded):
isprimes = [True]*(10**5+1)
isprimes[0] = False
isprimes[1] = False
for i in range(2, 10**5+1):
  if isprimes[i]:
    j = i**2
    while j < 10**5+1:
      isprimes[j] = False
      j += i
Q = int(input())
for _ in range(Q):
  c = 0
  l, r = map(int, input().split())
  for x in range(l, r+1, 2):
    if isprimes[x] and isprimes[(x+1)//2]:
      c += 1
  print(c)


Fixed submission:
isprimes = [True]*(10**5+1)
isprimes[0] = False
isprimes[1] = False
for i in range(2, 10**5+1):
  if isprimes[i]:
    j = i**2
    while j < 10**5+1:
      isprimes[j] = False
      j += i
islikes = [False]*(10**5+1)
for i in range(3, 10**5+1, 2):
  if isprimes[i] and isprimes[(i+1)//2]:
    islikes[i] = True
ruiseki = [0]*(10**5+1)
for i in range(1, 10**5+1):
  ruiseki[i] = ruiseki[i-1]+(1 if islikes[i] else 0)
Q = int(input())
for _ in range(Q):
  l, r = map(int, input().split())
  print(ruiseki[r]-ruiseki[l-1])
Buggy python submission (verdict: Runtime Error):
def dfs(prev, now, fromK, t, d):
  d[now] = fromK
  for nl in (t[now]):
    if nl[0] != prev:
      dfs(now, nl[0], fromK+nl[1], t, d)

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





Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(prev, now, fromK, t, d):
  d[now] = fromK
  for nl in (t[now]):
    if nl[0] != prev:
      dfs(now, nl[0], fromK+nl[1], t, d)

N = int(input())
T  = [[] for _ in range(N+1)]
for _ in range(N-1):
  a, b, l = map(int, input().split())
  T[a].append([b,l])
  T[b].append([a, l])
Q, K = map(int, input().split())
D = [0] * (N+1)
dfs(-1, K, 0, T, D)
for _ in range(Q):
  x, y = map(int, input().split())
  print(D[x]+D[y])
Buggy python submission (verdict: Runtime Error):
#解放2
from decimal import Decimal
from floor import math
a, b = input().split()
a = int(a)
b = Decimal(b)
print(floor(a*b))

Fixed submission:
#a, b = map(float, input().split())

a, b = input().split()
from decimal import Decimal
import math
print(math.floor(int(a)*Decimal(b)))

Buggy python submission (verdict: Runtime Error):
a, b = input().split()
b.replace(".", "")
print(int(a)*int(b)//100)

Fixed submission:
#a, b = map(float, input().split())

a, b = input().split()
from decimal import Decimal
import math
print(math.floor(int(a)*Decimal(b)))

Buggy python submission (verdict: Runtime Error):
#a, b = map(float, input().split())

a, b = input().split()

from decimal import Decimal
import math
print(math.floor(int(a)*Decimal(b))


Fixed submission:
#a, b = map(float, input().split())

a, b = input().split()
from decimal import Decimal
import math
print(math.floor(int(a)*Decimal(b)))
Buggy python submission (verdict: Runtime Error):
import collections

if __name__ == '__main__':
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for i in range(m)]

    ways = [[] for i in range(n+1)]

    for i in l:
        ways[i[0]].append(i[1])
        ways[i[1]].append(i[0])

    #print(ways)

    q = collections.deque()

    ans = [-1] * n # 道案内
    ans[0] = 0

    q.append(1)

    while(len(q) != 0):
        item = q.popleft()
        for i in ways[item]:
            if ans[i-1] == -1:
                ans[i-1] = item
                q.append(i)
                #print(ans , i , item)

    if -1 in ans:
        print("No")

    else:
        for i in range(1,n):
        print("Yes")
        print(ans[i])


Fixed submission:
import collections

if __name__ == '__main__':
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for i in range(m)]

    ways = [[] for i in range(n+1)]

    for i in l:
        ways[i[0]].append(i[1])
        ways[i[1]].append(i[0])

    #print(ways)

    q = collections.deque()

    ans = [-1] * n # 道案内
    ans[0] = 0

    q.append(1)

    while(len(q) != 0):
        item = q.popleft()
        for i in ways[item]:
            if ans[i-1] == -1:
                ans[i-1] = item
                q.append(i)
                #print(ans , i , item)

    if -1 in ans:
        print("No")
    else:
        print("Yes")
        for i in range(1,n):
            print(ans[i])
Buggy python submission (verdict: Runtime Error):

def looptime(n, a):
    for i in range(n):
        loop = 0
        start = i
        now = i

        time = 0

        while(loop < n):
            now = a[now]
            loop += 1
            now -= 1

            if now == start:
                return i+1, loop

def start_loop(goal, a):
    loop = 0
    now = 0

    time = 0

    while(loop < n):
        now = a[now]
        loop += 1
        now -= 1

        if now == goal-1:
            return loop

if __name__ == '__main__':

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    start, loop = looptime(n, a)
    how = start_loop(start, a)
    point = k%loop

    #print(start, loop, point, how)

    if how == loop:
        # startからループ開始
        time = 0
        now = 0
        while(time < point):
            now = a[now]
            now -= 1
            time += 1
        print(now+1)

    else:
        # 途中からループ開始
        if how > k:
            time = 0
            now = 0
            while(time < k):
                now = a[now]
                now -= 1
                time += 1
            print(now+1)

        else:
            time = 0
            now = start-1
            point = (point+how)%loop
            while(time < point-1):
                now = a[now]
                now -= 1
                time += 1
            print(now+1)


Fixed submission:
if __name__ == '__main__':

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

    root = [] # 訪れた頂点をメモ
    already = [-1] * (n+1) # rootのindexのメモ　と　すでに訪れたか

    c = 1# 周期
    l = 0# 例外部分のながさ

    v = 1#頂点は1 ここから遷移
    while(already[v] == -1): # すでに書いてあれば訪れている。かつ周期の起点となる場所
        already[v] = len(root) #訪れたら何回目かを記述
        root.append(v)
        v = a[v-1]

    c = len(root) - already[v]
    l = already[v]

    if k < l:#例外部分のながさ
        ans = root[k]
    else:# 周期にいるなら
        k -= l
        ans = root[k%c+l]

    print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

if s = "ARC":
    print("ABC")
elif s = "ABC":
    print("ARC")


Fixed submission:
s = input()

if s == "ARC":
    print("ABC")
elif s == "ABC":
    print("ARC")

Buggy python submission (verdict: Runtime Error):
s = input()

if s = "ARC":
    print("ABC")
elif s = "ABC"
    print("ARC")


Fixed submission:
s = input()

if s == "ARC":
    print("ABC")
elif s == "ABC":
    print("ARC")