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

from collections import deque
 
 
def dfs(field, h, w):
    visited = [[False] * w for _ in range(h)]
    q = deque([])
    for y in range(h):
        for x in range(w):
            if field[y][x] == '#':
                q.append((y, x, 0))
                visited[y][x] = True
    
    while q:
        i, j, d = q.popleft()
        if i > 0 and visited[i - 1][j] == False and field[i - 1][j] == '.':
            q.append((i - 1, j, d + 1))
            visited[i - 1][j] = True
        if i < h - 1 and visited[i + 1][j] == False and field[i + 1][j] == '.':
            q.append((i + 1, j, d + 1))
            visited[i + 1][j] = True
        if j > 0 and visited[i][j - 1] == False and field[i][j - 1] == '.':
            q.append((i, j - 1, d + 1))
            visited[i][j - 1] = True
        if j < w - 1 and visited[i][j + 1] == False and field[i][j + 1] == '.':
            q.append((i, j + 1, d + 1))
            visited[i][j + 1] = True
    else:
        return d


h , w = map(int, input().split())
field = [input() for _ in range(h)]
dot_cnt = sum(r.count('.') for r in field)
d = dfs(field, h, w)
print(d)

### FIXED CODE ###

import numpy as np

H,W = map(int,input().split())
use = np.zeros((H,W),dtype=int)
for i in range(H):
    s = input()
    for j,st in enumerate(s):
        if st == ".":
            use[i][j] = 10**10
        else:
            use[i][j] = 0

for i in range(1,H):
    use[i,:] = np.minimum(use[i,:],use[i-1,:]+1)
for i in reversed(range(H-1)):
    use[i,:] = np.minimum(use[i,:],use[i+1,:]+1)
for j in range(1,W):
    use[:,j] = np.minimum(use[:,j],use[:,j-1]+1)
for j in reversed(range(W-1)):
    use[:,j] = np.minimum(use[:,j],use[:,j+1]+1)

print(np.max(use))
### BUGGY CODE ###

n = int(input())
s = list(input())

a,b = [],[]
for i in range(1,n):
    if s[i]=="E":
        a.append(s[:i-1].count("W")+s[i+1:].count("E"))
        #print(a)
    elif s[i]=="W":
        b.append(s[i+1:].count("E")+s[:i-1].count("W"))
print(min(min(a),min(b)))

### FIXED CODE ###

import numpy as np
import sys
buf = sys.stdin.buffer
N = int(buf.readline())
L = list(input())

tE = L.count("E")
tW = N-tE
ce,cw = 0,0
ans = 3*(10**5)
for i in range(N):
    if L[i] == "E":
        ce +=1
    elif L[i] == "W":
        cw +=1
    if L[i] == "E":
        ans = min(ans,cw+(tE-ce))
    elif L[i] == "W":
      
        ans = min(ans,cw-1+(tE-ce))
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
s = list(input())
q = int(input())

for _ in range(q):
    query = input()
    if query[0] == '1':
        s = s[::-1]
    else:
        _, f, c = query.split()
        if f == '1':
            s.insert(0, c)
        else:
            s.append(c)

print("".join(s))


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import deque


s = deque(list(input()))
q = int(input())

reverce = False
for _ in range(q):
    query = input()
    if query[0] == '1':
        reverce = not reverce
    else:
        _, f, c = query.split()
        if (f == '1' and not reverce) or (f == '2' and reverce):
            s.appendleft(c)
        else:
            s.append(c)

if reverce:
    s.reverse()

print("".join(s))
### BUGGY CODE ###

from collections import deque

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

s = deque(inp())
q = iinp()

l = deque()

p = 0
o = 1

for i in range(q):
  a = inps()
  if o == 1 and a[0] == 1:
    continue
  if a[0] == "2":
    if a[1] == "1":
      if p == 0:
        l.appendleft(a[2])
        o += 1
      else:
        s.appendleft(a[2])
        o += 1
    else:
      if p == 0:
        s.append(a[2])
        o += 1
      else:
        l.append(a[2])
        o += 1
  if a[0] == "1":
    if p == 0:
      p = 1
    else:
      p = 0
    s.reverse()
    l.reverse()

