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

s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  p = np
print(p[5] % divisor)


### FIXED CODE ###

s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print(p[5] % divisor)
### BUGGY CODE ###

n, m = map(int, input().split())
line = set(range(1, n + 1))
for i in range(m):
    l, r = map(int, input().split())
    line &= set(range(l, r + 1))

print(len(line))


### FIXED CODE ###

n, m = map(int, input().split())
l_max = 1
r_min = 10 ** 5
for i in range(m):
    l, r = map(int, input().split())
    l_max = max(l, l_max)
    r_min = min(r, r_min)

print(max(0, r_min - l_max + 1))
### BUGGY CODE ###

# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W
# ty geekforgeeks
def knapSack(W, wt, val, n, avoid): 
    K = [[0 for x in range(W+1)] for x in range(n+1)] 
  
    # Build table K[][] in bottom up manner 
    for i in range(n+1): 
        for w in range(W+1):
            if avoid != None:
                index = i if i <= avoid else i + 1
            else:
                index = i
            if i==0 or w==0: 
                K[i][w] = 0
            elif wt[index-1] <= w: 
                K[i][w] = max(val[index-1] + K[i-1][w-wt[index-1]],  K[i-1][w]) 
            else: 
                K[i][w] = K[i-1][w] 
  
    return K[n][W] 

N, T = map(int, input().split())
wts = [None for i in range(N)]
val = [None for i in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    wts[i] = a
    val[i] = b

best = knapSack(T, wts, val, N, None)
for i in range(N):
    best = max(best, knapSack(T-1, wts, val, N - 1, i) + val[i])
print(best)



### FIXED CODE ###

# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W
# ty geekforgeeks
def knapSack(W, wt, val, n): 
    K = [[0 for x in range(W+1)] for x in range(n+1)] 
  
    # Build table K[][] in bottom up manner 
    for i in range(n+1): 
        for w in range(W+1):
            if i==0 or w==0: 
                K[i][w] = 0
            elif wt[i-1] <= w: 
                K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]) 
            else: 
                K[i][w] = K[i-1][w] 
        res = K[n][W] 
      
    w = W
    used = [False for i in range(N)]
    for i in range(n, 0, -1): 
        if res <= 0: 
            break
        # either the result comes from the 
        # top (K[i-1][w]) or from (val[i-1] 
        # + K[i-1] [w-wt[i-1]]) as in Knapsack 
        # table. If it comes from the latter 
        # one/ it means the item is included. 
        if res == K[i - 1][w]: 
            continue
        else: 
            # This item is included. 
            used[i - 1] = True
              
            # Since this weight is included 
            # its value is deducted 
            res = res - val[i - 1] 
            w = w - wt[i - 1] 
    return K[n][W], used

N, T = map(int, input().split())
wts = [None for i in range(N)]
val = [None for i in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    wts[i] = a
    val[i] = b

best, _ = knapSack(T, wts, val, N)
other, used = knapSack(T - 1, wts, val, N)
add = 0
for i, wasUsed in enumerate(used):
    if not wasUsed: add = max(add, val[i])
print(max(best, other + add))
### BUGGY CODE ###

# coding: utf-8
# Your code here!
n=int(input())
a=[0]
cnt=[0]
ans=True
for i in range(n):
    s=input()
    for j in range(len(a)):
        if a[j]==s:
            cnt[j]+=1
            ans=False
        if ans:
            cnt.append(1)
            a.append(s)
    ans=True
n=int(input())
for i in range(n):
    s=input()
    for j in range(len(a)):
        if a[j]==s:
            cnt[j]-=1

print(max(cnt))


### FIXED CODE ###

s=[input() for _ in range(int(input()))]
t=[input() for _ in range(int(input()))]
cnt=[0]*(len(s)+1)
for i in range(len(s)):
    cnt[i]=s.count(s[i])-t.count(s[i])
print(max(cnt))
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
a = [[] for _ in range(h)]
for i in range(h):
    a[i] = list(input())

dis = [[1000000 for _ in range(w)] for _ in range(h)]
queue = deque([])

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            dis[i][j] = 0
            queue.append([i, j])

while queue:
    now = deque.popleft(queue)
    if now[0] != 0:
        if dis[now[0]-1][now[1]] == 1000000:
            dis[now[0]-1][now[1]] = dis[now[0]][now[1]]+1
            queue.append([now[0]-1, now[1]])
            
    if now[0] != h-1:
        if dis[now[0]+1][now[1]] == 1000000:
            dis[now[0]+1][now[1]] = dis[now[0]][now[1]]+1
            queue.append([now[0]+1, now[1]])
            
    if now[1] != 0:
        if dis[now[0]][now[1]-1] == 1000000:
            dis[now[0]][now[1]-1] = dis[now[0]][now[1]]+1
            queue.append([now[0], now[1]-1])
            
    if now[1] != w-1:
        if dis[now[0]][now[1]+1] == 1000000:
            dis[now[0]][now[1]+1] = dis[now[0]][now[1]]+1
            queue.append([now[0], now[1]+1])

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, dis[i][j])

