Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
S = input()
S = S[::-1]

dp = [-1] * (N + 1)
dp[0] = 0

pos = 0
while pos < N:

    p = pos
    update = False

    for i in range(1, M + 1):
        if p + i > N:
            break
        if S[p + i] == "1":
            continue
        update = True
        pos = p + i
        dp[pos] = dp[p] + 1

    if not update:
        break

if dp[N] == -1:
    print(-1)
    exit()

dp = dp[::-1]
num = dp[0]
ans = []
pos = 0

while num > 0:
    for i in range(1, M + 1):
        if dp[pos + i] == num - 1:
            num -= 1
            pos += i
            ans.append(str(i))

ans = " ".join(ans)
print(ans)


### FIXED CODE ###

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

dp = [-1] * (N + M + 1)
dp[N] = 0
pos = N

while pos > 0:
    dist = dp[pos]
    tmp = pos

    for i in range(1, M + 1):
        if pos - i < 0:
            break
        if S[pos - i] == "0":
            dp[pos - i] = dist + 1
            tmp = pos - i
    if pos == tmp:
        break
    pos = tmp

if dp[0] == -1:
    print(-1)
    exit()

ans = []
cnt = dp[0]
pos = 0
while cnt > 0:
    for i in range(1, M + 1):
        if dp[pos + i] + 1 == cnt:
            ans.append(i)
            pos += i
            cnt -= 1
            break

print(*ans, sep=" ")
n,x = (int(i) for i in input().split())
listx=[int(i) for i in input().split()]
#print(n,x,listx)
listy=[abs(listx[i]-x) for i in range(n)]
listy.sort()
#print(listy)

def gcd(y, x):
    if x == 0:
        return y
    else:
        return gcd(x, y % x) #再帰定義
if x==1:
  ans=listy[0]
else:
  ans=gcd(listy[0],listy[1])
  if n > 2:
    for i in range(n-2):
      ans=gcd(ans,listy[i+2])
  
print(ans)

### FIXED CODE ###

n,x = (int(i) for i in input().split())
listx=[int(i) for i in input().split()]
#print(n,x,listx)
listy=[abs(listx[i]-x) for i in range(n)]
listy.reverse()
#print(listy)

def gcd(y, x):
    if x == 0:
        return y
    else:
        return gcd(x, y % x) #再帰定義
if n==1:
  ans=listy[0]
else:
  if listy[1]==0:
    ans=listy[0]
  else:
    ans=gcd(listy[0],listy[1])
    if n > 2:
      for i in range(0,n-2):
        if listy[i+2]==0:
          ans=ans
        else:
          ans=gcd(ans,listy[i+2])
  
print(ans)
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N = gete(int)

    cur, prev = [0]*3, [0]*3

    for _ in range(N):
        a, b, c = geta(int)
        prev, cur = cur, prev
        cur[0] = max(prev[1], prev[2]) + a
        cur[1] = max(prev[2], prev[0]) + b
        cur[2] = max(prev[0], prev[1]) + c


    print(max(cur))

if __name__ == "__main__":
    main()

### FIXED CODE ###

# dp[i]:  minimum possible total cost to reach Stone i.
# dp[1] = 0
# dp[2] = |h[2]-h[1]|
# dp[i+2] = min{ dp[i] + |h[i]-h[i+2]|,  dp[i+1] + |h[i+1]-h[i+2]| }
# dp[0] = INF, h[0] = INF

INF = 10**9

N, K = map(int, input().split())
h = [INF] + list(map(int, input().split()))

dp = [INF]*(N+1)
dp[1] = 0

for i in range(1, N+1):
    for j in range(1, K+1):
        if i+j > N:
            break

        tmp = dp[i] + abs(h[i] - h[i+j])

        if tmp < dp[i+j]:
            dp[i+j] = tmp

print(dp[N])
from operator import itemgetter
n,m = map(int,input().split())
t = [list(map(int,input().split())) for _ in range(m)]
t.sort(key=itemgetter(0))
c = [i[1] for i in t ]
s = [i[0] for i in t]
# print(c)
x = 0