if p == 0:
  for i in l:
    print(i,end="")
  for i in s:
    print(i,end="")
  print("")
else:
  for i in s:
    print(i,end="")
  for i in l:
    print(i,end="")
  print("")

### FIXED CODE ###

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

s = list(inp())
q = iinp()

l = []

p = 0
o = 1

for i in range(q):
  a = inps()
  if o == 1 and a[0] == 1:
    continue
  if a[0] == "2":
    if a[1] == "1":
      if p == 0:
        l.append(a[2])
        o += 1
      else:
        s.append(a[2])
        o += 1
    else:
      if p == 0:
        s.append(a[2])
        o += 1
      else:
        l.append(a[2])
        o += 1
  if a[0] == "1":
    if p == 0:
      p = 1
    else:
      p = 0

if p == 0:
  for i in range(len(l)):
    print(l[len(l)-1-i],end="")
  for i in s:
    print(i,end="")
  print("")
else:
  for i in range(len(s)):
    print(s[len(s)-1-i],end="")
  for i in l:
    print(i,end="")
  print("")
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    carray = [0] * N
    for i in range(1,N):
        if(S[i] == 'C' and S[i-1] == 'A'):
            carray[i:] = map(lambda x:x+1, carray[i:])
        else:
            continue
    
    # print(carray)
    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        ans.append(carray[r[i]-1]-carray[l[i]-1])

    for i in range(Q):
        print(ans[i])
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    carray = [0] * N
    for i in range(1,N):
        if(S[i-1:i+1] == 'AC'):
            carray[i] = carray[i-1]+1 
            # carray[i:] = map(lambda x:x+1, carray[i:])
        else:
            carray[i] = carray[i-1]
    # print(carray)
    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        t = carray[r[i]-1] - carray[l[i]-1]
        ans.append(t)

    for i in range(Q):
        print(ans[i])
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

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

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

a,b,n = map(int,input().split())
ans = math.floor((a*1)/b) - a*math.floor(1/b)
for i in range(1,n+1):
    d = math.floor((a*i)/b) - a*math.floor(i/b)
    if ans > d:
        break
    ans = max(ans,d)

print(ans)

### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

a,b,n = map(int,input().split())
ans = 0

if n < b-1:
    ans = math.floor((a*n)/b)
else:
    ans = math.floor((a*(b-1))/b)
print(ans)
### BUGGY CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N=int(input())

    A=[int(input()) for i in range(N)]
    temp=[0]*N
    i = 0
    cnt=0

    while True:
        if A[i] not in temp:
            temp[cnt] = A[i]
            if A[i]==2:
                print(cnt+1)
                break
            i=A[i]-1
            cnt+=1

        else:
            print(-1)
            break
resolve()

### FIXED CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N=int(input())

    A=[int(input()) for i in range(N)]
    num=0
    cnt=0

    for i in range(N):
        if A[num]==2:
            print(cnt+1)
            break
        num=A[num]-1
        cnt+=1

        if i==N-1:
            print(-1)

resolve()
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
h = np.array([int(x) for x in input().split()])
d = np.inf
dp = np.ones(N) * d
dp[0] = 0
for i in range(1, N):
  j = i - min(i, K)
  dp[i] = min(dp[j:i]+np.abs(h[i]-h[j:i]))
print(int(dp[N-1]))

### FIXED CODE ###

import sys
import numpy as np

# inputを高速化する。
input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)


for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])
### BUGGY CODE ###

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

e_long = max(X, N-X)
e_short = N - e_long

total = N

while e_long != e_short and e_long > 0 and e_short > 0:
    total += e_short * 2
    e_long -= e_short
    if e_short > e_long:
        tmp = e_long
        e_long = e_short
        e_short = tmp

total += e_short

