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

def cmb(n, r, p):
    return (fac[n] * pow(fac[r], p - 2, p) * pow(fac[n - r], p - 2, p)) % p


p = 998244353
N, M, K = map(int, input().split())
fac = [1] * (max(N, M) + 1)
for i in range(1, max(N, M) + 1):
    fac[i] = (fac[i - 1] * i) % p

ans = 0
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb(N - 1, k, p)
    ans %= p
print(ans)


### FIXED CODE ###

def cmb(n, r, p):
    return (fac[n] * pow(fac[r], p - 2, p) * pow(fac[n - r], p - 2, p)) % p


p = 998244353
N, M, K = map(int, input().split())
fac = [1] * (max(N, M) + 1)
for i in range(1, max(N, M) + 1):
    fac[i] = (fac[i - 1] * i) % p

ans = 0
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb(N - 1, k, p)
    ans %= p
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int, S: str):

    d = dict()

    for length in range(N//2,0,-1):
        for j in range(0,N-length+1):
            s = S[j:j+length]

            if d.get(s) != None:
                if d[s]+length <= j:
                    print(length)
                    return 
            else:
                d[s] = j

    print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int, S: str):

    a = ""
    ans = 0
    for i in range(N):
        a += S[i]
        while(len(a) > 0):
            if a in S[i+1:]:    
                ans = max(ans,len(a))
                break
            else:               
                a = a[1:]
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

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

n,q = map(int,input().split())
s = input()
for i in range(q):
    x,y = map(int,input().split())
    a = s[x-1:y]
    print(a.count("AC"))

### FIXED CODE ###

n,q = map(int,input().split())
s = list(input())
a = [0]*n
c = 0
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        c+=1
    a[i]=c
for i in range(q):
    l,r = map(int,input().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

## coding: UTF-8


N, W = map(int,input().split())
l = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+1) for _ in range(N)]

for i in range(N):
    for j in range(W+1):
        if(j >= l[i][0]):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-l[i][0]] + l[i][1])
        else:
            dp[i][j] = dp[i-1][j]
#for k in range(N):
    #print(dp[k])
print(dp[-1][-1])

### FIXED CODE ###

## coding: UTF-8


N, W = map(int,input().split())
l = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+1) for _ in range(N)]

for i in range(N):
    for j in range(W+1):
        if(j >= l[i][0]):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-l[i][0]] + l[i][1])
        else:
            dp[i][j] = dp[i-1][j]
#for k in range(N):
    #print(dp[k])
print(dp[-1][-1])
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P = [p-1 for p in P]

# 1,ループを検出
# 2,ループごとの最大値の計算
# 3,結果の出力

visited = set() #探索済みのものを格納する

