Harryxun/stf_run huggingface dataset:
N,K=map(int,(input().split()))
TO=list(map(int,input().split()))

visit_flag=[[0]*2 for i in [1]*N]
visit_count=0
first_visit=0
last_visit=0
next_town=1
visit_flag[0][0]=1
visit_flag[0][1]=0

for i in range(K):
    visit_count+=1
    next_town = TO[next_town-1]
    if visit_flag[next_town-1][0]==0:
        visit_flag[next_town-1][0]=1
        visit_flag[next_town-1][1]=visit_count
    else:
        first_visit=visit_flag[next_town-1][1]
        last_visit=visit_count
        break

roop=last_visit-first_visit
span=visit_flag[next_town-1][1]

if K<=roop:
    next_town = 1
    for i in range(K):     
        next_town = TO[next_town-1]
    ans=next_town
else:
#    if roop==0:
#        ans=next_town
    else:
        for i in range((K-span)%roop):
            next_town = TO[next_town-1]
            ans=next_town

print(ans)

### FIXED CODE ###

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

visit_flag=[[0]*2 for i in [1]*N]
visit_count=0
first_visit=0
last_visit=0
next_town=1
visit_flag[0][0]=1
visit_flag[0][1]=0

for i in range(K):
    visit_count+=1
    next_town = TO[next_town-1]
    if visit_flag[next_town-1][0]==0:
        visit_flag[next_town-1][0]=1
        visit_flag[next_town-1][1]=visit_count
    else:
        first_visit=visit_flag[next_town-1][1]
        last_visit=visit_count
        break

roop=last_visit-first_visit
span=visit_flag[next_town-1][1]

if K<=roop:
    next_town = 1
    for i in range(K):     
        next_town = TO[next_town-1]
    ans=next_town
else:
    if roop==0:
        ans=next_town
    else:
        for i in range((K-span)%roop):
            next_town = TO[next_town-1]
        ans=next_town

print(ans)
def main():
    b, w = map(int, input().split())
    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, 10**5):
        fact.append(fact[-1]*i % mod)

    half = pow(2, mod-2, mod)

    def nCr(n, r, mod=10**9+7):
        return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod

    h = 1

    A, B, C = 0, 1, 0
    for i in range(1, b+w+1):
        h = h*half % mod
        ans = B
        A = A*2 % mod
        B = B*2 % mod
        C = C*2 % mod
        if i-1 >= b:
            p = nCr(i-1, b)
            ans = (ans-p) % mod
            C = (C+p) % mod
            B = (B-p) % mod
        if i-w-1 >= 0:
            p = nCr(i-1, i-w-1)
            A = (A+p) % mod
            B = (B-p) % mod
        ans = (ans+A) % mod
        print(ans*h % mod)


main()

### FIXED CODE ###

def main():
    b, w = map(int, input().split())
    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, 2*(10**5)+5):
        fact.append(fact[-1]*i % mod)

    half = pow(2, mod-2, mod)

    def nCr(n, r, mod=10**9+7):
        return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod

    h = 1

    A, B, C = 0, 1, 0
    for i in range(1, b+w+1):
        h = h*half % mod
        ans = B
        A = A*2 % mod
        B = B*2 % mod
        C = C*2 % mod
        if i-1 >= b:
            p = nCr(i-1, b)
            ans = (ans-p) % mod
            C = (C+p) % mod
            B = (B-p) % mod
        if i-w-1 >= 0:
            p = nCr(i-1, i-w-1)
            A = (A+p) % mod
            B = (B-p) % mod
        ans = (ans+A) % mod
        print(ans*h % mod)


main()
# coding: utf-8
# Your code here!

#aを破壊的にgcd-zetaする
def zeta_gcd(a):
    n = len(a)-1
    seive = [True]*(n+1)
    for p in range(1,n):
        if seive[p]:
            for i in range(n//p,0,-1):
                a[i] += a[p*i]
                a[i] %= MOD
#    return a

#aを破壊的にgcd-mobiusする
def mobius_gcd(a):
    n = len(a)
    seive = [True]*(n+1)
    for p in range(1,n):
        if seive[p]:
            for i in range(1,n):
                if i*p >= n: break
                a[i] -= a[p*i] 
                a[i] %= MOD
#    return a

################################################

#################################################

SIZE=1000001; MOD=998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
inv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD

################################################
#################################################
import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]

