peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
s = input()
d = [[0]*2 for _ in range(len(s)+1)]
count_r = 0
count_l = 0
ans = 0
for i in range(len(s)):
    if s[i] == "<":
        d[i+1][0] = d[i][0]+1
    else:
        d[i+1][0] = 0
for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        d[i][1] = d[i+1][1]+1
    else:
        d[i][1] = 0
for i in range(len(s)+1):
    ans += max(d[i])
print(ans)
# Judge status: Accepted
h,w=map(int,input().split())
if h==1 or w==1:
    print(1)
else:
    print((h*w)//2+(h*w)%2)
# Judge status: Accepted
a,b,k=map(int,input().split())
num=set([])
for i in range(a,min(a+k,b+1)):
    num.add(i)

for j in range(max(a,b-k+1),b+1):
    num.add(j)

for ans in sorted(list(num)):
    print(ans)
# Judge status: Accepted
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
q = deque([0])
pre = [-1 for _ in range(n)]
while q:
    v = q.popleft()
    for t in g[v]:
        if pre[t] == -1:
            pre[t] = v
            q.append(t)
print('Yes')
for i in range(1, n):
    print(pre[i]+1)
# Judge status: Wrong Answer
N, M = map(int, input().split())
print(N*(N-1)+M*(M-1))
# Judge status: Wrong Answer
mod=(10**9)+7
n=int(input())
a=list(map(int,input().strip().split(' ')))
s=0
for x in a:
	s= (s+x)%mod
s=(s**2)%mod
t=0
for x in a:
	t= (t+ x**2)%mod
ans=((((s-t)%mod+mod)%mod)//2)
print(ans%mod)
# Judge status: Accepted
s = input()
l = len(s) - 7
print("YES" if any(s[:i] + s[i+l:] == "keyence" for i in range(8)) else "NO")
# Judge status: Wrong Answer
N = int(input())

lst = list()
for i in range(1, N+1):
    s, p = input().split()
    lst.append({"id":i, "s":s, "p":p})

lst.sort(key=lambda x:x["p"], reverse=True)
lst.sort(key=lambda x:x["s"])

for i in range(0, len(lst)):
    print(lst[i]["id"])
# Judge status: Wrong Answer
if __name__ == '__main__':
    (n, a, b) = [int(e) for e in input().split()]
    ans = (int(n/(a+b)))*a
    if n%(a+b) == 0:
        print(ans)
    elif n%(a+b) > a:
        print(ans + a)
    else:
        print(ans + a - n%(a+b) - 1)
# Judge status: Wrong Answer
NUM=[59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

N = int(input())

count=0
for val in NUM:
    if N>=val:
        #print(val, N//val)
        count+=N//val
        N=N%val
print(count)
# Judge status: Accepted
n = int(input())
xy = []
for _ in range(n):
	xy.append([int(x) for x in input().split()])
dis = 0
for x1, y1 in xy:
	for x2, y2 in xy:
		#print(x1,y1,x2,y2)
		dis += ((x1 - x2)**2 + (y1 - y2)**2)**0.5
print(dis/n)
# Judge status: Wrong Answer
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    N = int(inp.readline().strip())

    r = 0
    for i in range(N - 1):
        r += (i + 1)

    return r


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()
# Judge status: Accepted
A = {i-97:chr(i) for i in range(97,123)}
B = {v:k for k,v in A.items()}
s = list(input().strip())
K = int(input())
for i in range(len(s)-1):
    if s[i]!="a" and K>=26-B[s[i]]:
        K -= (26-B[s[i]])
        s[i]="a"
k = K%26
ind = (B[s[-1]]+k)%26
s[-1] = A[ind]
print("".join(s))
# Judge status: Wrong Answer
n = int(input())
cou = 0
for i in range(1,n+1):
  i = str(i)
  if i[0]!="0" and i[-1]!="0":
    if int(i[0])>int(i[-1]):
      cou +=  (9**(len(i)-1)-1)//8
    elif int(i[0])<int(i[-1]):
      cou += (9**(len(i)-2)-1)//8
  #print(i,cou)

cou *= 2
    
l = [0 for i in range(9)]
for i in range(1,n+1):
  i = str(i)
  if i[0]==i[-1]:
    l[int(i[0])-1] += 1
l1 = [i*i for i in l]
print(sum(l1)+cou)
# Judge status: Accepted
def resolve():
    n=input()
    if '9' in n:
        print('Yes')
    else:
        print('No')
resolve()
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

roster = {}
for i in range(n):
    roster[a[i]] = i+1

ans = ""
for i in range(1, n+1):
    ans += str(roster[i]) + " "

print(ans.rstrip())
# Judge status: Wrong Answer
print("Yes" if int(input())<=30 else "No")
# Judge status: Wrong Answer
K,S=map(int,input().split())
ans=0
t=S//3
for x in range(K+1):
  if 0<=S-x and S-x<=2*K:
    ans+=1
print(ans*(ans+1)//2)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
if n==1:
    print(a[0]+b[0])
    quit()
for i in range(n):
    if ans<sum(a[:i])+sum(b[i:])+b[i-1]:
        ans=sum(a[:i])+sum(b[i:])+b[i-1]
print(ans)
# Judge status: Wrong Answer
from itertools import groupby
n, a, b, c, d = map(int, input().split())
s = input()

g = groupby(s[a:c])
h = groupby(s[b:d])

for i, j in g:
    if i == "#" and len(list(j)) > 1:
        print("No")
        exit()

for i, j in h:
    if i == "#" and len(list(j)) > 1:
        print("No")
        exit()

if c < d:
    print("Yes")
    exit()

e = groupby(s[b:d])
for i, j in e:
    if i == "." and len(list(j)) > 2:
        print("Yes")
        exit()

print("No")
# Judge status: Accepted
A,B,C,k = map(int,input().split())
s1 = A-B
s2 = B-A
if k%2 == 0:
    print(s1)
elif k%2 == 1:
    print(s2)
# Judge status: Accepted
n=int(input())
txy=[]
txy.append([0,0,0])
for _ in range(n):
    txy.append(list(map(int,input().split())))
ans = 'Yes'
for i in range(1,len(txy)):
    t_=txy[i][0]-txy[i-1][0]
    d_=abs(txy[i][1]-txy[i-1][1])+abs(txy[i][2]-txy[i-1][2])
    if t_ >= d_ and (t_ - d_) % 2 == 0:
        pass
    else:
        ans='No'
        break
print(ans)
# Judge status: Accepted
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))

from collections import Counter
D = dict(Counter(A))

for i in range(M):
    B,C = list(map(int,input().split()))
    D[C]=D.get(C,0)+B

K = sorted(list(D.keys()),reverse=True)

out = 0
cnt = 0
now = 0
while cnt<=N-1:
    if D[K[now]]>0:
        out += K[now]
        D[K[now]] += -1
        cnt+=1
    else:
        now+=1
print(out)
# Judge status: Wrong Answer
a,b=map(int,input().split())
n=999
l=[1]*n
for i in range(1,n):
    l[i]=l[i-1]+(i+1)
for j in range(n):
    if l[j-1]<=a<=l[j]:
        print(l[j]-a)
        break
# Judge status: Accepted
H,W = map(int,input().split())
if H==1 or W==1:
    print(1)
else:
    print((H*W+1)//2)
# Judge status: Wrong Answer
s = input()
if s[0] != 9 and s[1] != 9:
  print('No')
else:
  print('Yes')
# Judge status: Wrong Answer
n = int(input())

ans = ""
while n != 0:
    rest = n % 2
    if rest == 1:
        ans += "1"
    else:
        ans += "0"

    n = (n - rest) // -2

if ans == "":
    ans += "0"

print(reversed(ans))
# Judge status: Accepted
if (int(input())%500)<=int(input()):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
data = input()

if data.find("7") != -1:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
A,B,C = map(int, input().split())

print('No' if C < A or B < C else 'Yes')
# Judge status: Accepted



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

rui=[]
rui.append(p[0]/2+0.5)
for i in range(1,n):
    rui.append(rui[i-1]+(p[i]/2+0.5))

#print(rui)
ans=[]
ans.append(rui[k-1])
for i in range(n-k):
    ans.append(rui[k+i]-rui[i])
    #print(ans)
print(max(ans))
# Judge status: Accepted
from math import atan,degrees
a,b,x = map(int,input().split())

if x >= a**2*b/2:
    print(degrees(atan(2*(a**2*b-x)/a**3) ))
elif x < a**2*b/2:
    print(degrees(atan(b**2*a/(2*x))))
# Judge status: Accepted
s=input()
x=0
if s[0]=="A" and s[1]!="C" and s[-1]!="C":
    for i in range(len(s)):
        if s.count("C")==1:
            if s[i].isupper():
                x+=1
        else:
            print("WA")
            exit()
    if x==2:
        print("AC")
    else:
        print("WA")

else:
    print("WA")
# Judge status: Accepted
def abc170_d():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    Amax = A[-1]
    check = [False] * (Amax + 1)
    ans = 0
    for i in range(N):
        if check[A[i]]: continue
        if not(i < N-1 and A[i] == A[i+1]): ans += 1
        k = 1
        while k*A[i] <= Amax:
            check[k*A[i]] = True
            k += 1
    print(ans)

abc170_d()
# Judge status: Accepted
N, M = map(int, input().split())
A = set(i//2 for i in map(int, input().split()))
B = []
for i in A:
	B = B + [0]
	while i % 2 == 0:
		i //= 2
		B[-1] += 1
if len(set(B)) == 1:
	m = max(A)
	A.remove(m)
	base = 0
	for i in range(m,M+1,2*m):
		semi = True
		for j in A:
			if i % j != 0 or (i // j) % 2 == 0:
				semi = False
				break
		if semi:
			base = i
			break
	if base == 0:
		print(0)
	else:
		print(((M // base) + 1)//2)
else:
	print(0)
# Judge status: Wrong Answer
S = input()
Q = int(input())

rev = 0
for _ in range(Q):
  TFC = input()
  if len(TFC) == 1: # T == 1
    rev ^= 1
  else:
    T, F, C = (i for i in TFC.split())  
    if F == '1' and rev:
      S = S + C
    else:
      S = C + S

if rev:
  print(S[::-1])
else:
  print(S)
# Judge status: Wrong Answer
d=int(input())
c=list(map(int,input().split()))
d=0
f=0
for i in range(26):
    g=sum(list(map(int,input().split())))
    if g>d:
        d=g;f=i
for i in range(d):print(f)
# Judge status: Wrong Answer
A=list(map(int,input().split()))
for i in range(4):
    if A[i]==0:
        print(i+1)
# Judge status: Accepted
x=int(input())

while True:

    i=2
    flag=True
    while i*i<=x:
        if x%i==0:
            flag=False
            break
        i+=1
    
    if flag:
        print(x)
        break
    
    x+=1
# Judge status: Accepted
n = list(input())
s = 0
for a in n:
    s += int(a)

if len(n) >= 2:
    if int(n[0]) >= 2:
        print(max(s, (len(n)-1)*9+int(n[0])-1))
    else:
        print(max(s, (len(n)-1)*9))
else:
    print(int(n[0]))
# Judge status: Wrong Answer
#!/usr/bin/env python3
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
f = lambda j: j not in a

mod = 10**9+7

dp = [0] * -~n
dp[0] = 1
dp[1] = f(1)

for i in range(2, -~n):
    dp[i] += (dp[i - 1] + dp[i - 2]) * f(i) % mod

print(dp[n])
# Judge status: Accepted
n = int(input());

s = [input() for i in range(n)]

ac = wa = tle = re = 0

for s_kind in s:
    if s_kind == "AC":
        ac += 1
    elif s_kind == "WA":
        wa += 1
    elif s_kind == "TLE":
        tle += 1
    elif s_kind == "RE":
        re += 1
    
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)
# Judge status: Accepted
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
a,b=[0],[0]
for i in range(n):
	a.append(a[i]+A[i])
for i in range(m):
	b.append(b[i]+B[i])
ans=0;j=m
for i in range(0,n+1):
	curr=a[i]
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)
# Judge status: Accepted
N,K=map(int,input().split())
A=list(map(int,input().split()))
N=N-1
K=K-1
if N==K:
    print(1)
    exit()
if N%K==0:
    print(N//K)
else:
    print(N//K+1)
# Judge status: Wrong Answer
import math
N,X=map(int,input().split())
x=[abs(i-X) for i in list(map(int,input().split()))]
print(min(x))
# Judge status: Accepted
s = input()
print("Good" if s[0] != s[1] and s[1] != s[2] and s[2] != s[3] else "Bad")
# Judge status: Accepted
N = int(input())
s = [input() for i in range(N)]
alpha = "abcdefghijklmnopqrstuvwxyz"
ans = ''
for i in alpha:
    min_ = float('Inf')
    for sj in s:
        cnt = 0
        for elem in sj:
            if elem == i:
                cnt += 1
        min_ = min(min_, cnt)
    ans += i * min_
print(ans)
# Judge status: Accepted
W,a,b = map(int, input().split())
if a+W <= b :
  print(b-(a+W))
elif b+W<= a :
  print(a-(b+W))
else :
  print( 0)
# Judge status: Wrong Answer
N = int(input())
NR = int(N**0.5)
count = 0
for i in range(1,int(N/2)):
    if int(N/i)-N/i == 0:
        count += int(N/i)-1
    else:
        count += int(N/i)

count += int(N/2)
print(count)
# Judge status: Wrong Answer
n=int(input(''))
A=10**9+7
if n==1:
    print(0)
elif n==2:
    print(2)
elif n>=3:
    e=1
    for i in range(n):
        e=e*10
        if e>=A:
            e=e%A
    
    d=1
    for i in range(n):
        d=d*8
        if e>=A:
            e=e%A

    r=e-d
    if r<A:
        r=r+A

    print((r)%(10**9+7))
# Judge status: Wrong Answer
N = int(input())
res = 1
max = 1
for i in range(1, N+1):
    cnt = 0
    n = i
    while True:
        if n%2 != 0:
            break
        else:
            n = n//2
            cnt += 1
    if cnt > max:
        res = i
        max = cnt
print(res)
# Judge status: Accepted
x, y, z = map(int, input().split())
x, y = y, x
x, z = z, x
print(x, y, z)
# Judge status: Wrong Answer
n,m=map(int,input().split())
print((m//2+n)//2)
# Judge status: Wrong Answer
N = int(input())
H = list(map(int,input().split()))

length = [0]
i = 0
while i != N-1:
  if H[i+1] <= H[i]:
    i += 1
  else:
    length.append(i+1)
    i += 1

length.append(N-1)
res = 0
for j in range(len(length)-1):
  res = max(res,length[j+1]-length[j])
    
print(res)
# Judge status: Accepted
import sys
import numpy as np
n = int(input())

dp = list(map(int, sys.stdin.readline().split()))

for i in range(n-1):
    a, b, c = list(map(int, sys.stdin.readline().split()))
    dp0, dp1, dp2 = dp
    dp[0] = max(dp1+a,dp2+a)
    dp[1] = max(dp0+b,dp2+b)
    dp[2] = max(dp0+c,dp1+c)
print(max(dp))
# Judge status: Accepted
a,b = map(int,input().split())
if a == b:
    print(a+b)
elif a > b:
    print(a+(a-1))
else:
    print(b+(b-1))
# Judge status: Accepted
a,b,c = map(int, input().split())
d = a + b
if d >= c:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
temp=int(input())
if(temp<=30):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import itertools
a = []
cnt_list = []
for _ in range(3):
    a += map(int, input().split())
n = int(input())
for _ in range(n):
    b = int(input())
    for i, j in enumerate(a):
        if b == j:
            cnt_list.append(i)
ans = 'No'
if len(cnt_list) > 2:
    cnt_list = set(cnt_list)
    for k in list(itertools.permutations(cnt_list, 3)):
        if sum(k) % 3 == 0:
            ans = 'Yes'
print(ans)
# Judge status: Accepted
α=input()
if α.isupper()==True:
    print('A')
else:
    print('a')
# Judge status: Accepted
ab, bc, ca = map(int, input().split())
print(int(ab*bc/2))
# Judge status: Wrong Answer
S = input()
f=0
l=0
for i in range(len(S)):
    if(S[i] =="A"):
        f = i+1
for j in range(len(S)-1,0,-1):
    if(S[j] == "Z"):
        l = j+1
print(l-f+1)
# Judge status: Accepted
import sys
sys.setrecursionlimit(200000) #追加
S = [-1]*(101010)
def opt_S(h,n):
    if(n == 0):return 0
    elif(n == 1):return abs(h[1]-h[0])
    else :
        if(S[n] != -1):return S[n]
        s1 = opt_S(h,n-1) + abs(h[n-1]-h[n])
        s2 = opt_S(h,n-2) + abs(h[n-2]-h[n])
        S[n] = min(s1,s2)
        return S[n]



N = int(input())
h = list(map(int,input().split()))
print(opt_S(h,N-1))
# Judge status: Accepted
#!/usr/bin/env python3
import sys


def solve(N: int):
    answer = 0
    for i in range(1,N+1):
        if i%3 == 0 or i%5 == 0:
            continue
        else:
            answer += i
    print(answer)
    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()
# Judge status: Wrong Answer
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
score = {'r':p, 's':r, 'p':s}
from collections import deque
past = deque([])

ans = 0
for i in range(n):
  past.append(t[i])
  if i < k:
    ans += score[t[i]]
  else:
    if past.popleft() != t[i]:
      ans += score[t[i]]
print(ans)
# Judge status: Wrong Answer
n, k, s = map(int, input().split())
A = [s+1]*n
for i in range(k):
    A[i] = s
print(*A)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))

now = 1
for ai in a:
    if ai == now:
        now += 1

if now == 1:
    print(-1)
else:
    print(N - now + 1)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
A.sort()

n = A.pop()
A.sort(key=lambda a: abs(a - n // 2))
r = A[0]
print(n, r)
# Judge status: Accepted
N= int(input())
if N%2==0:
    cand = list(range(1,N,2))
else:
    cand = list(range(1,N+1,2))

ans = 0
num = 0
for n in range(1,N+1):
    num = 0
    for c in cand:
        if n%c==0:
            num+=1
    if num ==8:
        ans+=1
print(ans)
# Judge status: Accepted
import math
# a=int(input())
#b=int(input())
# c=[]
# for i in b:
#     c.append(i)
e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]
cal=1
for i in range(e1-e2):
    if f[i]>=f[i+e2]:
        print("No")
    else:
        print("Yes")
# Judge status: Accepted
#!/usr/bin/env python3

def main():
    A, B, C = map(int, open(0).read().split())

    m = A*B*C
    ans = min(abs(2*A*C*(B//2) - m), abs(2*C*B*(A//2) - m), abs(2*B*A*(C//2) - m))

    print(ans)


main()
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) - min(a) <= 1:
  print("Yes")
  exit(0)
for i in range(N - 1):
  if a[i + 1] - a[i] < 0:
    a[i] -= 1
  if a[i] - a[i + 1] < 0:
    a[i + 1] -= 1
for i in range(N - 1):
  if a[i + 1] < a[i]:
    print("No")
    exit(0)
print("Yes")
# Judge status: Accepted
x = int(input())

for i in range(x,10**6):
    for k in range(2,i):
        if i % k != 0:
            continue
        else:
            break
    else:
        break
print(i)
# Judge status: Accepted
n,m=map(int,input().split())
st=[]
ch=[]
def mht(ax,ay,bx,by):
  return abs(ax-bx)+abs(ay-by)

for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  ax=i[0]
  ay=i[1]
  mn=1000000000
  for (j,k) in zip(ch,range(len(ch))):
    bx=j[0]
    by=j[1]
    mh=mht(ax,ay,bx,by)
    if mh<mn:
      mn=mh
      nm=k
  print(nm+1)
# Judge status: Accepted
n = int(input())
s = input()
t = input()

idx = 0
ct = 0

for i in s:
    if i == t[idx]:
        ct += 1
        idx += 1
        
print(n*2 - ct)
# Judge status: Wrong Answer
s=input()
al = list('abcdefghijelmnopqrstuvwxyz')
for s0 in s:
    if s0 in al:
        al.remove(s0)
if len(al) == 0:
    print(None)
else:
    print(al[0])
# Judge status: Wrong Answer
n = int(input())
if n == 1:
    print("a")
elif n == 2:
    print("aa")
    print("ab")
elif n == 3:
    print("aaa")
    print("aab")
    print("aba")
    print("abb")
    print("abc")
# Judge status: Accepted
n,m=map(int,input().split())
h=list(map(int,input().split()))
good=[True]*n
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    if h[a]<h[b]:
        good[a]=False
    elif h[b]<h[a]:
        good[b]=False
    elif h[b]==h[a]:
        good[a]=False
        good[b]=False
print(good.count(True))
# Judge status: Accepted
n = int(input())
a = int(input())

b = n % 500

if a >= b:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
A,B,C=map(int,input().split())
if A==B==C:
    print('No')
elif A!=B and B!=C and A!=C:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
def check_month(month):
    return 1 <= int(month) <= 12

S = input()

ls = S[:2]
rs = S[2:]

if check_month(ls) and check_month(rs):
    print('AMBIGUOUS')
elif check_month(ls) and not check_month(rs):
    print('MMYY')
elif not check_month(ls) and check_month(rs):
    print('YYMM')
else:
    print('NA')
# Judge status: Accepted
I=lambda : list(map(int,input().split()))

n,m = I();md=10**9+7;p=0;a=1
dp=[0,1];l=[0]*(10**5+2)
for _ in range(m):
    x=int(input())
    l[x]=1
for i in range(1,n+1):
    if l[i]:
        dp.append(0)
    else:
        dp.append((dp[-1]+dp[-2])%md)
print(dp[-1])
# Judge status: Accepted
a,b = map(int, input().split())

if a-b >= 2:
    print(a+(a-1))
elif b-a >= 2:
    print(b+(b-1))
else:
    print(a+b)
# Judge status: Accepted
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)

ans = [-1] * n
from collections import deque
d = deque([0])
while d:
    u = d.popleft()
    for v in G[u]:
        if ans[v] == -1:
            ans[v] = u
            d.append(v)

if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for v in ans[1:]:
        print(v + 1)
# Judge status: Wrong Answer
N=int(input())
s=list(input())
t=list(input())
f=s+t
if s==t:
    print(''.join(s))
    exit()
for i in range(0,N):
    if s[-i:]==t[:i]:
        f=s+t[i:]
print(''.join(f))
# Judge status: Wrong Answer
n = 8
a = list(map(int, '1 2 1 4 2 1 4 1'.split()))
count_dict = {}
total_sum = 0
for i in a:
    if i not in count_dict:
        count_dict[i] = a.count(i)
        total_sum += (a.count(i))*(a.count(i)-1)//2
for i in a:
    print(total_sum - (a.count(i)*(a.count(i)-1)//2) + (a.count(i)-1)*(a.count(i)-2)//2)
# Judge status: Wrong Answer
N, K = map(int, input().split())
a = list(map(int, input().split()))
#index = a.index(1)
#print(index)

if K == 2:
    print(K-1)
else:
    if N == K:
        print(1)
    elif (N-K) % (K-1) != 0:
        print(int((N-K)/(K-1))+2)
    else:
        print(int((N-K)/(K-1))+1)
# Judge status: Accepted
N = int(input())
i = 0
total = 0
while True:
    total += i
    if total >= N:
        tmp = i
        break
    i += 1

for j in range(tmp, 0, -1):
    if N - tmp >= 0:
        N -= tmp
        print(tmp)
    if N == 0:
        break
    tmp -= 1
# Judge status: Wrong Answer
n,d = map(int,input().split())
print(n//(2*d+1)+1)
# Judge status: Accepted
S=input()

if int(S[5:7])>=5:
    print("TBD")
else:
    print("Heisei")
# Judge status: Accepted
import math
N,D = map(int,input().split())
X = [0]*N
total = 0
cnt = 0
for i in range(N):
  X[i] = list(map(int,input().split()))
for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      total += abs(X[j][k]-X[i][k])**2
    if math.sqrt(total)%1==0:
      cnt += 1
    total=0
print(cnt)
# Judge status: Accepted
import sys
W, H, N = map(int, sys.stdin.readline().split(" "))
Map = [list(map(int,sys.stdin.readline().split(" "))) for i in range(N)]
L = 0
R = W
B = 0
T = H
 
for i in Map:
  if i[2] == 1:
    l = i[0]
    L = max(L, l)
  if i[2] == 2:
    r = i[0]
    R = min(R, r)
  if i[2] == 3:
    b = i[1]
    B = max(B, b)
  if i[2] == 4:
    t = i[1]
    T = min(T, t)
    
if R - L > 0 and T - B > 0:
  print((R - L) * (T - B))
else:
  print(0)
# Judge status: Accepted
def main():
    num = int(input())

    def ggg():
        for divisor in range(1, num + 1):
            quotient = num // divisor
            yield (quotient + 1) * quotient * divisor // 2

    print(sum(ggg()))


if __name__ == '__main__':
    main()

# Python 3.8.2: 1332 ms
# Pypy 3 (7.3.0): 172 ms
# Judge status: Accepted
li = list(map(int,input().split()))
for i in range(len(li)):
    if 0==li[i]:
        print(i+1)
# Judge status: Accepted
N = int(input())
ans = 0
d = 2
while d*d <= N:
  e = 0
  while N%d == 0:
    e+=1
    N//=d
  i=1
  while i<=e:
    ans+=1
    e-=i
    i+=1
  d+=1

if N>1:
  ans+=1
print(ans)
# Judge status: Wrong Answer
n = int(input())

stations = []
for _ in range(n-1):
  stations.append(list(map(int, input().split())))

me = 0
for i in range(n-1):
  remain = n - i - 1
  cost = 0
  time = 0
  for r in range(remain):
    c, s, f = stations[r+i]
    if time < s:
      time = s
    else:
      if time - s < s:
        time = s*2
      else:
        time = s + ((time - s)//f)*f
    time += c
  print(time)
  
print(0)
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], -x[0]))
day = 0
ans = 0
for a, b in ab:
    if day + a <= m:
        ans += b
        day += 1
print(ans)