print(total)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N, X = map(int, input().split())
    ans = N
    min_ = min(X, N-X)
    max_ = max(X, N-X)
    while min_ != 0:
        # print(max_, min_)
        ans += (max_ // min_) * 2 * min_
        tmp = max_ % min_
        max_ = min_
        min_ = tmp
    ans -= max_
    print(ans)


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

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

res = 0
for j in range(N-K+1):
  ans = sum([x for x in p[j:j+K]])
  res = max(res,ans)
  
print(res) 

### FIXED CODE ###

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

m = check = sum(p[0:K])
for i in range(K,N):
  check = check+p[i]-p[i-K]
  m = max(m,check)
print(m)
### BUGGY CODE ###

N = int(input())

a = 0  # not carried
b = 0  # carried
t = N % 10
a, b = a + t, a + (10 - t)
N //= 10
while N != 0:
    t = N % 10
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
    N //= 10
print(min(a, b + 1))


### FIXED CODE ###

N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)
### BUGGY CODE ###

import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ruiseki = [1]
    for i in range(1, n+1):
        ruiseki.append(a[i-1]*ruiseki[i-1])
    for i in range(k-1, n-1):
        if ruiseki[i+1]//ruiseki[i-k+1] >= ruiseki[i+2]//ruiseki[i+2-k]:
            print("No")
        else:
            print("Yes")
    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###

import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(k, n):
        if a[i] > a[i-k]:
            print("Yes")
        else:
            print("No")
    return 0

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

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

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

for i in range(1, N + 1):
    for j in range(W):
        w = wv[i - 1][0]
        v = wv[i - 1][1]
        if j + w <= W:
            dp[i][j + w] = max(dp[i][j + w], dp[i - 1][j] + v)
            dp[i][j] = max(dp[i][j], dp[i - 1][j])
        else:
            dp[i][j] = max(dp[i][j], dp[i - 1][j])
        
print(max(dp[-1]))

### FIXED CODE ###

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

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

for i in range(1, N + 1):
    for j in range(W):
        w = wv[i - 1][0]
        v = wv[i - 1][1]
        if j + w <= W:
            dp[i][j + w] = max(dp[i][j + w], dp[i - 1][j] + v)
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
        
print(max(dp[-1]))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().strip().split()))
ans = "YES"
for i in range(n - 1):
    for j in range(i, n - i - 1):
        if a[i] == a[j + 1]:
            ans = "NO"
print(ans)        

### FIXED CODE ###

n = int(input())
a = list(map(int,input().strip().split()))
ans = "YES"
dic = {}
for i in range(n):
    temp = str(a[i])
    if temp in dic:
        ans = "NO"
    else:
        dic[temp] = 1
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

for i in range(M):
  A += [BC[i][1]] * BC[i][0]

print( sum(sorted(A, reverse=True)[:N]) )

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
D = [(A[i], 1) for i in range(N)]

for i in range(M):
  B, C = (map(int, input().split()))
  D.append((C, B))
  
D.sort()
D.reverse()

ans, left = 0, N
for (i, j) in D:
    use = min(j, left)
    ans += use * i
    left -= use
print(ans)
### BUGGY CODE ###

import math
import sys
sys.setrecursionlimit(100000000)

n, k = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(n - 1)]
qs = [list(map(int, input().split())) for _ in range(k)]

ws = [0 for _ in range(n)]
for q in qs:
	ws[q[0] - 1] += q[1]

ds = [[] for _ in range(n)]
for l in ls:
	ds[l[0] - 1].append(l[1] - 1)

ans = [0 for _ in range(n)]

def dfs(x, v):
	ans[x] = ws[x] + v
	if len(ds[x]) > 0:
		for nxt in ds[x]:
			dfs(nxt, ans[x])

dfs(0, 0)

print(*ans)


### FIXED CODE ###

n, k = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(n - 1)]
qs = [list(map(int, input().split())) for _ in range(k)]

ws = [0 for _ in range(n)]
for q in qs:
	ws[q[0] - 1] += q[1]

ds = [[] for _ in range(n)]
for l in ls:
	ds[l[0] - 1].append(l[1] - 1)