ans = "aaa"
ans = list(ans)
for i in range(3):
    for j in range(len(s)):
        if i==s[j]-1 :
            if str(c[j])!=ans[i] and ans[i]=="a":
                ans[i]=str(c[j])
            elif  str(c[j])!=ans[i] and ans[i]!="a":
                x =1
# print(ans)

if x==1:
    print(-1)
elif n!=1 and ans[3-n]=="0":
    print(-1)
elif m==0 and n!=1:
    print(-1)
elif m==0 and n==1:
    print(0)
else:
    if ans[3-n]=="a" and max(s)<n and n!=1:
    #     ans[3-n]="1"
    # print(ans)
    for i in range(3):
        if ans[i]=="a":
            ans[i]="0"
    # if ans[n-1]=="0" and max(s)<n and n!=1:
    #     ans[n-1]="1"
    # print(ans)
    ans = int("".join(ans))
    if len(str(ans))>n:
        print(-1)
    else:
        print(ans)

### FIXED CODE ###

from operator import itemgetter
n,m = map(int,input().split())
t = [list(map(int,input().split())) for _ in range(m)]
t.sort(key=itemgetter(0))
c = [i[1] for i in t ]
s = [i[0] for i in t]
# print(c)
x = 0

ans = "a"*n
ans = list(ans)
for i in range(n):
    for j in range(len(s)):
        if i==s[j]-1 :
            if str(c[j])!=ans[i] and ans[i]=="a":
                ans[i]=str(c[j])
            elif  str(c[j])!=ans[i] and ans[i]!="a":
                x =1
# print(ans)

if ans[0]=="0" and n!=1:
    x=1
for i in range(len(ans)):
    if ans[i]=="a":
        ans[i]="0"
# print(ans)
if ans[0]=="0"and n!=1:
    ans[0]="1"
if x==0:
    print(int("".join(ans)))
else:
    print(-1)
def S:
    sample_list = ['Sunny', 'Cloudy', 'Rainy']
random.shuffle(sample_list)
print sample_list
if S==Sunny:
  print(Cloudy)
if S==Cloudy:
  print(Rainy)
if S==Rainy:
  print(Sunny)


### FIXED CODE ###

S=input()
a=["Sunny", "Cloudy", "Rainy"]
print(a[((a.index(S)+1))%3])
l,r,n = map(int,input())
count = 0
for i in range(l,r+1):
  if i % n == 0:
    count += 1
print(count)

### FIXED CODE ###

l,r,n = map(int,input().split())
count = 0
for i in range(l,r+1):
  if i % n == 0:
    count += 1
print(count)
A = int(input())
B = int(input())
C = int(A * B)
print(C)

### FIXED CODE ###

a, b = map(int, input().split())
print(a * b)
n = int(input())
if n < 105:
  print(0)
else:
  ans = 0
  for i in range(n,103,-2):
    count = 1
    for j in range(1,99,2):
      nj = n%j
      if nj == 0:
        count += 1
      if count == 9:
        break
    if count == 8:
      ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = 0
for i in range(1,n+1,2):
  c = 0
  for j in range(1,n+1):
    if i%j == 0:
      c += 1
  if c == 8:
    a +=1
print(a)
n,m = map(int,input().split())
ans = [0]*n
for i in range(n):
    s,c = map(int,input().split())
    if ans[s-1] == 0 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == 0:
    print(-1)
    exit()
print("".join([str(n) for n in ans]))

### FIXED CODE ###

n,m = map(int,input().split())
ans = [99]*n
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == 99 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == 0 and n != 1:
    print(-1)
    exit()
if ans[0] == 99 and n != 1:
    ans[0] = 1
for i in range(n):
    if ans[i] == 99:
        ans[i] = 0


