Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input()
Q = int(input())
reverse = False
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse = not reverse 
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if (F == 1 and reverse == False) or (F == 2 and reverse == True):
            S = C + S
        elif (F == 2 and reverse == False) or (F == 1 and reverse == True):
            S = S + C

if reverse%2 == 1:
    S = S[::-1]


print(S)
print('\n')


### FIXED CODE ###

S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')
### BUGGY CODE ###

# https://atcoder.jp/contests/abc125/tasks/abc125_c

import itertools
from collections import Counter
from collections import defaultdict
import bisect

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

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

    answers = []
    # half
    m = N // 2
    ans1 = 0
    for i in range(m):
        ans1 = gcd(A[i], ans1)

    for i in range(m, N):
        ans = ans1
        for j in range(m, N):
            if i == j:
                continue
            ans = gcd(A[j], ans)
        answers.append(ans)

    ans2 = 0
    for i in range(m, N):
        ans2 = gcd(A[i], ans2)

    for i in range(m):
        ans = ans2
        for j in range(m):
            if i == j:
                continue
            ans = gcd(A[j], ans)
        answers.append(ans)

    print(max(answers))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# https://atcoder.jp/contests/abc125/tasks/abc125_c

import itertools
from collections import Counter
from collections import defaultdict
import bisect

memo = {}


def gcd(a, b):
    if a in memo:
        if b in memo[a]:
            return memo[a][b]
    ans = gcd_core(a, b)
    if a in memo:
        memo[a][b] = ans
    else:
        memo[a] = {}
        memo[a][b] = ans
    return ans


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


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

    ming = 0

    cand = []

    for i in range(N):
        temp = gcd(A[i], ming)
        # print(temp)
        if temp != ming:
            cand.append(i)
        ming = temp

    # print(index)

    answers = []
    for c in cand:
        ans1 = 0
        for i in range(N):
            if i != c:
                ans1 = gcd(A[i], ans1)
        answers.append(ans1)

    print(max(answers))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from sys import stdin
import sys
import copy
sys.setrecursionlimit(200000)
N,M,K=list(map(int,input().split()))
counter=[[None,None] for i in range(N+1)]
friend_list=[set() for _ in range(N+1)]
block_list=[set() for _ in range(N+1)]
def friend_tansaku(i,j):
    color.add(j)
    for friend in friend_list[j]:
        if friend not in color :
            friend_tansaku(i,friend)





for _ in range(M):
   a,b= list(map(int, input().split()))
   friend_list[a].add(b)
   friend_list[b].add(a)
for _ in range(K):
    a, b = list(map(int, input().split()))
    block_list[a].add(b)
    block_list[b].add(a)
for i in range(1,N+1):

    color =set()
    if counter[i][0] is None:
        friend_tansaku(i,i)
        cnt=len(color)
        color=tuple(color)
        for aa in color:
            counter[aa]=[color,cnt]
    color,cnt =set(counter[i][0]),counter[i][1]
    for k in block_list[i]:
        if k not in color:
            cnt+=1

    count=cnt-(len(friend_list[i])+len(block_list[i]))-1
    if i==N:print(count)
    else:print(count,end=" ")

### FIXED CODE ###

from sys import stdin
import sys
import copy
sys.setrecursionlimit(200000)
N,M,K=list(map(int,input().split()))
counter=[[None,None] for i in range(N+1)]
friend_list=[set() for _ in range(N+1)]
block_list=[set() for _ in range(N+1)]
def friend_tansaku(i,j):
    color.add(j)
    cnt[0]+=1
    for friend in friend_list[j]:
        if friend not in color :
            friend_tansaku(i,friend)





for _ in range(M):
   a,b= list(map(int, input().split()))
   friend_list[a].add(b)
   friend_list[b].add(a)
for _ in range(K):
    a, b = list(map(int, input().split()))
    block_list[a].add(b)
    block_list[b].add(a)
for i in range(1,N+1):
    cnt=[0]
    color =set()
    if counter[i][0] is None:
        friend_tansaku(i,i)
        cnt=cnt[0]
        for aa in color:
            counter[aa]=[color,cnt]
    color,cnt =counter[i][0],counter[i][1]
    for k in block_list[i]:
        if k not in color:
            cnt+=1

    count=cnt-(len(friend_list[i])+len(block_list[i]))-1
    if i==N:print(count)
    else:print(count,end=" ")