ans = 0
for i in range(N):
  if i in visited: #探索済みの場合
    continue
  
  # 1,ループを検出
  j = i
  C_tmp = [] #たどる順番にコストを格納
  while j not in visited:
    C_tmp.append(C[j])
    visited.add(j)
    j = P[j] #次のjへ
    
  # 2,ループごとの最大値の計算
  N_tmp = len(C_tmp) #ループ長さ
  tmp = 0 #何も足さないときは0(これが最大になる可能性もあるので注意)
  
  # N_tmp < K の場合には注意が必要
  # C_tmpの全要素の和が正になるときには、できるだけループを多く回したい
  # C_tmpの全要素の和が負になるときには、１周以内に収めたい
  loop_sum = max(0, sum(C_tmp)) #負の場合にはなかったことにすればよい
  #ただし、これらのうち番号が負になるものや、範囲外のものは当然のぞく
  
  #調べたいのは、
  #  sum(C)が正のとき  操作の回数が K-N_tmp+1 から K まで
  #  sum(C)が負のとき  操作の回数が 0 から N_tmp-1 まで
  #　  例1：N_tmp = 5, K = 8, ループ１周の和が正の時
  #       0 　 1 　 2 　 3 　 4 ◯ （「上段」）
  #       5 ◯ 6 ◯ 7 ◯ 8 ◯   　 （「下段」）
  #　  例2：N_tmp = 5, K = 8, ループ１周の和が負の時
  #       0 ◯ 1 ◯ 2 ◯ 3 ◯ 4 ◯ 
  #       5 　 6 　 7 　 8 　
  #    ただし、ループを１周ごとになかったことにするなら、結局次のように考えて良い
  #       0 　 1 　 2 　 3 　 4 ◯ （「上段」）
  #       5 ◯ 6 ◯ 7 ◯ 8 ◯   　 （「下段」）
  #　  例3：N_tmp = 5, K = 3, ループ１周の和が正の時
  #       0 ◯ 1 ◯ 2 ◯ 3 ◯   　 （「上段」）
  
  #ひとまず、回すことができる最大のループ回数を計算し、その和を求めておく
  base = loop_sum * (K // N_tmp)
  
  #はみ出した部分について和を求める。（「下段」については、loop_sumを一回引くことで対処）
  # (操作回数) % N_tmp を lとして、連続したl個の要素の和を調べる
  ans = max(ans, base) # l = 0 のとき
  behind = False #下段を調べているときにTrueとする
  for l in range(1,min(N_tmp, K+1)): # l > 1 のとき
    if (not behind) and l > K % N_tmp: #下段に移るとき、ループを１週戻す
      behind = True
      base -= loop_sum
    summ = sum(C_tmp[0:l]) + base
    for j in range(N_tmp):
      ans = max(ans, summ) #最大値の更新
      summ += C_tmp[(j+l)%N_tmp] - C_tmp[j] #始点を1ずらす
      
      
#3,結果の出力
# K > 1に注意
print(max(C) if max(C) < 0 else ans)


  
    
    

### FIXED CODE ###

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

P = [p-1 for p in P]
#print(P)

visited = set()
ans = 0
for i in range(N):
  if i in visited:
    continue
  tmp = []
  j = i
  while j not in visited:
    tmp.append(C[j])
    visited.add(j)
    j = P[j]
  #print(tmp,visited)  
  M = len(tmp)
  L = max(0,sum(tmp))
  now = L * (K // M)
  k = K % M
  tmp2 = 0
  tmp4 = 0
  for l in range(1,min(M,K)+1):
    tmp2 += tmp[l-1]
    tmp3 = tmp2
    for j in range(M):
      tmp4 = max(tmp4, tmp3) 
      tmp3 += tmp[(j+l)%M] - tmp[j%M]
      #print(tmp4, l, j)
      ans = max(ans, now+tmp4 if l <= k else now+tmp4-L)
  #ans = max(ans, now+tmp4 if l <= k else now+tmp4-L) 
  #print(i, L, now, l, k, tmp4, M, visited, now+tmp4)
  del tmp

flag = True
for c in C:
  if c > 0:
    flag = False
    
print(max(C) if flag else ans)
### BUGGY CODE ###

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]
mindata = min(arr)
arr_replace = [mindata for x in range(k)]


cnt = 0
idx=arr.index([x for x in arr if x !=mindata][0])

while not (all(x == mindata for x in arr)):
    
    if not(all(x == mindata for x in arr[idx:idx + k])):
        cnt += 1
        arr[idx:idx + k] = arr_replace
    
    if not(all(x == mindata for x in arr[idx + k-1:idx + k-1 + k])):
        cnt += 1
        arr[idx + k-1:idx + k-1 + k] = arr_replace
    
    idx += k-1 + k-1
    
#    print(arr,idx)
#    print(arr[idx:idx+k])
#    print(arr[idx+k-1:idx+k-1+k])
    
print(cnt) 
    
    
    


### FIXED CODE ###

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]

cnt=1
if n <= k:
    
    print(cnt)
    
else:
    
    chkflg = True
    
    while chkflg:
        
        cnt+=1

        s = k + 1 + (k-1) * (cnt-2)
        e = k * 2-1 + (k-1) * (cnt-2)
        
        if s<=n<=e:
            
            chkflg=False
            
            
    print(cnt)
### BUGGY CODE ###

x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)
rn.sort(reverse=True)

pn = pn[:x]
qn = qn[:y]

while min(pn[-1], qn[-1]) <= rn[0]:
  if pn[-1] >= qn[-1]:
    qn[-1] = rn[0]
  else:
    pn[-1] = rn[0]
  del rn[0]
  if len(rn) == 0:
    break
  pn.sort(reverse=True)
  qn.sort(reverse=True)
  
print(sum(pn) + sum(qn))

### FIXED CODE ###

x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)

pqr = pn[:x] + qn[:y] + rn
pqr.sort(reverse=True)
  
print(sum(pqr[:x+y]))
### BUGGY CODE ###

import sys

import numba as nb

input = sys.stdin.readline