print("".join([str(i) for i in ans]))
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from math import ceil
    K=int(input())
    X,Y=map(int,input().split())
    # defaultは 0 <= Y <= X
    def trans(u,v):
        if(abs(X)<abs(Y)): u,v=v,u
        if(X<0): u=-u
        if(Y<0): v=-v
        return u,v

    x,y=max(abs(X),abs(Y)),min(abs(X),abs(Y))
    if(K%2==0 and (X+Y)&1):
        print(-1)
        return

    # x+y<K
    if(x+y<K and (x+y)&1):
        print(3)
        print(*trans(x,-K+x))
        print(*trans(x+(K+x-y)//2,-(K-x-y)//2))
        print(*trans(x,y))
        return
    if(x+y<K and (not (x+y)&1)):
        print(2)
        print(*trans((x+y)//2,-k+(x+y)//2))
        print(*trans(x,y))
        return

    print(0)
    # x+y>=K
    # c=(-x-y)%K
    # n=ceil((x+y)/K)+(c&1)
    # l=(K*n-x-y)//2
    # print(n)
    # nx,ny=K-l,-l
    # print(*trans(nx,ny))
    # while(nx+K<=x):
    #     nx+=K
    #     print(*trans(nx,ny))
    # nx,ny=x,ny+(K-(x-nx))
    # print(*trans(nx,ny))
    # while(ny+K<=y):
    #     ny+=K
    #     print(*trans(nx,ny))
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from math import ceil
    K=int(input())
    X,Y=map(int,input().split())
    # defaultは 0 <= Y <= X
    def trans(u,v):
        if(abs(X)<abs(Y)): u,v=v,u
        if(X<0): u=-u
        if(Y<0): v=-v
        return u,v

    x,y=max(abs(X),abs(Y)),min(abs(X),abs(Y))
    if(K%2==0 and (X+Y)&1):
        print(-1)
        return

    # x+y<K
    if(x+y<K and (x+y)&1):
        print(3)
        print(*trans(x,-K+x))
        print(*trans(x+(K+x-y)//2,-(K-x-y)//2))
        print(*trans(x,y))
        return
    if(x+y<K and (not (x+y)&1)):
        print(2)
        print(*trans((x+y)//2,-K+(x+y)//2))
        print(*trans(x,y))
        return

    # x+y=K
    if(x+y==K):
        print(1)
        print(*trans(x,y))
        return
    
    # x+y>K
    c=(-x-y)%K
    n=ceil((x+y)/K)+(c&1)
    l=(K*n-x-y)//2
    print(n)
    nx,ny=K-l,-l
    print(*trans(nx,ny))
    while(nx+K<=x):
        nx+=K
        print(*trans(nx,ny))
    nx,ny=x,ny+(K-(x-nx))
    print(*trans(nx,ny))
    while(ny+K<=y):
        ny+=K
        print(*trans(nx,ny))
resolve()
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

Q = []
buffer = sum(EP[:k])
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))

### FIXED CODE ###

import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

buffer = sum(EP[:k])
Q = [buffer]
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))
s = list(1:n)
s = str(s[k])
s = s.lower()
print(s)


### FIXED CODE ###

N, K = (int(i) for i in input().split())
S = list(input())

S[K - 1] = S[K - 1].lower()
print(''.join(S))
import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

s = []
for _ in range(n):
	s.append(input())

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and d[s[i+1].strip(s[i])] == 0:
			d[s[i+1].strip(s[i+1].strip(s[i]))] += 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
		else:
			d[s[i][0]] += 1
			ans.append(s[i][0])
print('Yes')
for i in range(len(ans)):
	print(ans[i])



### FIXED CODE ###

import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

s = []
for _ in range(n):
	s.append(input())

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and s[i+1].strip(s[i]) != '' and d[s[i+1].strip(s[i])] == 0:
			string = s[i+1].strip(s[i+1].strip(s[i]))
			d[string] += 1
			d[s[i].strip(string)] -= 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
		else:
			d[s[i][0]] += 1
			d[s[i][1]] -= 1
			ans.append(s[i][0])
print('Yes')
for i in range(len(ans)):
	print(ans[i])
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
print('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
      
  

### FIXED CODE ###

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

x1=A+B
x2=A-B
x3=A*B

print(max(x1,max(x2,x3)))
#!/usr/bin/env python3
import sys
YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(n: int, A: int, B: int, C: int, s: "List[str]"):
    S = {}
    S[(A,B,C)] = ""
    for i in range(n):
        N = {}
        d = s[i]
        for a,b,c in S:
            path = S[(a,b,c)]
            if d == "AB":
                if b > 0:
                    # A+1,B-1
                    N[(min(n,a+1),b-1,c)] = path + "A"
                if a > 0:
                    N[(a-1,min(n,b+1),c)] = path + "B"
            elif d == "BC":
                if c > 0:
                    # b +1,c -1
                    N[(a, min(n,b + 1), c-1)] = path + "B"
                if b > 0:
                    N[(a, b -1, min(n,c+1))] = path + "C"
            else:
                if c > 0:
                    N[(min(n,a+1),b,c-1)] = path + "A"
                if a > 0:
                    N[(a-1,b,min(n,c+1))] = path + "C"
        if len(N) == 0:
            print(NO)
            exit()
        S = N
    print(YES)
    for a,b,c in S:
        p = S[(a,b,c)]
        for i in p:
            print(i)
        break

    return


# Generated by 1.1.6 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
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, A, B, C, s)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    print("ABC" if S == "ARC" else "ARC")
    return


# Generated by 1.1.6 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()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()
import math
     
    n, a, b = map(int, input().split(" "))
     
    h = []
    for i in range(n):
        h.append(int(input()))
     
    h.sort(reverse=True)
     
     
    def check(count_target, h, a, b):
        count = 0
     
        for i in h:
            if i >= count_target * b:
                count += math.ceil((i - count_target * b) / (a - b))
        return count_target - count
     
     
    l = 1
    r = math.ceil(h[0] / b)
     
     
    while r - l > 1:
        mid = math.floor(l + (r - l) / 2)
     
        if check(mid, h, a, b) < 0:
            l = mid
        else:
            r = mid
     
     
    if check(l, h, a, b) < 0:
        print(int(r))
    else:
        print(int(l))

### FIXED CODE ###

import math

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

h = []
for i in range(n):
    h.append(int(input()))

h.sort(reverse=True)


def check(count_target, h, a, b):
    count = 0

    for i in h:
        if i >= count_target * b:
            count += math.ceil((i - count_target * b) / (a - b))
    return count_target - count


l = 1
r = math.ceil(h[0] / b)


while r - l > 1:
    mid = math.floor(l + (r - l) / 2)

    if check(mid, h, a, b) < 0:
        l = mid
    else:
        r = mid


if check(l, h, a, b) < 0:
    print(int(r))
else:
    print(int(l))
N = int(input())
mons = list(map(int, input().split()))
yush = list(map(int, input().split()))

temp = sum(mons)

for i, yu in enumerate(yush):
    mo = mons[i]
    if (yu >= mo):
        mons[i] = 0
        yush[i] = yu - mo
        
        if (mons[i + 1] > yush[i]):
            mons[i + 1] -= yush[i]
        else:
            monx[i + 1] = 0
        
    else:
        mons[i] = mo - yu
        yush[i] = 0
ans = temp - sum(mons)
print(ans)

### FIXED CODE ###

N = int(input())
mons = list(map(int, input().split()))
yush = list(map(int, input().split()))

temp = sum(mons)

for i, yu in enumerate(yush):
    mo = mons[i]
    if (yu >= mo):
        mons[i] = 0
        yush[i] = yu - mo
        
        if (mons[i + 1] > yush[i]):
            mons[i + 1] -= yush[i]
        else:
            mons[i + 1] = 0
        
    else:
        mons[i] = mo - yu
ans = temp - sum(mons)
print(ans)
data = [
    "{0} {1}".format(s, r)
    for s in ('S', 'H', 'C', 'D')]
    for r in range(1, 13 + 1)
    ]

count = int(input())
for c in range(count):
    card = input()
    data.remove(card)

for c in data:
    print(c)

### FIXED CODE ###

data = [
     "{0} {1}".format(s, r) 
      for s in ('S', 'H', 'C', 'D')
      for r in range(1, 13 +1)
        ]
count = int(input())
for c in range(count):
      card = input()
      data.remove(card)
 
for c in data:
   print(c)
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
i = 0
c = 0
m = list()
while i < n:
    if a[i]==a[i+1]:
        m.append(i)
        i += 1
        c += 1
    i += 1
    if c == 2:
        break
print(m[0]*m[1])

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
i = 0
c = 0
m = list()
while i < n-1:
    if a[i]==a[i+1]:
        m.append(a[i])
        i += 1
        c += 1
    i += 1
    if c == 2:
        break
if c == 2:
    print(m[0]*m[1])
else:
    print(0)
n,m=map(int,input().split())

N=[]

for i in range(n):
    N.append([0,0])

co=0
pe=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='WA':
        N[p-1][0]+=1
    elif N[p-1][1]!=1:
        pe+=N[p][0]
        co+=1
        N[p-1][1]=1

print(str(co)+' '+str(pe))

### FIXED CODE ###

n,m=map(int,input().split())

N=[]

for i in range(n):
    N.append([0,0])

co=0
pe=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='WA':
        N[p-1][0]+=1
    elif N[p-1][1]!=1:
        pe+=N[p-1][0]
        co+=1
        N[p-1][1]=1

print(str(co)+' '+str(pe))
import sys
sys.setrecursionlimit(40000000000)
def knap(n,w,weight,value,dp):
  #  print(n,":",w,":",len(dp),":",len(dp[n]))
    if dp[n][w]!=-1:
        return dp[n][w]
    if n==0:
        dp[n][w]=0
        return 0
    if w==0:
        dp[n][w]=0
        return 0
    if w-weight[n]<0:
        tmp2=knap(n-1,w,weight,value,dp)
        dp[n][w]=tmp2
        return tmp2
    tmp1=knap(n-1,w-weight[n],weight,value,dp)+value[n]
    tmp2=knap(n-1,w,weight,value,dp)
    if tmp1>tmp2:
        dp[n][w]=tmp1
        return tmp1
    else:
        dp[n][w]=tmp2
        return tmp2
        

n,W=map(int,input().split())
weight=[0]
value=[0]
for i in range(n):
    a,b=map(int,input().split())
    weight.append(a)
    value.append(b)
dp=[[-1]*(W+1)]*(n+1)
print(knap(n,W,weight,value,dp))



### FIXED CODE ###

def knap(N,W,weight,value):
    inf=float("inf")
    dp=[[-inf for i in range(W+1)] for j in range(N+1)]
    #各nについて初期化　以下で各ｗについて0この時０とする
    for i in range(W+1):#w+1とは0~w
        dp[0][i]=0
    for i in range(N):#each n 0~N-1
        for w in range(W+1):#w 0~w
            if weight[i]<=w:#=を入れないとぎりぎりの時が困る
                dp[i+1][w]=max(dp[i][w-weight[i]]+value[i],dp[i][w])
            else:
                dp[i+1][w]=dp[i][w]
   # print(dp)
    return dp[N][W]


n,W=map(int,input().split())
w=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
print(knap(n,W,w,v))
i = input()
i1 = list(map(int, i.split() ) )
i2 = i1[0] - i1[1]
i3 = i1[2] - i2
		if i3 < 0:
 				i3 = 0
		else:
 				i3 = i3

print(i3)

### FIXED CODE ###

i = input()
i1 = list(map(int, i.split() ) )
i2 = i1[0] - i1[1]
i3 = i1[2] - i2
if i3 < 0:
 print("0")
else:
 print(i3)
a =input()
print(a.replace("1","x"),replace("9","1").replace("x","9"))

### FIXED CODE ###

a = input()
print(a.replace("1","x").replace("9","1").replace("x","9"))
a, b = map(int, input().split())
print(6 - a - b)


### FIXED CODE ###

a = int(input())
b = int(input())
print(6 - a - b)
# -*- coding: utf-8 -*-

def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))



N,M = input_multiple_number()

ans = [0]*(N)
ans[0] = 1
michi = [[] for i in range(N+1)]
isVisit = [False]*N
isVisit[0] = True

for i in range(M):
	a,b = input_multiple_number()
	michi[a].append(b)
	michi[b].append(a)

def DFS(K):
	for heya in michi[K]:
		if ans[heya-1] == 0:
			ans[heya-1] = K

	for heya in michi[K]:
		if not isVisit[heya-1]:
			isVisit[heya-1] = True
			DFS(heya)

DFS(1)
print("Yes")
for i in ans[1:]:
	print(i)




### FIXED CODE ###

# -*- coding: utf-8 -*-

def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))