print(ans)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
a = [[] for _ in range(h)]
for i in range(h):
    a[i] = list(input())

dis = [[1000000 for _ in range(w)] for _ in range(h)]
queue = deque([])

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            dis[i][j] = 0
            queue.append([i, j])

while queue:
    now = deque.popleft(queue)
    if now[0] != 0:
        if dis[now[0]-1][now[1]] == 1000000:
            dis[now[0]-1][now[1]] = dis[now[0]][now[1]]+1
            queue.append([now[0]-1, now[1]])
            
    if now[0] != h-1:
        if dis[now[0]+1][now[1]] == 1000000:
            dis[now[0]+1][now[1]] = dis[now[0]][now[1]]+1
            queue.append([now[0]+1, now[1]])
            
    if now[1] != 0:
        if dis[now[0]][now[1]-1] == 1000000:
            dis[now[0]][now[1]-1] = dis[now[0]][now[1]]+1
            queue.append([now[0], now[1]-1])
            
    if now[1] != w-1:
        if dis[now[0]][now[1]+1] == 1000000:
            dis[now[0]][now[1]+1] = dis[now[0]][now[1]]+1
            queue.append([now[0], now[1]+1])

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, dis[i][j])

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

import numpy as np

n, a = map(int, input().split())
x = list(map(int, input().split()))
x_max = max(x)
x_sum = sum(x)
if x_max < a:
    print(0)
