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

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M = LI()
ab = []
for i in range(N):
    ab.append(LI())

ab.sort()
candidates = []

ans = 0
s = 0
for i in range(1, M+ 1):
    for j in range(s, N):
        a,b = ab[j]
        if a <= i:
            candidates.append(b)
        else:
            s = j
            break
    candidates.sort()
    if len(candidates) > 0:
        # print(candidates)
        ans += candidates[-1]
        candidates = candidates[:-1]

print(ans)



### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
import heapq

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M = LI()
ab = []
for i in range(N):
    ab.append(LI())

ab.sort()
candidates = []

ans = 0
s = 0
for i in range(1, M+ 1):
    for j in range(s, N):
        a,b = ab[j]
        if a <= i:
            heapq.heappush(candidates, -b)
        else:
            s = j
            break
    else:
        s = j + 1
    if len(candidates) > 0:
        # print(candidates)
        ans += -1 * heapq.heappop(candidates)

print(ans)
"""
4 3 2

3 2 3 1
2 3 1


"""
### BUGGY CODE ###

n = int(input())
A = [int(i) for i in input().split()]
S = [sum(A[:i]) for i in range(n+1)]
out = 0
for i in set(S):
    num = S.count(i)
    out += num*(num-1)//2
print(out)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i] + A[i]
def hello(data):
    dt = Counter()
    for i in data:
        dt[str(i)] += 1
    return dt
num = hello(S)
out = [i*(i-1)//2 for i in num.values() if i>1]
print(sum(out))
### BUGGY CODE ###

s = input()
f = 0
for i in range(len(s)-1):
	if f == 0:
		if s.count(s[i]) >= 2:
			t = s[i:]
			a = 0
			for j in range(t.count(s[i])-1):
				b = t[a+1:].index(s[i])
				u = t[:a+b+2]
				a += b
				if u.count(s[i]) > len(u)/2:
					print(i+1, i+a+2)
					f = 1
					break
else:
	if f == 0:
		print("-1 -1")



### FIXED CODE ###

s = input()
for i in range(len(s)-2):
	if s[i] == s[i+1]:
		print(i+1, i+2)
		break
	elif s[i] == s[i+2]:
		print(i+1, i+3)
		break
else:
	if s[-2] == s[-1]:
		print(len(s)-1, len(s))
	else:
		print(-1, -1)
### BUGGY CODE ###

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

for B, C in BC:
  B -= 1
  t = False
  while A[B] > C:
    B -= 1
    if B < 0:
      t = True
      break
  if t:
    continue
  if B == 0:
    A = [C] + A[1:]
  else:
    A = [C]*len(A[:B+1]) + A[B+1:]
  A.sort()
print(sum(A))

### FIXED CODE ###

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key = lambda x: -x[1])

for B, C in BC:
  A.extend([C]*B)
  if len(A) > N*2:
    break
A.sort(reverse = True)
print(sum(A[:N]))
### BUGGY CODE ###

N = int(input())
S = input()
moji = {'R', 'G', 'B'}

count = 0
for j in range(1, N-1):
    sj = S[j]
    for i in range(0, j):
        si = S[i] 
        if si == sj:
            continue
        
        diff_m = moji - {sj, si}
        m = list(diff_m)[0]
        c = S.count(m, j+1, N)

        if (j+j-i) < N:
            sk = S[j + j - i]
            if sk != sj and sk != si:
                c -= 1
        count += c

print(count)

### FIXED CODE ###

N = int(input())
S = input()
moji = {'R', 'G', 'B'}

count = 0
for j in range(1, N-1):
    sj = S[j]
    diff_m = moji - {sj}
    rem_moji = list(diff_m)
    for mi, mj in zip(rem_moji, rem_moji[::-1]):
        ci = S.count(mi, 0, j)
        ck = S.count(mj, j+1, N)
        count += ci * ck

    l = min([j+1, N - j])
    for d in range(1, l):
        si = S[j-d]
        sk = S[j+d]
        if si != sj and sj != sk and sk != si:
            count -= 1

print(count)
### BUGGY CODE ###

def factorization(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])

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

    return arr