N,M = input_multiple_number()

shilve = [-1]*(N+1)
michi = [[] for _i in range(N+1)]

for i in range(M):
	a,b = input_multiple_number()
	michi[a].append(b)
	michi[b].append(a)

que = [1]

while len(que) > 0:
	now_heya = que.pop(0)
	for nexthop in michi[now_heya]:
		if shilve[nexthop] == -1:
			shilve[nexthop] = now_heya
			que.append(nexthop)


print("Yes")
for i in shilve[2:]:
	print(i)
N = input()
a = [input() for i in range(N)]
for i in range(N):
    a, b, c = list.sprit()

    a_2 = a ** 2
    b_2 = b ** 2
    c_2 = c ** 2

    if a_2 == b_2 + c_2 or b_2 == a_2 + c_2 or c_2 == a_2 + b_2:
        print "YES"
    else:
        print "NO"

### FIXED CODE ###

N = input()
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))

for j in range(N):

    x = a[j][0] ** 2
    y = a[j][1] ** 2
    z = a[j][2] ** 2

    if x == y + z:
        print "YES"
    elif y == x + z:
        print "YES"
    elif z == x + y:
        print "YES"
    else:
        print "NO"
n = int(input())
a = input().split()
a_int = list(map(int,a)
col = 400
all_col = 0 
max_c = 8
for i in range(n):
    if a_int > max_c * col:
        all_col += 1
    else:
        ii = int(a_int/col)
        if c[ii] < 1
            c[ii] += 1
        
cnt = c.count(1)
min_c = max(cnt, 1)

print(str(min_c)+' ' +str(max_c))

### FIXED CODE ###

from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))