else:
    dp = np.zeros([n + 1, n + 1, x_sum + 1], dtype=int)
    dp[0, 0, 0] = 1
    for i in range(1, n + 1):
        for j in range(n + 1):
            for k in range(x[i - 1]):
                dp[i, j, k] = dp[i - 1, j, k]
            if j > 0:
                for k in range(x[i - 1], x_sum + 1):
                    dp[i, j, k] = dp[i - 1, j, k] + dp[i - 1, j - 1, k - x[i - 1]]

    ans = 0
    for j in range(1, min(x_sum // a + 1, n + 1)):
        ans += dp[-1, j, j * a]
    print(ans)


### FIXED CODE ###

n, a = map(int, input().split())
x = list(map(int, input().split()))
x_max = max(x)
x_sum = sum(x)
ans = 0
if x_max >= a:
    dp = [[0 for j in range(2 * x_sum + 1)] for i in range(2)]
    dp[0][x_sum] = 1
    for i in range(1, n + 1):
        idx = i % 2
        y = x[i - 1] - a
        for j in range(2 * x_sum + 1):
            if 0 <= j - y <= 2 * x_sum:
                dp[idx][j] = dp[1 - idx][j] + dp[1 - idx][j - y]
            else:
                dp[idx][j] = dp[1 - idx][j]
    ans = dp[n % 2][x_sum] - 1
print(ans)
### BUGGY CODE ###

# DP tabelを3つに分けた

import numpy as np

def main():
    MOD = 998244353

    N, S = map(int, input().split())
    A = tuple(map(int, input().split()))

    DP0 = np.array([[0] * (S + 1) for _ in range(N + 1)], dtype = np.int64)
    DP1 = np.array([[0] * (S + 1) for _ in range(N + 1)], dtype = np.int64)
    DP2 = np.array([[0] * (S + 1) for _ in range(N + 1)], dtype = np.int64)

    DP0[0, 0] = 1

    for i in range(N):
        DP0[i + 1, :] = DP0[i, :] 
        DP1[i + 1, 0] = (DP0[i, 0] + DP1[i, 0]) % MOD
        a = A[i]
        if a > S:
            DP1[i + 1, 1:] = DP1[i, 1:] #以前から合計jになっている場合のみOK
        else:
            DP1[i + 1, 1:a] = DP1[i, 1:a] #以前から合計jになっている場合のみOK
            DP1[i + 1, a:] = (DP1[i, a:] + DP0[i, :S - a + 1] + DP1[i, :S - a + 1]) % MOD

        DP2[i + 1, S] = (DP1[i, S] + DP2[i, S])
        if a <= S:
            DP2[i + 1, S] += DP0[i, S - a] + DP1[i, S - a]
        DP2[i + 1, S] %= MOD

    print (DP2[N, S])

    # for i in range(N + 1):
    #     print (DP[i])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    MOD = 998244353

    N, S = map(int, input().split())
    A = tuple(map(int, input().split()))

    DP0 = [[0] * (S + 1) for _ in range(N + 1)]
    DP1 = [[0] * (S + 1) for _ in range(N + 1)]
    DP2 = [[0] * (S + 1) for _ in range(N + 1)]

    DP0[0][0] = 1

    for i in range(N):
        DP0[i + 1][0] = DP0[i][0] 
        DP1[i + 1][0] = DP0[i][0] + DP1[i][0]
        a = A[i]
        if a > S:
            for j in range(1, S + 1):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
        else:
            for j in range(1, a):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
            for j in range(a, S + 1):
                DP1[i + 1][j] = (DP1[i][j] + DP0[i][j - a] + DP1[i][j - a]) % MOD
                # DP[i + 1][j][1] = (DP[i][j][0] + DP[i][j][1] + DP[i + 1][j - a][1]) % MOD

        DP2[i + 1][S] = (DP1[i][S] + DP2[i][S])
        if a <= S:
            DP2[i + 1][S] += DP0[i][S - a] + DP1[i][S - a]
        DP2[i + 1][S] %= MOD

    print (DP2[N][S])

    # for i in range(N + 1):
    #     print (DP[i])

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

n, k = map(int, input().split())
A = list(map(int, input().split()))
B = [0]*1001
for i in range(1, 1001):
    B[i] = (1+i)/2
C = [B[A[j]] for j in range(n)]
ans = []
for i in range(n-k+1):
    ans.append(sum(C[i:i+k]))
print(max(ans))


### FIXED CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))
B = [(1+i)/2 for i in A]
ans = sum(B[:k])
t = ans
for i in range(n-k):
    t-=B[i]
    t+=B[i+k]
    if t>ans: ans=t
print(ans)
### BUGGY CODE ###

N, P = map(int, input().split())
S = input()
L_S = len(S)

count = 0
for left in range(L_S):
    for right in range(left + 1, L_S + 1):
        num = S[left:right]
        while num[0] == '0' and len(num) > 1:
            num = num[1:]
        if (int(num) % P) == 0:
            count += 1
print(count)


### FIXED CODE ###

def main():

    N, P = map(int, input().split())
    S = input()

    if P == 2 or P == 5:
        ans = 0
        for i in range(N):
            if int(S[i]) % P == 0:
                ans += (i + 1)
        print(ans)
        exit()

    sum_rem = [0] * N
    sum_rem[0] = int(S[N - 1]) % P
    ten = 10
    for i in range(1, N):
        a = (int(S[N - 1 - i]) * ten) % P
        sum_rem[i] = (a + sum_rem[i - 1]) % P
        ten = (ten * 10) % P

    ans = 0
    count = [0] * P
    count[0] = 1
    for i in range(N):
        ans += count[sum_rem[i]]
        count[sum_rem[i]] += 1
    print(ans)


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

N = int(input())
a = [int(i)-1 for i in input().split()]

for i in range(N):
  print(a.index(i)+1,end=" ")

### FIXED CODE ###

N = int(input())
dic = {}
a = [int(i) for i in input().split()]

for i in range(N):
    dic.setdefault(a[i], i+1)
    
dic = sorted(dic.items(), key=lambda x:x[0])

for i in range(N):
    print(dic[i][1], end=" ")
### BUGGY CODE ###

from itertools import accumulate

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

current_arr = A
for _ in range(K):
    imos = [0] * N
    ruiseki = [0] * (N+1)
    for i, ai in enumerate(current_arr):
        imos[max([0, i-ai])] += 1
        if i+ai+1 < N:
            imos[i+ai+1] -= 1
    for j, im in enumerate(imos):
        ruiseki[j+1] = ruiseki[j] + im
    current_arr = ruiseki[1:]
#print(imos)
#print(ruiseki)
#print(*accumulate(imos))
print(*current_arr)


### FIXED CODE ###

import sys
from itertools import accumulate

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

current_arr = A
if K > 41:
    print(*([N]*N))
else:
    for _ in range(K):
        imos = [0] * N
        ruiseki = [0] * (N+1)
        for i, ai in enumerate(current_arr):
            imos[max([0, i-ai])] += 1
            if i+ai+1 < N:
                imos[i+ai+1] -= 1
        for j, im in enumerate(imos):
            ruiseki[j+1] = ruiseki[j] + im
        current_arr = ruiseki[1:]
#print(imos)
#print(ruiseki)
#print(*accumulate(imos))
    print(*current_arr)
### BUGGY CODE ###

# coding: utf-8
N = int(input())

ans = 0
if N <= 356:
    print(ans)
    exit()

if N >= 777777754:
    N = 777777753

for i in range(357,N+1,2):
    st = str(i)
    if ("0" in st) or ("1" in st) or ("2" in st) or ("4" in st) or ("6" in st) or ("8" in st) or ("9" in st):
        continue
    if ("3" in st) and ("5" in st) and ("7" in st):
        ans+=1
print(ans)


### FIXED CODE ###

# coding: utf-8
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret

print(dfs("0"))
### BUGGY CODE ###

import sys


def solve(n, m, links):
    v4 = set()
    v6 = 0
    for v, link in enumerate(links):
        l = len(link)
        if l % 2 == 1:
            return False
        if l == 4:
            v4.add(v)
        elif l >= 6:
            v6 += 1
    if v6 > 0:
        return True
    if len(v4) > 2:
        return True
    if len(v4) < 2:
        return False
    s = v4.pop()
    t = v4.pop()
    visited = set()
    q = [s]
    while q:
        v = q.pop()
        if v == t:
            continue
        if v == s:
            if s in visited:
                return True
        elif v in visited:
            continue
        visited.add(s)
        q.extend(u for u in links[v] if u not in visited)
    return False


n, m = map(int, input().split())
links = [set() for _ in [0] * n]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
print('Yes' if solve(n, m, links) else 'No')


### FIXED CODE ###

import sys


def solve(n, m, links):
    v4 = set()
    v6 = 0
    for v, link in enumerate(links):
        l = len(link)
        if l % 2 == 1:
            return False
        if l == 4:
            v4.add(v)
        elif l >= 6:
            v6 += 1
    if v6 > 0:
        return True
    if len(v4) > 2:
        return True
    if len(v4) < 2:
        return False
    s = v4.pop()
    t = v4.pop()
    for c in links[s]:
        visited = {s, t}
        q = [c]
        while q:
            v = q.pop()
            if v in visited:
                continue
            visited.add(v)
            for u in links[v]:
                if v != c and u == s:
                    return True
                if u not in visited:
                    q.append(u)
    return False


n, m = map(int, input().split())
links = [set() for _ in [0] * n]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
print('Yes' if solve(n, m, links) else 'No')
### BUGGY CODE ###

# def s(i) :
# 	p = data
# 	p[i] = 0
# 	p.sort()
# 	print(p[-1])


n = int(input())
data = [int(input()) for k in range(n)]
for i in range(n):
	data2 = data[:]
	data2[i] = 0
	data2.sort()
	print(data2[-1])
	# s = data
	# s[i] = 0
	# s.sort()
	# print(s[-1])
	# print(s)

### FIXED CODE ###

n = int(input())
data = [int(input()) for k in range(n)]
m1,m2 = sorted(data, reverse=1)[:2]
b = [m2 if x==m1 else m1 for x in data]
print('\n'.join(map(str,b)))
### BUGGY CODE ###

[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in range(10**9) :
    if i in A:
        for j in A[i] :
            for k in range(L) :
                if j + k not in ANS :
                    ANS[j+k] = i
                    count += 1
        if count > N * 0.9997 : break
    else:
        continue

for i in range(L):
    if i not in ANS : ANS[i] = min(B[:i+1])
for i in range(L,N):
    if i not in ANS : ANS[i] = min(B[i+1-L:i+1])
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

N,A,B=map(int, raw_input().split()) 
H=[ input() for i in range(N) ] 

def func(n , T):

	S=[]
	for x in T:
		x-=n*B
		if x>0:
			S.append(x)

	sa=A-B
	for x in S:
		if x%sa==0:
			n-=x/sa
		else:
			n-=(x/sa+1)
		if n<0:
			return False
	else:
			return True

l=0
r=10**15
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

### FIXED CODE ###

N,A,B= map(int,raw_input().split())
h=[input() for _ in range(N)]

high=max(h)
low=1

def enough(T):
	cnt=0
	for i in h:
		i-=T*B
		if i>0:
			if i%(A-B)==0:
				cnt+=i/(A-B)
			else:
				cnt+=i/(A-B)+1
	if cnt<=T:
		return True
	else:
		return False

ans=0
while low<=high:
	c= (low + high) / 2
	if enough(c):
		high=c-1
		ans=c
	else:
		low=c+1


print ans
### BUGGY CODE ###

from math import gcd
n = int(input())
A = tuple(map(int, input().split()))

from collections import deque
q = deque([])
q.append([0, A[0], False])
q.append([1, A[1], True])
# 深さ優先探索
# idx, これまでのGCD, 抜いたか抜いてないか
ans = 0
while q:
    idx, g, jogai = q.pop()
    if idx == n-1:
        ans = max(ans, g)
        continue

    q.append([idx+1, gcd(g, A[idx+1]), jogai])
    if not jogai:
        q.append([idx+1, g, True])
print(ans)


### FIXED CODE ###

from math import gcd
n = int(input())
A = list(map(int, input().split()))

# 以降のGCD
left_gcds = [A[0]]
for a in A[1:]:
    left_gcds.append(gcd(left_gcds[-1], a))

right_gcds = [A[-1]]
for a in A[:n-1][::-1]:
    right_gcds.append(gcd(right_gcds[-1], a))
right_gcds.reverse()

ans = 0
for i in range(n):
    if i == 0:
        tmp = right_gcds[i+1]
    elif i == n-1:
        tmp =left_gcds[i-1]
    else:
        tmp = gcd(left_gcds[i-1], right_gcds[i+1])
    ans = max(ans, tmp)
print(ans)
### BUGGY CODE ###

nkq=list(map(int,input().split()))
a = [int(input()) for _ in range(nkq[2])]
point=[0]*nkq[0]
for i in range(nkq[0]):
    point[i]=nkq[1]-nkq[2]+a.count(i+1)
for j in range(nkq[0]):
    if point[j]>0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

nkq=list(map(int,input().split()))
a = [int(input()) for _ in range(nkq[2])]
point=[nkq[1]-nkq[2]]*nkq[0]
for i in range(nkq[2]):
    point[a[0]-1]+=1
    del a[0]
for j in range(nkq[0]):
    if point[j]>0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N - 1 + M)]

from collections import defaultdict
from heapq import *

vs = defaultdict(set)
ws = defaultdict(int)

for a, b in AB:
    vs[a].add(b)
    ws[b] += 1

for i in range(1, N + 1):
    if not ws[i]:
        root = i
        break

h = []

heappush(h, (0, root, 0))

rs = [-1] * (N + 1) 
ls = [0] * (N + 1)

rs[root] = 0

#print(vs)

while h:
    l, n, parent = heappop(h)
    #print("*", l, n, parent)
    for m in vs[n]:
        if ls[m] > l - 1:
            #print("+", l -1, m, n)
            ls[m] = l - 1
            prer = rs[m]
            if prer != n and prer in vs[m]:
                vs[m].remove(prer)
            rs[m] = n
            heappush(h, (l - 1, m, n))

for i in range(1, N + 1):
    print(rs[i])


### FIXED CODE ###

N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N - 1 + M)]