for i in range(0, n):
	for x in ds[i]:
		ws[x] += ws[i]

for i in range(n):
	print(ws[i])
### BUGGY CODE ###

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

set_A = set(A)
count = 0
pre_ans = 0

for i in set_A:
    count = A.count(i)
    pre_ans += count*(count - 1) // 2

for i in A:
    count = A.count(i)
    ans = pre_ans - (count-1)
    print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
X = [0]*N

for i in A:
    X[i-1] += 1

cnt = 0
for i in X:
    cnt += i* (i-1) // 2

for i in A:
    ans = cnt - (X[i-1] - 1)
    print(ans)
### BUGGY CODE ###

N,K,Q = [int(x) for x in input().rstrip().split()]
l = [K for x in range(N)]

for i in range(Q):
    a = int(input())
    for j in range(N):

        if a-1 != j:

            l[j]=l[j]-1
for i in l:
    if 0<i:
     
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N,K,Q=[int(x) for x in input().rstrip().split()]
cnt=[0 for i in range(N)]
for i in range(Q):
  A=int(input())
  cnt[A-1]+=1
for i in cnt:
  if 0<(K-Q+i):
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

n,m=[int(i) for i in input().split()]
a=[int(input()) for _ in range(m)]
dp=[1]+[0]*100010
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    else:
        try:
            dp[i]=dp[i-1]+dp[i-2]
        except:
            dp[i]=dp[i-1]
        dp[i]%=1000000007
print(dp[n])

### FIXED CODE ###

n,m=[int(i) for i in input().split()]
a=[int(input()) for _ in range(m)]
dp=[1]+[1]*100010
for i in a:
    dp[i]=0
for i in range(2,n+1):
    if dp[i]:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)
### BUGGY CODE ###

A, B = map(int, input().split())

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factorize(x):
    res = []
    i = 2
    while i * i <= x:
        if x % i:
            continue
        res.append([i, 0])
        while x % i == 0:
            x //= i
            res[-1][1] += 1
        i += 1
    if x != 1:
        res.append([x, 1])
    return res


cd = gcd(A, B)
ans = len(prime_factorize(cd)) + 1
print(ans)