def main():
    n = int(input())
    al = list(map(int, input().split())) 
    lcm_dic = {}
    for a in al:
        fac = factorization(a)
        for f in fac:
            lcm_dic.setdefault(f[0],0)
            lcm_dic[f[0]] = max(f[1], lcm_dic[f[0]])
    lcm = 1
    for prim, cnt in lcm_dic.items():
        lcm *= (prim**cnt)
    # print(lcm)

    ans = 0
    for a in al:
        ans += lcm//a
        ans%=(10**9+7)
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
from collections import deque, Counter, defaultdict

input = sys.stdin.readline
MOD = (10**9+7)

def factorization(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])
    if arr==[]:
        arr.append([n, 1])
    return arr


def pow_k1(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x


def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
        x%=MOD
    return K * x


def main():
    n = int(input())
    al = list(map(int, input().split())) 
    lcm_dic = defaultdict(int)
    # lcm_dic = {}
    # al_facs = []
    for a in al:
        fac = factorization(a)
        # a_fac_dic = {}
        for f in fac:
            # lcm_dic.setdefault(f[0],0)
            lcm_dic[f[0]] = max(f[1], lcm_dic[f[0]])
            # a_fac_dic[f[0]] = f[1]
        # al_facs.append(a_fac_dic)


    lcm = 1
    for prime, cnt in lcm_dic.items():
        lcm *= pow_k1(prime,cnt)

    
    ans = sum( [ lcm//a for a in al] ) % MOD
    # ans = 0
    # for a in al:
    #     ans += lcm//a
    #     ans%=MOD


    # ans = 0
    # for al_f in al_facs:
    #     curr_val = 1
    #     for prime, cnt in lcm_dic.items():
    #         if prime in al_f:
    #             curr_val *= pow_k(prime,(cnt-al_f[prime]))
    #             curr_val%=MOD
    #         else:
    #             curr_val *= pow_k(prime,cnt)
    #             curr_val%=MOD
    #     ans += curr_val
    #     ans %= MOD
    print(ans)


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

def counter(x):
        if x == 0:
                return 0
        return counter(x >> 1) + int(bin(x & 1), 2)

N = int(input())
A = []
x = [0] * N 
for i in range(N):
        A.append(int(input()))
        x[i] = [list(map(int, input().split())) for j in range(A[i])]

ans = 0 
for bits in range(1, 1 << N): 
        flag = 1 
        for i in range(N):
                if not int(bin(bits & (1 << i)), 2): 
                        continue
                for j in range(A[i]):
                        if int(bin((bits >> (x[i][j][0] - 1) & 1) ^ x[i][j][1]), 2): 
                                flag = 0 
        if flag:
                ans = max(ans, counter(bits))
print(ans)

### FIXED CODE ###

def counter(x):
        if x == 0:
                return 0
        return counter(x >> 1) + int(bin(x & 1), 2)

N = int(input())
A = []
x = [0] * N 
for i in range(N):
        A.append(int(input()))
        x[i] = [list(map(int, input().split())) for j in range(A[i])]

ans = 0 
for bits in range(1, 1 << N): 
        flag = 1 
        for i in range(N):
                if not int(bin(bits & (1 << i)), 2): 
                        continue
                for j in range(A[i]):
                        if int(bin((bits >> (x[i][j][0] - 1) & 1) ^ x[i][j][1]), 2): 
                                flag = 0 
        if flag:
                ans = max(ans, counter(bits))
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    n = str(N)
    pay = ""
    kuriage = 0
    LEN = len(n)

    for i in range(LEN-1,-1,-1):
        if i != 0:
            if int(n[i-1]) >= 5:
                if int(n[i])+kuriage <= 4:
                    pay += str(int(n[i])+kuriage)
                    kuriage = 0
                else:
                    pay += "0" 
                    kuriage = 1
            else:
                if int(n[i])+kuriage <= 5:
                    pay += str(int(n[i])+kuriage)
                    kuriage = 0
                else:
                    pay += "0" 
                    kuriage = 1
        else:
            if int(n[i])+kuriage <= 5:
                pay += str(int(n[i])+kuriage)
                kuriage = 0
            else:
                pay += "0" 
                kuriage = 1

    if kuriage == 1:
        pay += "1"
    
    pay = pay[::-1]

    oturi = int(pay)-N
    pay_count = 0
    oturi_count = 0

    for i in pay:
        pay_count += int(i)
    
    for i in str(oturi):
        oturi_count += int(i)

    # print(pay)
    # print(oturi)
    print(pay_count+oturi_count)
    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
    solve(N)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: str):
    n = list(map(int,list(N)))
    kuriage = 0
    LEN = len(n)
    pay_count = 0

    for i in range(LEN-1,-1,-1):
        if i != 0:
            if n[i-1] >= 5:
                if n[i]+kuriage <= 4:
                    pay_count += n[i]+kuriage
                    kuriage = 0
                else:
                    pay_count += 10-(n[i]+kuriage)
                    kuriage = 1
            else:
                if n[i]+kuriage <= 5:
                    pay_count += n[i]+kuriage
                    kuriage = 0
                else:
                    pay_count += 10-(n[i]+kuriage)
                    kuriage = 1
        else:
            if n[i]+kuriage <= 5:
                pay_count += n[i]+kuriage
                kuriage = 0
            else:
                pay_count += 10-(n[i]+kuriage)
                kuriage = 1

    if kuriage == 1:
        pay_count += 1
    print(pay_count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)
    solve(N)

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

def factorial(n):
  fact = 1
  for i in range(2, n+1):
    fact *= i%(10**9+7)
  return fact

N, M = map(int, input().split())
MOD = 10**9+7
if N == M:
  print(2*factorial(N)**2 % MOD)
elif abs(N-M) == 1:
  print(factorial(min(N, M))**2 * max(N, M) % MOD)
else:
  print(0)

### FIXED CODE ###

def factorial(n):
  fact = 1
  for i in range(2, n+1):
    fact = fact * i % (10**9+7)
  return fact

N, M = map(int, input().split())
MOD = 10**9+7
if N == M:
  print(2*factorial(N)**2 % MOD)
elif abs(N-M) == 1:
  print(factorial(min(N, M))**2 * max(N, M) % MOD)
else:
  print(0)
### BUGGY CODE ###

# C - Tsundoku
import sys
sys.setrecursionlimit(10**9)

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())

la = 0
t = 0
for i in range(N):
    if A[i] + t <= K:
        la += 1
        t += A[i]

lb = 0
t = 0
for i in range(M):
    if B[i] + t <= K:
        lb += 1
        t += B[i]

T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)
    return