num = [0]*SIZE
for i in a: num[i] += i

assert n != 3

zeta_gcd(num)
ans = [i*i for i in num]
mobius_gcd(ans)

res = 0
for i,c in enumerate(ans):
    res = (res + c*inv[i])%MOD
for i in a:
    res = (res-i)%MOD
        
print(res*inv[2]%MOD)









### FIXED CODE ###

# coding: utf-8
# Your code here!
SIZE=1000001; MOD=998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
inv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD


import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]

num = [0]*1000001
db = [0]*1000001
for i in a:
    num[i] += i
    db[i] += i*i
    db[i] %= MOD

def zeta(a,n):
    sieve = [True]*(n+1)
    for p in range(2,n):
        if sieve[p]:
            for k in range(n//p,0,-1):
                sieve[k*p] = False
                a[k] += a[k*p]
                a[k] %= MOD
    return a


def meb(a,n):
    sieve = [True]*(n+1)
    for p in range(2,n):
        if sieve[p]:
            for k in range(1,n):
                if k*p >= n: break
                sieve[k*p] = False
                a[k] -= a[k*p] 
                a[k] %= MOD
    return a


#n = 1000000

n = 1000000

#zn = [i*i for i in zeta(num,n)]
#zdb = zeta(db,n)
#print(zn[:20])
#print(zdb[:20])

zn = [i*i for i in zeta(num,n)]
zdb = zeta(db,n)
ans = [i-j for i,j in zip(zn, zdb)]

#ans = [i*i-j for i,j in zip(zeta(num,n), zeta(db,n))]

#print(ans[:20])
#print(meb(ans,n)[:20])

res = 0
for i,c in enumerate(meb(ans,n+1)):
    res = (res + c*inv[i])%MOD
        
print(res*inv[2]%MOD)
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
A, B = [0]*N, [0]*N

for i in range(N):
	A[i], B[i] = MAP()

max_A = max(A)
dp = [INF]*(H+max_A+1)
dp[0] = 0
for i in range(N):
	for j in range(A[i], H+max_A+1):
		dp[j] = min(dp[j], dp[j-A[i]]+B[i])

print(min(dp[N][H:]))


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import heapq

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = MAP()

dp = [[INF]*(H+max(A)+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(H+max(A)):
        if j < A[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]]+B[i])

print(min(dp[N][H:]))
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  #出力の制限
N = 300000
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

K = int(input())
S = len(input())
ans = 0
for i in range(S, S + K + 1):
    ans += cmb(S + K, i, mod) * pow(25, K + S - i, mod)
    ans %= mod
print(ans)


### FIXED CODE ###

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  #出力の制限
N = 2000005
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

K = int(input())
S = len(input())
ans = 0
for i in range(S, S + K + 1):
    ans += cmb(S + K, i, mod) * pow(25, K + S - i, mod)
    ans %= mod
print(ans)
input()
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(s[::2]) - sum(s[1::2]))

### FIXED CODE ###

input()
lst = sorted(list(map(int, input().split())))[::-1]
print(sum(lst[::2]) - sum(lst[1::2]))
n=int(input())
import numpy as np
a=np.array(input().split(),dtype=int)
np.append(a,[0])
i=0
ans=0
while i<a.size:
  if a[i]==i+1:
    ans+=1
    if a[i+1]==i+2:
      i+=2
      continue
  i+=1
print(ans)

### FIXED CODE ###

n=int(input())
import numpy as np
a=np.array(input().split(),dtype=int)
i=0
ans=0
while i<a.size:
  if a[i]==i+1:
    ans+=1
    if i+1 < a.size and a[i+1]==i+2:
      i+=2
      continue
  i+=1