### BUGGY CODE ###

N = int(input())
T = [[] for i in range(N)]
for i in range(N):
    a = list(input())
    T[i] = a
num = 0
for i in range(N):
    flag = True
    for j in range(N):
        for k in range(N):
            q = k + i
            p = j + i
            if q >= N:
                q -= N
            if p >= N:
                p -= N
            if j == q:
                continue
            if T[j][q] != T[k][p]:
                flag = False

    if flag:
        num += 1

print(num * N)

### FIXED CODE ###

N = int(input())
T = [[] for i in range(N)]
for i in range(N):
    a = list(input())
    T[i] = a
num = 0
for i in range(N):
    flag = True
    for j in range(N):
        for k in range(N):
            q = k + i
            p = j + i
            if q >= N:
                q -= N
            if p >= N:
                p -= N
            if j == q:
                continue
            if T[j][q] != T[k][p]:
                flag = False

    if flag:
        num += 1

print(num * N)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
tempA = [int(i) for i in input().split()]
tempB = [int(i) for i in input().split()]
A = [0] * (N+1)
for i in range(1, N+1):
    A[i] = A[i-1] + tempA[i-1]
B = [0] * (M+1)
for i in range(1, M+1):
    B[i] = B[i-1] + tempB[i-1]

ans = 0
for a in range(N+1):
    if A[a] > K:
        break
    for b in range(M+1):
        if A[a] + B[b] <= K:
            ans = max(ans, a+b)
        else:
            break

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
tempA = [int(i) for i in input().split()]
tempB = [int(i) for i in input().split()]
A = [0] * (N+1)
for i in range(1, N+1):
    A[i] = A[i-1] + tempA[i-1]
B = [0] * (M+1)
for i in range(1, M+1):
    B[i] = B[i-1] + tempB[i-1]

ans = 0
for a in range(N+1):
    if A[a] > K:
        break
    for b in range(ans-a+1, M+1):
        if A[a] + B[b] <= K:
            ans = max(ans, a+b)
        else:
            break

print(ans)
### BUGGY CODE ###

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
    
N, M, K = map(int, input().split())

ans = 0

for i in range(1, M):
    ans += i * (M-i) * N**2 
for i in range(1, N):
    ans += i * (N-i) * M**2

ans *= cmb(N*M-2, K-2)

print(int(ans % (10**9+7)))



### FIXED CODE ###

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

N, M, K = map(int, input().split())

ans = 0

for i in range(1, M):
    ans += (i * (M-i) * N**2) % (10**9 + 7) 
for i in range(1, N):
    ans += (i * (N-i) * M**2) % (10**9 + 7)

ans *= comb(N*M-2 , K-2, 10**9+7)

print(int(ans % (10**9+7)))
### BUGGY CODE ###

N, X, Y = map(int, input().split())

result = []
for i in range(1, N+1):
    for j in range(i, N+1):
        if j<=X:
            result.append(j-i)
        else:
            jy = abs(Y-j)
            ix = abs(X-i)
            if (j-i)<=(jy+ix+1):
                result.append(j-i)
            else:
                result.append(jy+ix+1)
            
for i in range(N-1):
    print(result.count(i+1))

### FIXED CODE ###

from itertools import combinations
N, X, Y = map(int, input().split())

result = [0]*N
for i, j in combinations(range(1, N+1), 2):
    mins = min([j-i, abs(Y-j)+abs(X-i)+1])
    result[mins] += 1
    
for i in range(1, N):
    print(result[i])
### BUGGY CODE ###

s=list(input())
i=0
while i<len(s)-1: #重複を削除
    if s[i]==s[i+1]:
        s.remove(s[i])
    else:
        i+=1
print(len(s)-1)

### FIXED CODE ###

s=input()
cnt=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]: cnt+=1
print(cnt)
### BUGGY CODE ###

from operator import mul
from functools import reduce
import itertools

N = int(input())

# N = i*jをみつける
# (i, j)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def remove_dup_list(tmplist):
    return list(map(list, set(map(tuple, tmplist))))


prime_list = prime_factorize(N)


#print(prime_list)


import copy
if len(prime_list)<=1:
    result = N-1
else:
    result = 10**12


    