dfs(0, 0, T, 0)
print(ans)

### FIXED CODE ###

# C - Tsundoku

import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Asum = [0]
for i in range(N):
    Asum.append(Asum[i] + A[i])

Bsum = [0]
for j in range(M):
    Bsum.append(Bsum[j] + B[j])

ans = 0
for i in range(N+1):
    if Asum[i] > K:
        continue
    tmp = K - Asum[i]
    j = bisect.bisect_right(Bsum, tmp) - 1
    ans = max(ans, i+j)
print(ans)
### BUGGY CODE ###

from itertools import permutations

def WarshallFloyd(M):
    N = len(M)
    for k in range(N):
        for j in range(N):
            for i in range(N):
                M[i][j] = min(M[i][j], M[i][k] + M[k][j])
    return M

INF = 1e10

N, M, K = map(int, input().split())
R = [int(i) - 1 for i in input().split()]
E = [[INF] * N for _ in range(N)]
for a, b, c in (map(int, input().split()) for _ in range(M)):
    a -= 1; b -= 1
    E[a][b] = E[b][a] = c

E = WarshallFloyd(E)
ans = min(sum(E[p[i]][p[i + 1]] for i in range(K - 1)) for p in permutations(R))
print(ans)


### FIXED CODE ###

from itertools import permutations

def WarshallFloyd(M):
    N = len(M)
    for k in range(N):
        for j in range(N):
            for i in range(N):
                M[i][j] = min(M[i][j], M[i][k] + M[k][j])
    return M

INF = 1e10