print(ans)
import sys
sys.setrecursionlimit(10 ** 7)
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in sys.stdin.readline()][:-1]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
print(int(memo_ls[0][0] % (1e9+7)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in input()]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
        memo_ls[_h][_w] %= (1e9+7)
print(int(memo_ls[0][0] % (1e9+7)))
N = int(input())

if N % 2 == 0:
  print(int((N/2)**2))
  
else:
  print(int((N // 2)((N // 2) + 1)))


### FIXED CODE ###

N = int(input())
 
if N % 2 == 0:
  print(int((N/2)**2))
  
else:
  print(int((N // 2)*((N // 2) + 1)))
import itertools
N, M, Q = map(int, input().split())
for i in range(Q):
    q_list.append(list(map(int, input().split())))

q_list = []
final_score = 0
for A in itertools.combinations_with_replacement(range(1,11), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)

### FIXED CODE ###

import itertools
N, M, Q = map(int, input().split())
q_list = []
final_score = 0
for i in range(Q):
    q_list.append(list(map(int, input().split())))
for A in itertools.combinations_with_replacement(range(1,M+1), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)
def solve():
    file_input = stdin
    
    N = int(file_input.readline())
    img = tuple(tuple(map(int, line.split())) for line in file_input)
    
    acc_row = (tuple(accumulate(line)) + (0,) for line in img)
    acc_col = tuple(tuple(accumulate(line)) + (0,) for line in zip(*img))
    
    ans = 0
    for i, tpl_1 in enumerate(zip(img, acc_row)):
        img_i, acc_row_i = tpl_1
        for j, img_j in enumerate(img[i:], start=i):
            if acc_row_i[j] - acc_row_i[i - 1] > ans:
                ans = acc_row_i[j] - acc_row_i[i - 1]
                
            if i == j:
                continue
            
            col = acc_col[0]
            col_max = col[j] - col[i - 1]
            
            for acc_col_k, img_i_k, img_j_k in zip(acc_col[1:], img_i[1:], img_j[1:]):
                col = acc_col_k[j] - acc_col_k[i - 1]
                
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + img_i_k + img_j_k
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()


### FIXED CODE ###

from sys import stdin
from itertools import accumulate

def solve():
    file_input = stdin
    
    N = int(file_input.readline())
    G = tuple(tuple(map(int, line.split())) for line in file_input)
    G1 = tuple(t[1:] for t in G)
    
    # accumulated rows
    ar = ((0,) + tuple(accumulate(line)) for line in G)
    
    # accumulated columns
    ac = ((0,) + tuple(accumulate(line)) for line in zip(*G))
    ac_1 = next(ac)
    ac = tuple(zip(*ac))
    
    ans = 0
    for i, t1 in enumerate(zip(G1, ar, ac, ac_1)):
        G_i, ar_i, ac_i, ac_1i = t1
        ar_ii = ar_i[i]
        for j, t2 in enumerate(zip(G1[i:], ar_i[i+1:], ac[i+1:], ac_1[i+1:]), start=i):
            G_j, ar_ij, ac_j, ac_1j = t2
            single_row = ar_ij - ar_ii
            if single_row > ans:
                ans = single_row
                
            if i == j:
                continue
            
            col_max = ac_1j - ac_1i
            
            for ac_jk, ac_ik, G_ik, G_jk in zip(ac_j, ac_i, G_i, G_j):
                col = ac_jk - ac_ik
                
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + G_ik + G_jk
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()
n = int(input())
x = list(map(int,input().split()))

x_sorted = sorted(x)

for i in range(n):
    l = x_sorted.copy()
    l.remove(x[i])
    print(l[int(n/2)-1])



### FIXED CODE ###

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

x_sorted = sorted(x)

med = (x_sorted[int(n/2)-1] + x_sorted[int(n/2)])/2

for i in range(n):
    if x[i]<med:
        print(x_sorted[int(n/2)])
    else:
        print(x_sorted[int(n/2)-1])
A, B = map(float, input().split())

print(int((A*(B*100)/100))

### FIXED CODE ###

A, B = input().split()
A = int(A)
x,y = B.split('.')
B = 100*int(x)+int(y)

print(A*B//100)
N, K = map(int, input().split())
H = map(int, input().split())

H.sorted(reverse=True)
ans=0

if K >= N:
    print(ans)
else:
    for i in range(K):
        ans += 1


### FIXED CODE ###

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

H.sort(reverse=True)

if K >= N:
    print(0)
else:
    print(sum(H[K:]))
alpha = 'abcdefghijklmnopqrstuvwxyz'
m = {k:0 for k in alpha}

while True:
    line = input()
    if not line:
        break;
    for s in line:
        s = s.lower()
        if s in m:
            m[s] += 1

for s in alpha:
    print('%s : %d' % (s, m[s]))

### FIXED CODE ###

import sys

alpha = 'abcdefghijklmnopqrstuvwxyz'
m = {k:0 for k in alpha}
q = ''
for line in sys.stdin:
    q += line

for s in q:
    s = s.lower()
    if s in m:
        m[s] += 1
    
for s in alpha:
    print('%s : %d' % (s, m[s]))
from collections import defaultdict
N = int(input())
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
d = defaultdict(int)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = X[i] - X[j]
        q = Y[i] - Y[j]
        d[(p, q)] += 1
print(N - max(d.values()))

### FIXED CODE ###

from collections import defaultdict
N = int(input())
if N == 1:
    print(1)
    exit()
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
d = defaultdict(int)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = X[i] - X[j]
        q = Y[i] - Y[j]
        d[(p, q)] += 1
print(N - max(d.values()))
import sys

sys.setrecursionlimit(10 ** 7)

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

N = int(input())
X = list(input())

pc = X.count("1")

# X == 0 の時
if pc == 0:
    for i in range(N):
        print(1)
    exit()

sml = pc - 1
big = pc + 1

b = 0
mod_s = 0
mod_b = 0
for x in X[::-1]:
    if x == "1":
        mod_s += pow(2, b, sml)
        mod_s %= sml

        mod_b += pow(2, b, big)
        mod_b %= big

    b += 1

# print(mod_s, mod_b, sml, big)


ELE = []

b = 0
for x in X[::-1]:
    if x == "0":
        t = (mod_b + pow(2, b, big)) % big
        ELE.append((t, 1))
    else:
        t = (mod_s - pow(2, b, sml)) % sml
        if t < 0:
            t += sml
        ELE.append((t, 1))
    b += 1


def solve(x, c):
    if x == 0:
        return c

    b = 0
    nx = x
    while nx > 0:
        b += nx & 1
        nx >>= 1

    ret = solve(x % b, c + 1)
    return ret


ANS = []
for x, pc in ELE:
    ANS.append(solve(x, pc))

print("\n".join(map(str, ANS[::-1])))



### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)

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

N = int(input())
X = list(input())

pc = X.count("1")

# X == 0 の時
if pc == 0:
    for i in range(N):
        print(1)
    exit()

sml = pc - 1
big = pc + 1

b = 0
mod_s = 0
mod_b = 0
for x in X[::-1]:
    if x == "1":
        if sml:
            mod_s += pow(2, b, sml)
            mod_s %= sml

        mod_b += pow(2, b, big)
        mod_b %= big

    b += 1

# print(mod_s, mod_b, sml, big)


ELE = []

b = 0
for x in X[::-1]:
    if x == "0":
        t = (mod_b + pow(2, b, big)) % big
        ELE.append((t, 1))
    else:
        t = (mod_s - pow(2, b, sml)) % sml if sml else 0

        if sml:
            ELE.append((t, 1))
        else:
            ELE.append((0, 0))
    b += 1


def solve(x, c):
    if x == 0:
        return c

    b = 0
    nx = x
    while nx > 0:
        b += nx & 1
        nx >>= 1

    ret = solve(x % b, c + 1)
    return ret


ANS = []
for x, pc in ELE:
    ANS.append(solve(x, pc))

print("\n".join(map(str, ANS[::-1])))
a, b, c, d, e, f = map(int, input().split())
a_list = set([])
b_list = set([])
for i in range((f // a) + 1):
    for j in range((f // b) + 1):
        if 0 < ((a*i) + (b*j)) * 100 <= f:
            a_list.add(((a*i)+(b*j))*100)
for i in range((f // c) + 1):
    for j in range((f // d) + 1):
        if ((c*i) + (d*j)) <= f:
            b_list.add((c*i)+(d*j))
ans = 0
ans_1 = 0
ans_2 = 0
for aa in a_list:
    for bb in b_list:
        if (aa + bb <= f) & ((bb / (aa + bb) * 100 <= e):
            if ans <= (bb / (aa + bb)) * 100:
                ans = (bb / aa) * 100
                ans_1 = aa + bb
                ans_2 = bb
print(str(ans_1) + " " + str(ans_2))

### FIXED CODE ###

a, b, c, d, e, f = map(int, input().split())
a_list = set([])
b_list = set([])
for i in range((f // a) + 1):
    for j in range((f // b) + 1):
        if 0 < ((a*i) + (b*j)) * 100 <= f:
            a_list.add(((a*i)+(b*j))*100)
for i in range((f // c) + 1):
    for j in range((f // d) + 1):
        if ((c*i) + (d*j)) <= f:
            b_list.add((c*i)+(d*j))
ans = 0
ans_1 = 0
ans_2 = 0
for aa in a_list:
    for bb in b_list:
        if (aa + bb <= f) & ((bb / aa) <= e * 0.01):
            if ans <= (bb / aa) * 100:
                ans = (bb / (aa)) * 100
                ans_1 = aa + bb
                ans_2 = bb
print(str(ans_1) + " " + str(ans_2))
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
num = [(i, num[i]) for i in range(10) if i in A]
num.sort(key=lambda x: x[0], reverse=True)
num.sort(key=lambda x: x[1])
dp = ["" for i in range(N+1)]
ans = 0
tmp = set()
for x in num:
    if x > N:
        continue
    for i in range(1, N+1-x[1]):
        for n, k in num:
            if i - k in tmp:
                dp[i] = dp[i-k]+str(n)
                tmp.add(i)
                break
            else:
                if i == k:
                    dp[i] = str(n)
                    tmp.add(k)
                    break
    tmp2 = list(dp[N-x[1]])
    tmp2.append(str(x[0]))
    tmp2.sort(reverse=True)
    ans = max(int("".join(map(str, tmp2))), ans)
print(ans)


### FIXED CODE ###

import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
num = [(i, num[i]) for i in range(10) if i in A]
num.sort(key=lambda x: x[0], reverse=True)
num.sort(key=lambda x: x[1])
dp = [0 for i in range(N+1)]
ans = 0
tmp = set()
tmp.add(0)
for i in range(1, N+1):
    for n, k in num:
        if i - k in tmp:
            dp[i] = 1 + dp[i-k]
            tmp.add(i)
            break


num.sort(reverse=True)
tmp = N
ans = []
for i in reversed(range(1, dp[N])):
    for n, k in num:
        if dp[tmp - k] == i:
            ans.append(n)
            tmp -= k
            break
for n, k in num:
    if k == tmp:
        ans.append(n)
        break

ans.sort(reverse=True)
ans = "".join(map(str, ans))
print(ans)
x  = input()


if x[-1] == "3":
    print("bon")
elif x[-1] = "0" or x[-1] = "1" or x[-1] = "6" or x[-1] = "8":
    print("pon")
else:
    print("hon")   

### FIXED CODE ###

x  = input()


if x[-1] == "3":
    print("bon")
elif x[-1] == "0" or x[-1] =="1" or x[-1] == "6" or x[-1] == "8":
    print("pon")
else:
    print("hon")
str = input()
times = int(input())
revers = 0
head = ""
tail = ""
for i in range(times):
    com = input().split()
    if com[0] == "1":
        if revers == 0:
            revers = 1:
        else :
            revers = 0
        
    else :
        if com[1] == "1":
            if revers == 0:
                head = com[2]+head
            else :
                tail = tail + com[2]
        else : 
            if revers == 1:
                head = com[2]+head
            else :
                tail = tail + com[2]          
str = head + str + tail
if revers == 1:
    str = str[::-1]
                
print(str)

### FIXED CODE ###

str = input()
times = int(input())
revers = 0
head = ""
tail = ""
for i in range(times):
    com = input().split()
    if com[0] == "1":
        if revers == 0:
            revers = 1
        else :
            revers = 0
        
    else :
        if com[1] == "1":
            if revers == 0:
                head = com[2]+head
            else :
                tail = tail + com[2]
        else : 
            if revers == 1:
                head = com[2]+head
            else :
                tail = tail + com[2]          
str = head + str + tail
if revers == 1:
    str = str[::-1]
                
print(str)
n = int(input())

if 104 >= n:
    print(0)
else:
    ans = 0
    for i in range(105,n+1):
        cnt=0
        for j in range(1,i+1):
            if i%j == 0:
                cnt+=1
            
        if cnt == 8:
            ans+=1

print(ans)

### FIXED CODE ###

n = int(input())

ans = 0
for i in range(1,n+1):
    if i%2 == 0:
        continue
    cnt=0
    for j in range(1,i+1):
        if i%j == 0:
            cnt+=1
        
    if cnt == 8:
        ans+=1

print(ans)