for i in range(len(prime_list)//2):
    # i個抽出
    tmp = list(itertools.combinations(prime_list, i+1))
    tm = map(list, tmp)
    tm = remove_dup_list(tm)
    for _ in tm:
        temp_origin_list = copy.copy(prime_list)
        for item in _:
            temp_origin_list.remove(item)
        #print(_, temp_origin_list)
        result = min(result, reduce(mul, _) + reduce(mul, temp_origin_list) - 2)
print(result)

### FIXED CODE ###

import math
N = int(input())
result = N
for i in range(1, int(math.sqrt(N))+2):
    if N % i == 0:
        result = min(result, i - 1 + N//i - 1)
print(result)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
l = list()
for i in range(N):
    l.append((p[i] * (p[i] + 1)) / 2 / p[i])

for i in range(N - K + 1):
    ans = max(ans, sum(l[i:i + K]))

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

N, K = map(int, input().split())
p = list(map(int, input().split()))

l = [0] * (N + 1)
l[0] = (p[0] + 1) / 2
for i in range(1, N + 1):
    l[i] = l[i - 1] + (p[i - 1] + 1) / 2

ans = 0
for i in range(N - K + 1):
    if ans < l[i + K] - l[i]:
        ans = l[i + K] - l[i]

print(ans)
### BUGGY CODE ###

N = int(input())
#S = [input() for i in range(N)]
S=[]
alpha_dic={"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":[]}
ans_list = []
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    #S.append(''.join(temp))
    #alpha_dic[temp[0]].append(i) 
    alpha_dic[temp[0]].append(''.join(temp)) 

for key,value in alpha_dic.items():
    set_S = set(value)
    for s in set_S:
        a = value.count(s)
        ans += a*(a-1)/2

print(round(ans))

### FIXED CODE ###

N = int(input())
#S = [input() for i in range(N)]
S=[]
ans_dic={}
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    temp = ''.join(temp)
    #S.append(''.join(temp))
    #alpha_dic[temp[0]].append(i) 
    if temp in ans_dic:
        ans_dic[temp] += 1
    else:
        ans_dic[temp] = 1
    
for key,value in ans_dic.items():
    ans += value*(value-1)/2

print(round(ans))
### BUGGY CODE ###

from bisect import bisect_left
a,b,q=map(int,input().split())
s=[]
t=[]
x=[]
s.append(-float("inf"))
t.append(-float("inf"))
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
s.append(float("inf"))
t.append(float("inf"))
s.sort()
t.sort()
for i in range(q):
    x=int(input())
    ans=float("inf")
    tmp_s_1=bisect_left(s,x)-1
    tmp_s_2=tmp_s_1+1
    tmp_s_1_t=bisect_left(t,s[tmp_s_1])
    tmp_s_2_t=bisect_left(t,s[tmp_s_2])
    ans=min(abs(x-s[tmp_s_1])+abs(s[tmp_s_1]-t[tmp_s_1_t-1]), abs(x-s[tmp_s_1])+abs(s[tmp_s_1]-t[tmp_s_1_t]), abs(x-s[tmp_s_2])+abs(s[tmp_s_2]-t[tmp_s_2_t-1]), abs(x-s[tmp_s_2])+abs(s[tmp_s_2]-t[tmp_s_2_t]))
    tmp_t_1=bisect_left(t,x)-1
    tmp_t_2=tmp_t_1+1
    tmp_t_1_s=bisect_left(s,t[tmp_t_1])
    tmp_t_2_s=bisect_left(s,t[tmp_t_2])
    ans=min(ans, abs(x-t[tmp_t_1])+abs(t[tmp_t_1]-s[tmp_t_1_s-1]), abs(x-t[tmp_t_1])+abs(t[tmp_t_1]-s[tmp_t_1_s]), abs(x-t[tmp_t_2])+abs(t[tmp_t_2]-s[tmp_t_2_s-1]), abs(x-t[tmp_t_2])+abs(t[tmp_t_2]-s[tmp_t_2_s]))
    print(ans)

### FIXED CODE ###

from bisect import bisect_left
a,b,q=map(int,input().split())
s=[]
t=[]
x=[]
s.append(-10**12)
t.append(-10**12)
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
s.append(10**12)
t.append(10**12)
for i in range(q):
    x=int(input())
    tmp_s=bisect_left(s,x)-1
    tmp_s_1=s[tmp_s]
    tmp_s_2=s[tmp_s+1]
    tmp_t=bisect_left(t,x)-1
    tmp_t_1=t[tmp_t]
    tmp_t_2=t[tmp_t+1]
    print(min(abs(x-tmp_s_1)+abs(tmp_s_1-tmp_t_1),
    abs(x-tmp_s_1)+abs(tmp_s_1-tmp_t_2),
    abs(x-tmp_s_2)+abs(tmp_s_2-tmp_t_1),
    abs(x-tmp_s_2)+abs(tmp_s_2-tmp_t_2),
    abs(x-tmp_t_1)+abs(tmp_t_1-tmp_s_1),
    abs(x-tmp_t_1)+abs(tmp_t_1-tmp_s_2),
    abs(x-tmp_t_2)+abs(tmp_t_2-tmp_s_1),
    abs(x-tmp_t_2)+abs(tmp_t_2-tmp_s_2)))
### BUGGY CODE ###

N, X = map(int, input().split())
x = [int(i) for i in input().split()]

y = [abs(X-i) for i in x]
D = min(y)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

### FIXED CODE ###

import collections

N, X = map(int, input().split())
x = [int(i) for i in input().split()]

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
z = [(y[i+1] - y[i]) for i in range(0, N)]
zz = []
for i in range(0, N):
    if z[i] != 0 and not(z[i] in zz):
        zz.append(z[i])
a = collections.Counter(zz).keys()
D = min(a)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)
### BUGGY CODE ###

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

dp = [0]*(10**6+1)

for i in arr:
    for j in range(i, len(dp), i):
        if j in arr:
            dp[j] += 1
print(dp.count(1))

### FIXED CODE ###

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

dp = [0]*(10**6+1)

for i in sorted(arr):
    dp[i] += 1
    if dp[i] == 1:
        for j in range(2*i, len(dp), i):
            dp[j] += 2
print(dp.count(1))
### BUGGY CODE ###

n = int(input())
a = [0]*n
cnt = 0
for i in range(1,int((n-3)**1/2 //1)):
  for j in range(1,int((n-i**2)**1/2 //1)):
    for k in range(1,int((n-i**2-j**2)**1/2 //1)):
      b = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if b <= n:
        a[b-1] += 1

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



### FIXED CODE ###

n = int(input())
a = [0]*n
cnt = 0
for i in range(1,100):
  for j in range(1,100):
    for k in range(1,100):
      b = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if b <= n:
        a[b-1] += 1

for i in a:
  print(i)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    H,N = map(int,input().split())
    INF = 10**10
    at = []
    for _ in range(N):
        A,B = map(int,input().split())
        at.append((A,B))
        
    at.sort(key=itemgetter(0))
    
    dp = [INF for _ in range(H+1)]
    dp[0] = 0
    for i in range(N):
        use,a = at[i]
        for j in range(1,H+1):
            if j < use:
                dp[j] = min(dp[j],a)
            else:
                dp[j] = min(dp[j],dp[j-use]+a)
        
    print(dp[-1])
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    H,N = map(int,input().split())
    x = []
    ma = 0
    for _ in range(N):
        a,b = map(int,input().split())
        ma = max(ma,a)
        x.append((a,b))
    INF = 10**18
    
    dp = [INF for _ in range(H+ma+1)]
    dp[0] = 0
    for i in range(1,H+ma+1):
        dp[i] = min(dp[i-a]+b for a,b in x)
    
    print(min(dp[H:]))

if __name__ == "__main__":
    main()
### BUGGY CODE ###


#from collections import defaultdict
#from pprint import pprint
#from collections import deque
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。
#import numpy as np
#import math
# = map(int,input().split())

# = list(map(int,input().split()))

# = [list(map(int,input().split())) for _ in range(XXXX)]

def func(i):
    if i == 0:
        return 0
    elif i == 1:
        return d
    elif i in memo:
        return memo[i]
    else:
        min_val = int(min(
            d*i,
            d*abs(i-i//2*2) + a + func(i//2),
            d*abs(i-(i+1)//2*2) + a + func((i+1)/2),
            d*abs(i-i//3*3) + b + func(i//3),
            d*abs(i-(i+2)//3*3) + b + func((i+2)//3),
            d*abs(i-i//5*5) + c + func(i//5),
            d*abs(i-(i+4)//5*5) + c + func((i+4)//5)
        ))

    memo[i] = min_val
    return min_val



t = int(input())

nabcd = [list(map(int,input().split())) for _ in range(t)]


for i in range(t):
    n = nabcd[i][0]
    a = nabcd[i][1]
    b = nabcd[i][2]
    c = nabcd[i][3]
    d = nabcd[i][4]

    memo = {}


    print(func(n))
    #print(memo)


### FIXED CODE ###


#from collections import defaultdict
#from pprint import pprint
#from collections import deque
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。
#import numpy as np
#import math
# = map(int,input().split())

# = list(map(int,input().split()))

# = [list(map(int,input().split())) for _ in range(XXXX)]

def func(i):
    if i == 0:
        return 0
    elif i == 1:
        return d
    elif i in memo:
        return memo[i]
    else:
        min_val = int(min(
            d*i,
            d*abs(i-i//2*2) + a + func(i//2),
            d*abs(i-(i+1)//2*2) + a + func((i+1)//2),
            d*abs(i-i//3*3) + b + func(i//3),
            d*abs(i-(i+2)//3*3) + b + func((i+2)//3),
            d*abs(i-i//5*5) + c + func(i//5),
            d*abs(i-(i+4)//5*5) + c + func((i+4)//5)
        ))

    memo[i] = min_val
    return min_val



t = int(input())

nabcd = [list(map(int,input().split())) for _ in range(t)]


for i in range(t):
    n = nabcd[i][0]
    a = nabcd[i][1]
    b = nabcd[i][2]
    c = nabcd[i][3]
    d = nabcd[i][4]

    memo = {}


    print(func(n))
    #print(memo)
### BUGGY CODE ###


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

g=[[] for i in range(n)]
cost = [[float("inf") for i in range(n)] for i in range(n)] 

for i in range(m):
    ai,bi=map(int, input().split())
    g[ai-1].append(bi-1)
    g[bi-1].append(ai-1)
    cost[ai-1][bi-1] = 1
    cost[bi-1][ai-1] = 1
    
seen=[False]*n
    
def dfs(g,v):
    seen[v]=True    
    for nv in g[v]:
        if seen[v]:
            continue
        dfs(g,nv)

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################
        
icnt=0
for v in range(n):
    if seen[v]:
        continue
    dfs(g,v)
    icnt+=1
    
if icnt!=n:
    print("No")
else:
    print("Yes")

    q=dijkstra(0,n,m,cost)
    r=[0]*n
    for i in range(1,len(q)):
        qmin=10**10
        for j in g[i]:
            if qmin>q[j]:
                qmin=q[j]
                r[i]=j
#            print("1:",g[i],j,q[j],qmin)
        print(r[i]+1)
                

### FIXED CODE ###

import sys
from collections import deque

icase=0
if icase==0:
    n,m=map(int,input().split())
    g = [[] for _ in range(n)]
    for i in range(m):
        ai,bi=map(int,input().split())
        g[ai-1].append(bi-1)
        g[bi-1].append(ai-1)
elif icase==1:
    n,m=4,4
    g=[[1], [0, 2, 3], [1, 3], [2, 1]]
elif icase==2:
    n,m=6,9
    g=[[5, 4], [3, 5], [3, 4], [2, 1, 5, 4], [2, 0, 3, 5], [0, 3, 1, 4]]

q=deque([0])

stack=[0]
parent=[-1]*n
parent[0]=0
dist=[-1]*n
dist[0]=0
while q:
    state = q.popleft()
#    print("--- q:",q,"state:",state,"g:",g[state],"p:",parent)
    for v in g[state]:
#        print("  state:",state,"v:",v,"q:",q)
#        if parent[state] == v:
        if parent[v] !=-1:
            continue
        else:
#            print("parent:",parent,"xx:",xx,"stack",stack)
            parent[v]=state
            dist[v]=dist[state]+1
            q.append(v)
#            print(" state:",state,"v:",v,"parent:",parent,"stack",stack,"dist[v]",dist[v])
for i in range(1,n):
    if parent[i]==-1:
        print("No")
        sys.exit()

print("Yes")
for i in range(1,n):
#    print(i+1,dist[i])    
    print(parent[i]+1)