N, M, K = map(int, input().split())
R = [int(i) - 1 for i in input().split()]
E = [[INF] * N for _ in range(N)]
for a, b, c in (map(int, input().split()) for _ in range(M)):
    a -= 1; b -= 1
    E[a][b] = E[b][a] = c

E = WarshallFloyd(E)
ans = min(sum(E[p[i]][p[i + 1]] for i in range(K - 1)) for p in permutations(R))
print(ans)
### BUGGY CODE ###

from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])

if reverse == 1: q.reverse()
for i in range(len(q)):
    print(q[i],end="")
print()

### FIXED CODE ###

from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))
### BUGGY CODE ###

import numpy as np  # noqa

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

jumps = []
for i in range(K):
    l, r = map(int, input().split())
    jumps.append([l, r])

jumps = np.array(jumps)
dp2 = np.zeros(K + 1)

dp = np.zeros(N + 1)
dp[1] = 1
for i in range(2, N + 1):
    for j, jump in enumerate(jumps):
        mn = max(0, i - jump[1])
        mx = max(mn, i - jump[0])
        if mn > 0:
            dp2[j] -= dp[mn - 1]
        if mx > 0:
            dp2[j] += dp[mx]
        dp[i] = (dp[i] + dp2[j]) % m


print(int(dp[N]))


### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353


@njit((i8, i8[:]), cache=True)
def main(N, LR):
    L, R = LR[::2], LR[1::2]
    K = len(L)
    F = np.zeros(N + 10, np.int64)
    F[0] = 1
    for n in range(1, N + 10):
        F[n] += F[n - 1]
        for k in range(K):
            l, r = L[k], R[k] + 1
            if n - l >= 0:
                F[n] += F[n - l]
            if n - r >= 0:
                F[n] -= F[n - r]
        F[n] %= MOD
    ans = F[N - 1] - F[N - 2]
    return ans % MOD


N, K = map(int, readline().split())
LR = np.array(read().split(), np.int64)

print(main(N, LR))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,readline().split())
a = list(map(int,readline().split()))
c = 1
for i in range(k):
  c *= a[i]
  
for i in range(n-k):
  chk = c*a[k+i]//a[i]
  if chk > c:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,readline().split())
a = list(map(int,readline().split()))
for i in range(n-k):
  chk = a[k+i]
  c = a[i]
  if chk > c:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

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

ans = 1
for i in range(len(box)):
  if i == 0: continue
  tibi = min(box[:i])
  if box[i] <= tibi:
    ans += 1
    
print(ans)

### FIXED CODE ###

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

tibi = box[0]
ans = 1
for i in range(len(box)):
  if i == 0: continue
  if box[i] <= tibi:
    tibi = box[i]
    ans += 1
    
print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(500000)

def input() -> str:
    return sys.stdin.readline().rstrip()