import sys
sys.setrecursionlimit(200000)

from collections import defaultdict

vs = defaultdict(set)
ws = defaultdict(set)

for a, b in AB:
    vs[a].add(b)
    ws[b].add(a)

#print(vs)
#print(ws)

L = []

cs = [0] * (1 + N)

def visit(n):
    if cs[n] == 1:
        return
    elif cs[n] == 0:
        cs[n] = 1
        for m in vs[n]:
            visit(m)
        cs[n] = 2
        L.append(n)

for n in range(1, N + 1):
    if cs[n] == 0:
        visit(n)

#print(L)

nrank = {}

for r, n in enumerate(L):
    nrank[n] = r

#print(nrank)

for n in range(1, N + 1):
    r = 0
    if ws[n]:
        r = sorted(ws[n], key=lambda x:nrank[x])[0]
    print(r)
### BUGGY CODE ###

import heapq
import numpy as np

N, M = [int(x) for x in input().split(" ")]

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * np.inf
d[0] = 0
prev = np.ones(N, dtype=int) * -1
q = [(d[0], 0)]
heapq.heapify(q)

while len(q) != 0:
  c, u = heapq.heappop(q)
  for nv in e[u]:
    alt = d[u] + 1
    if d[nv] > alt:
      d[nv] = alt
      prev[nv] = u
      heapq.heappush(q, (alt, nv))

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in prev[1:]]))


### FIXED CODE ###

import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)