def main():
    n = input()
    a = readLine_int_list()

    c = []
    _c = [] 

    for i in a:
        rank = i//400
        if rank > 7:
           _c.append(rank) 
        else:    
            c.append(rank)
    
    
    p = len(set(c))
    print(max(1,p), p+len(_c))

        
if __name__ == "__main__":
    main()
def f(x):
    if x == 1:
        return 1
    else:
        return 2 * f(H // 2) + 1   

H = int(input())

min = f(H)

print(min)

### FIXED CODE ###

def f(x):
    if x == 1:
        return 1
    else:
        return 2 * f(x // 2) + 1   

H = int(input())

min = f(H)

print(min)
import collections

from math import factorial
def ncr(n,r):
 if n>2:
  return factorial(n) / factorial(r) / factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = c.values()
  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
solve()
  
  

### FIXED CODE ###

import collections
import sys
sys.setrecursionlimit(100000000)

from math import factorial
def ncr(n,r):
 if n==r:
  return 1
 elif n>2:
  return factorial(n) // factorial(r) // factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = list(c.values())

  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
solve()
n = input()
if 7 in n:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = str(input())
seven = "7"
if seven in n:
    print("Yes")
else:
    print("No")
N,K=map(int,input().split())

H=list(input())

cnt=0

for h in H:
  if h>K:
    cnt+=1
print(cnt)

### FIXED CODE ###

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

H=list(map(int,input().split()))

cnt=0

for h in H:
  if h>=K:
    cnt+=1
print(cnt)