def f(i, j):
    if j <= 0:
        return 0
    if i < 0 and j > 0:
        return float("inf")
    ij = n * j + i
    if ij not in dp:
        dp[ij] = min([f(i - 1, j - k * ab[i][0]) + k * ab[i][1] for k in range((h - 1) // ab[i][0] + 2)])
    return dp[ij]

h, n = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: -x[0])
dp = dict()
print(f(n - 1, h))

### FIXED CODE ###

import sys

def input() -> str:
    return sys.stdin.readline().rstrip()

h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
m = max(a for a, _ in ab)
dp = [0] * (h + m * 2 + 1)
for i in range(-m, h + m + 1):
    if i <= 0:
        dp[i] = 0
    else:
        dp[i] = min(dp[i - a] + b for a, b in ab)
print(min(dp[h:h + m + 1]))
### BUGGY CODE ###

from itertools import product as prod

n, m = [int(x) for x in input().split()]

gr = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    gr[a].append((b, c))
    gr[b].append((a, c))

def dist(i, j, gr=gr):
    tmp_d = float("inf")
    if i == j:
        return 0
    for (n, d) in gr[i]:
        if n == j:
            tmp_d = d
    gr_cp = [[(n, d) for (n, d) in g if n != i] for g in gr]
    routes = [d + dist(n, j, gr=gr_cp) for (n, d) in gr_cp[i]]

    return min(routes + [tmp_d])

ans = 0
for i, j in prod(range(1, n), range(1, n)):
    for (node, d) in gr[i]:
        if node == j and d > dist(i, j):
            ans += 1
print(ans // 2)


### FIXED CODE ###

import copy
from itertools import product as prod

n, m = [int(x) for x in input().split()]

wait = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(n):
    wait[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    wait[a-1][b-1] = c
    wait[b-1][a-1] = c

dist = copy.deepcopy(wait)
for k, i, j in prod(range(n), range(n), range(n)):
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    dist[j][i] = min(dist[j][i], dist[j][k] + dist[k][i])

ans = 0
for i, j in prod(range(n), range(n)):
    if not wait[i][j] == float("inf") and dist[i][j] < wait[i][j]:
        ans += 1

print(ans // 2)
### BUGGY CODE ###

def main():
    N = int(input())
    S = input()

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    result = 0
    l = list(range(N - 1, -1, -1))
    for i in l:
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in l:
            if S[i] == S[j]:
                t = dpi1[j + 1] + 1
                dpi[j] = t
                ji = j - i
                if t > ji:
                    t = ji
                if t > result:
                    result = t
    print(result)


main()


### FIXED CODE ###

N = int(input())
S = input()

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

ans = 0

for i in range(N):
    a = L[i]
    for ii in range(i + 1, N):
        b = L[ii]
        for iii in range(N - 1, ii, -1):
            c = L[iii]
            if a >= b + c:
                continue
            ans += iii - ii
            break

print(ans)

### FIXED CODE ###

import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N - 2):
    a = L[i]
    for ii in range(i + 1, N - 1):
        b = L[ii]
        iii = bisect.bisect_left(L, a + b)
        ans += iii - ii - 1
            
print(ans)
### BUGGY CODE ###

inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = set([])
prev_cnt = 0
now = [1]

while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    prev.add(n)
    elist = []
    for next in Edict[n]:
        if next not in now:
            if next not in prev:
                output[next] = n
                now.append(next)

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")




### FIXED CODE ###

inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = [0 for n in range(N+1)]
prev_cnt = 0
now = [1]

prev[1] = 1
while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    for next in Edict[n]:
        if prev[next] == 0:
            output[next] = n
            now.append(next)
            prev[next] = 1

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")
### BUGGY CODE ###

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

for i in range(M):
    A[N-1] //= 2
    A.sort()

print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
# ヒープキューを使用するために、符号を反転
a = list(map(lambda x: x*(-1), A))
heapq.heapify(a)

tmp = 0
for i in range(M):
    # 商を求める際に一旦、正の数に変換
    tmp = (heapq.heappop(a)*(-1)) // 2
    # 負の数に変換して元に戻す
    heapq.heappush(a, -tmp)

print(sum(a)*(-1))
### BUGGY CODE ###

a,b,c,d = map(int,input().split())
count = 0

for i in range(a,b+1):
  if i%c !=0 and i%d !=0:
    count += 1

print(count)

### FIXED CODE ###

from fractions import gcd
a,b,c,d = map(int,input().split())
cd = gcd(c,d)

#A-1
A1 = (a-1) - (a-1)//c -(a-1)//d +(a-1)//(c*d//cd)
 
#Bまで
B = b - b//c - b//d +b//(c*d//cd)
 
print(B-A1)
### BUGGY CODE ###

n=0
W=0
n,W=map(int,input().split())
dp=[W+1]*(101010)
dp[0]=0
for i in range(n):
    w,v=map(int,input().split())
    j=100000
    while j>=0:
        if dp[j+v]>dp[j]+w:
            dp[j+v]=dp[j]+w
        j-=1
ans=0
for v in range(len(dp)):
    if dp[v]<=W:
        ans=v
print(ans)

### FIXED CODE ###

n=0
W=0
n,W=map(int,input().split())
dp=[W+1]*101010
dp[0]=0
for i in range(n):
    w,v=map(int,input().split())
    j=100000
    while j>=0:
        if dp[j+v]>dp[j]+w:
            dp[j+v]=dp[j]+w
        j-=1
ans=0
for v in range(len(dp)):
    if dp[v]<=W:
        ans=v
print(ans)