@nb.njit("i8(List(i8, reflected=True),i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ok = -1
    ng = len(a)

    def is_ok(a, key, idx):
        if a[idx] < key:
            return True
        else:
            return False

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(a, key, mid):
            ok = mid
        else:
            ng = mid

    return ok


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

    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            x = binary_search(L, L[a] + L[b])
            ans += (x - b)

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from bisect import bisect_left

input = sys.stdin.readline


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

    L.sort()
    ans = 0
    for i in range(N - 1):
        a = L[i]
        for j in range(i + 1, N):
            k = bisect_left(L, a + L[j])
            ans += (k - 1 - j)

    print(ans)


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

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

f = 0
d = 1
e = 1
for i in range(n-k):
    for j in range(k):
        d *= a[i+j]
        e *= a[i+j+1]

    if d < e:
        print("Yes")
        d,e = 1,1
    else:
        print("No")
        d,e = 1,1

### FIXED CODE ###

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

f = 0
d = 1
e = 1
for i in range(n-k):


    if a[i] < a[i+k]:
        print("Yes")

    else:
        print("No")
### BUGGY CODE ###

import copy
import math

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

Us=[0]*M
Vs=[0]*M
As=[0]*M
Bs=[0]*M
for i in range(M):
    Us[i],Vs[i],As[i],Bs[i] = map(int,input().split())

# ---
V={}
Ns = max(As)*N
Nv=N*(Ns+1)
cnt=0
for i in range(1,N+1):
    for ns in range(Ns+1):
        V[(i,ns)]=cnt
        cnt+=1
#T= copy.copy(V)


if S > Ns:
    S = Ns

# --
w = [[math.inf]*Nv for _ in range(Nv) ]
# U <-> V
for _ in range(M):
    u = Us.pop()
    v = Vs.pop()
    a = As.pop()
    b = Bs.pop()
    #
    for i in range(Ns+1): # i = 0,..,Ns
        ns_s = Ns - i
        ns_g = ns_s - a
        if ns_g >= 0:
            # U -> V
            w[ V[(u,ns_s)] ][ V[(v,ns_g)] ] = b
            # V -> U
            w[ V[(v,ns_s)] ][ V[(u,ns_g)] ] = b
            #print(u,v,a,b,ns_s,ns_g,V[(u,ns_s)],V[(v,ns_g)])

# -----

for i in range(N):
    c,d = map(int,input().split())
    v = i+1
    for j in range(Ns): # j = 0,...,Ns-1
        ns_s = j
        ns_g = j + c
        if ns_g > Ns:
            ns_g = Ns
        w[ V[(v,ns_s)] ][ V[(v,ns_g)] ] = d

# -----
D=[-1]*Nv
# -----
T=list(range(Nv))

s=V[(1,S)]
T.remove(s) #del T[s]
D[s] = 0
for v in T:
    D[v] = w[ s ][ v ]
#while len(T) > 0:
for _ in range(Nv-1):
    u = min(T,key=lambda x:D[x])
    T.remove(u)
    for v in T:
        D[ v ] = min( D[ v ], D[ u ] + w[ u ][ v ] )

for i in range(2,N+1):
    ans = min([ D[ V[(i,ns)] ] for ns in range(Ns+1) ])
    print(ans)

### FIXED CODE ###

import math
import heapq

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

Us=[0]*M
Vs=[0]*M
As=[0]*M
Bs=[0]*M
for i in range(M):
    Us[i],Vs[i],As[i],Bs[i] = map(int,input().split())
    Us[i] -= 1
    Vs[i] -= 1

# ---
V={}
Ns = max(As)*N
Nv=N*(Ns+1)
cnt=0
for i in range(N):
    for ns in range(Ns+1):
        V[(i,ns)]=cnt
        cnt+=1

G=[[] for _ in range(Nv)]

if S > Ns:
    S = Ns

# U <-> V
for _ in range(M):
    u = Us.pop()
    v = Vs.pop()
    a = As.pop()
    b = Bs.pop()
    #
    for i in range(Ns+1): # i = 0,..,Ns
        ns_s = Ns - i
        ns_g = ns_s - a
        if ns_g >= 0:
            # U -> V
            G[ V[(u,ns_s)] ].append( (V[(v,ns_g)],b) )
            # V -> U
            G[ V[(v,ns_s)] ].append( (V[(u,ns_g)],b) )
            #print(u,v,a,b,ns_s,ns_g,V[(u,ns_s)],V[(v,ns_g)])

# -----

for i in range(N):
    c,d = map(int,input().split())
    for j in range(Ns): # j = 0,...,Ns-1
        ns_s = j
        ns_g = j + c
        if ns_g > Ns:
            ns_g = Ns
        G[ V[(i,ns_s)] ].append( (V[(i,ns_g)],d) )

# -----
D=[math.inf]*Nv
q=[]
# -----

s=V[(0,S)]
D[s] = 0
heapq.heappush(q,(0,s))

while len(q) > 0:
    p_cost,p_v = heapq.heappop(q)
    if D[p_v] < p_cost:
        continue
    for e_to,e_cost in G[p_v]:
        if D[ e_to ] > D[p_v] + e_cost:
            D[e_to] = D[p_v] + e_cost
            heapq.heappush(q, (D[e_to], e_to))

for i in range(1,N):
    ans = min([D[i*(Ns+1)+v] for v in range(Ns+1)])
    print(ans)
### BUGGY CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

n = INT()
a = sorted(LIST())

k = 1
flag = 1
for i in range(1, n):
    k *= a[i-1]
    if gcd(k, a[i]) > 1:
        flag = 0
        break

if flag == 1:
    print("pairwise coprime")
    exit()
else:
    g = a[0]
    for i in range(1, n):
        g = gcd(g, a[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")

### FIXED CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

n = INT()
a = LIST()
m = max(a)

primes = [0]*(m+1)
primes[1] = 1
for i in range(2, m+1):
    if primes[i] == 0:
        for j in range(1, m//i+1):
            primes[i*j] = i

count = [0]*(m+1)
for x in a:
    y = x
    while primes[y] != y:
        count[primes[y]] += 1
        p = primes[y]
        while y % p == 0:
            y //= p
    if primes[y] >= 2:
        count[primes[y]] += 1

if max(count) <= 1:
    print("pairwise coprime")
else:
    g = 0
    for x in a:
        g = gcd(g, x)
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")
### BUGGY CODE ###

L,R=map(int,input().split())
r=min(R,L+2019*2)
minimum=2019*2
for i in range(L,r+1):
    for j in range(i+1,r+1):
        minimum=min(minimum,i*j%2019)
print(minimum)

### FIXED CODE ###

L,R=map(int,input().split())
left=L%2019
right=R%2019
print(0 if R-L>=2019 else min([i*j%2019 for i in range(left,right+1) for j in range(i+1,right+1)]))
### BUGGY CODE ###

class Node():
    def __init__(self, key, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next

class link():
    def __init__(self):
        self.node = Node(None)
        self.node.prev = self.node.next = self.node

    def insert(self, key):
        elem = Node(key, self.node, self.node.next)
        self.node.next.prev = elem
        self.node.next = elem

    def search(self, key):
        elem = self.node.next
        while (elem != self.node) and (elem.key != key):
            elem = elem.next
        return elem

    def delete(self, node):
        if node == self.node:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self.delete(self.node.next)

    def deleteLast(self):
        self.delete(self.node.prev)

    def show_keys(self):
        keys = []
        elem = self.node.next
        while elem != self.node:
            keys.append(str(elem.key))
            elem = elem.next
        print(' '.join(keys))

n = int(input())
linkedlist = link()
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        linkedlist.insert(int(com[1]))
    elif com[0] == 'delete':
        linkedlist.delete(linkedlist.search(int(com[1])))
    elif com[0] == 'deleteFirst':
        linkedlist.deleteFirst()
    else:
        linkedlist.deleteLast()
linkedlist.show_keys()


### FIXED CODE ###

from collections import deque

n = int(input())
q = deque()
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.appendleft(com[1])
    elif com[0] == 'delete':
        try:
            q.remove(com[1])
        except:
            pass
    elif com[0] == 'deleteFirst':
        q.popleft()
    else:
        q.pop()
print(" ".join(q))
### BUGGY CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappop

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)
    A = [next(it) for i in range(N)]
    B = [next(it) for i in range(M)]

    dq = []
    heappush(dq, (0, 0, 0, 0))
    ans = 0
    seen = set()
    while dq:
        k, n, i, j = heappop(dq)

        if (i, j) in seen:
            continue
        if k > K:
            break
        seen.add((i, j))
        ans = max(ans, n)

        if i < N:
            heappush(dq, (k+A[i], n+1, i+1, j))
        if j < M:
            heappush(dq, (k+B[j], n+1, i, j+1))

    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, M, K = next(it), next(it), next(it)

    A = [0] * (N+1)
    B = [0] * (M+1)
    ans = 0
    for i in range(1, N+1):
        A[i] = A[i-1] + next(it)
    for i in range(1, M+1):
        B[i] = B[i-1] + next(it)

    lo = 0
    hi = 2*(N+M)+1
    while lo < hi:
        mid = (lo+hi)//2
        for j in range(max(0, mid-M), min(mid, N)+1):
            if A[j] + B[mid-j] <= K:
                lo = mid+1
                break
        else:
            hi = mid

    print(lo-1)


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

# dpF - LCS
def main():
    S, T = tuple(input().rstrip() for _ in range(2))
    n, m = len(S), len(T)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if S[i - 1] == T[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
    ans = []
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            n -= 1
            m -= 1
            ans += [S[n]]
    print(*ans[::-1], sep="")


if __name__ == "__main__":
    main()

### FIXED CODE ###

# dpF - LCS
def main():
    S, T = tuple(input().rstrip() for _ in range(2))
    n, m = len(S), len(T)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if S[i - 1] == T[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
    ans = []
    while n > 0 and m > 0:
        if dp[n][m] == dp[n - 1][m]:
            n -= 1
        elif dp[n][m] == dp[n][m - 1]:
            m -= 1
        else:
            n -= 1
            m -= 1
            ans += [S[n]]
    print(*ans[::-1], sep="")


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

#入力
HWD = list(map(int, input().split()))
H, W, D = HWD[0], HWD[1],  HWD[2]
field = []
for i in range(H):
    field.append(list(map(int, input().split())))
           
Q = int(input())
target = []
for i in range(Q):
    target.append(list(map(int, input().split())))

#動作
for test in range(Q):
    count = 0
    next_point = target[test][0]
    while not next_point == target[test][1]:
        now_point = next_point
        next_point = now_point + D
        for field_h in range(H):
            if now_point in field[field_h] or next_point in field[field_h]:
                for field_w in range(W):
                    if field[field_h][field_w] == now_point:
                        now_h = field_h
                        now_w = field_w
                    if field[field_h][field_w] == next_point:
                        next_h = field_h
                        next_w = field_w
        count += abs(next_h - now_h) + abs(next_w - now_w)
    print(count)

### FIXED CODE ###

#入力
HWD = list(map(int, input().split()))
H, W, D = HWD[0], HWD[1],  HWD[2]
field_dict = {}
for h in range(H):
    field = list(map(int, input().split()))
    for w in range(W):
        field_dict[field[w]] = (h, w)

#numberからD動かした時の魔力
move_dict = {}
pre_length = 0
for now_point in range(1, H * W + 1):
    pre_point = now_point - D
    if now_point > D:
        pre_length = move_dict[now_point - D]
        now_h = field_dict[now_point][0]
        now_w = field_dict[now_point][1]
        pre_h = field_dict[pre_point][0]
        pre_w = field_dict[pre_point][1]
        move_dict[now_point] = abs(now_h - pre_h) + abs(now_w - pre_w) + pre_length
    else:
        move_dict[now_point] = 0
           
#試験
Q = int(input())
for test in range(Q):
    target = list(map(int, input().split()))
    count = move_dict[target[1]] - move_dict[target[0]]
    print(count)
### BUGGY CODE ###

from collections import deque
N, M = map(int, input().split())
p = [0]
ans = [0]
D = deque()
for i in range(N):
    p.append(list())
    if i == 0:
        ans.append(0)
    else:
        ans.append(-1)
for i in range(M):
    A, B = map(int, input().split())
    p[A].append(B)
    p[B].append(A)
D.append(1)
while len(D) != 0:
    ind = D.popleft()
    for i in p[ind]:
        if ans[i] == -1:
            D.append(i)
            ans[i] = ind
    if -1 not in ans[2:]:
        break
if -1 in ans[2:]:
    print('No')
else:
    print('Yes')
    for i in ans[2:]:
        print(i)

### FIXED CODE ###

from collections import deque
N, M = map(int, input().split())
p = [0]
ans = [0]
for i in range(N):
    p.append(list())
    if i == 0:
        ans.append(0)
    else:
        ans.append(-1)
for i in range(M):
    A, B = map(int, input().split())
    p[A].append(B)
    p[B].append(A)
D = deque([1])
while D:
    ind = D.popleft()
    for i in p[ind]:
        if ans[i] == -1:
            D.append(i)
            ans[i] = ind

if -1 in ans[2:]:
    print('No')
else:
    print('Yes')
    for i in ans[2:]:
        print(i)