### FIXED CODE ###

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

    def gcd(x, y):
        while y != 0:
            x, y = y, x % y
        return x

    def prime_factorize(n):
        arr = []
        temp = n
        for i in range(2, int(-(-(n ** 0.5) // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])

        if temp != 1:
            arr.append([temp, 1])


        return arr

    cd = gcd(A, B)
    ans = len(prime_factorize(cd)) + 1
    print(ans)


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

N = int(input())
c = input()

white_index = 0
red_index = N
ans = 0
for i in range(N):
    red_index = c.rfind('R')
    white_index = c.find('W')
    if red_index < 0:
        break
    if white_index >= red_index or white_index < 0:
        break
    c = c[:red_index] + 'W' + c[red_index+1:]
    c = c[:white_index] + 'R' + c[white_index+1:]
    ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
c = input()

ans = 0

red_index = c.rfind('R')
white_index = c.find('W')
if red_index < 0:
    print(0)
    exit()
if white_index >= red_index or white_index < 0:
    print(0)
    exit()
ans += 1

for i in range(N):
    red_end = red_index
    white_start = white_index + 1
    red_index = c.rfind('R', 0, red_end)
    white_index = c.find('W', white_start, N)
    if red_index < 0:
        break
    if white_index >= red_index or white_index < 0:
        break
    ans += 1
print(ans)
### BUGGY CODE ###

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

Map = [[[0]*K for i in range(K)] for j in range(2)]
for i in range(N):
  x, y, c = input().split()
  x, y = int(x), int(y)
  if c == 'B':
    c = 0
  else:
    c = 1
  nx, ny = x//K, y//K
  if (nx + ny) % 2:
    c = 1 - c
  x %= K
  y %= K
  Map[c][x][y] += 1

def get_v(c, x, y):
  global Map
  if x < 0 or y < 0:
    return 0
  else:
    return Map[c][x][y]

for c in range(2):
  for x in range(K):
    for y in range(K):
      Map[c][x][y] += get_v(c, x-1, y) + get_v(c, x, y-1) - get_v(c, x-1, y-1)

ans = 0
for x in range(K+1):
  for y in range(K+1):
    b2 = get_v(0, x-1, K-1) + get_v(0, K-1, y-1) - 2*get_v(0, x-1, y-1)
    w1 = get_v(1, x-1, K-1) + get_v(1, K-1, y-1) - 2*get_v(1, x-1, y-1)
    b1 = Map[0][K-1][K-1] - b2
    w2 = Map[1][K-1][K-1] - w1
    ans = max(ans, b1+w1, b2+w2)

print(ans)

### FIXED CODE ###

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

Map = [[[0]*K for i in range(K)] for j in range(2)]
for i in range(N):
  x, y, c = input().split()
  x, y = int(x), int(y)
  if c == 'B':
    c = 0
  else:
    c = 1
  nx, ny = x//K, y//K
  if (nx + ny) % 2:
    c = 1 - c
  x %= K
  y %= K
  Map[c][x][y] += 1

def get_v(c, x, y):
  global Map
  if x < 0 or y < 0:
    return 0
  else:
    return Map[c][x][y]

for c in range(2):
  for x in range(K):
    for y in range(K):
      Map[c][x][y] += get_v(c, x-1, y) + get_v(c, x, y-1) - get_v(c, x-1, y-1)

ans = 0
for x in range(K+1):
  for y in range(K+1):
    b2 = get_v(0, x-1, K-1) + get_v(0, K-1, y-1) - 2*get_v(0, x-1, y-1)
    w1 = get_v(1, x-1, K-1) + get_v(1, K-1, y-1) - 2*get_v(1, x-1, y-1)
    b1 = Map[0][K-1][K-1] - b2
    w2 = Map[1][K-1][K-1] - w1
    ans = max(ans, b1+w1, b2+w2)

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

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m = A[0]
for i in range(61):
    cnt0 = cnt1 = 0
    if m < 2 ** i:
        break
    for a in A:
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)


### FIXED CODE ###

def main():
    n = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = 0
    mod = 10 ** 9 + 7
    m=A[0]
    for i in range(61):
        cnt0 = cnt1 = 0
        if m < 2 ** i:
            break
        for j, a in enumerate(A):
            if a < 2 ** i:
                cnt0 += n - j
                break
            if (a >> i) & 1:
                cnt1 += 1
            else:
                cnt0 += 1
        ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
        ans %= mod

    print(ans)

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

from collections import deque
import sys


def input():
    return sys.stdin.readline().strip()


N, M = map(int, input().split())
graph = {i: set() for i in range(N)}
for _ in range(M):
    A, B = map(lambda x: int(x) - 1, input().split())
    graph[A].add(B)
    graph[B].add(A)

tokens = [-1] * N
visited = {0}
q = deque([0])
while q:
    v = q.popleft()
    visited.add(v)
    for nv in graph[v] - visited:
        if tokens[nv] < 0:
            tokens[nv] = v
        q.append(nv)
if -1 in tokens[1:]:
    print('No')
else:
    print('Yes')
    [print(t + 1) for t in tokens[1:]]


### FIXED CODE ###

from collections import deque, defaultdict
import sys


def input():
    return sys.stdin.readline().strip()


N, M = map(int, input().split())
graph = defaultdict(set)
for _ in range(M):
    A, B = map(lambda x: int(x) - 1, input().split())
    graph[A].add(B)
    graph[B].add(A)
if len(set(graph.keys())) != N:
    print('No')
    exit()

tokens = [-1] * N
visited = {0}
q = deque([0])
while q:
    v = q.popleft()
    visited.add(v)
    for nv in graph[v]:
        if nv in visited:
            continue
        if tokens[nv] < 0:
            tokens[nv] = v
            q.append(nv)

print('Yes')
[print(t + 1) for t in tokens[1:]]