Harryxun/stf_run huggingface dataset:
from requests import api

n,W = map(int,input().split())
w,v = [],[]
for i in range(n):
    wi,vi = map(int,input().split())
    w.append(wi)
    v.append(vi)
sv = sum(v)
INF = float("INF")
dp = [[INF]*sv for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(sv):
        if j-v[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i])
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
    #print(dp)
ans = 0
for i in range(sv):
    #print(dp[n][i])
    if dp[n][i] <= W:
        ans = max(ans,i)
print(ans)


### FIXED CODE ###

n,W = map(int,input().split())
w,v = [],[]
for i in range(n):
    wi,vi = map(int,input().split())
    w.append(wi)
    v.append(vi)
mv = sum(v)
INF = float("INF")
dp = [[INF]*(mv+100) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for sv in range(mv+100):
        if sv-v[i] >= 0:
            dp[i+1][sv] = min(dp[i+1][sv],dp[i][sv-v[i]]+w[i])
        dp[i+1][sv] = min(dp[i+1][sv],dp[i][sv])
    #print(dp)
ans = 0
for i in range(mv+100):
    #print(dp[n][i])
    if dp[n][i] <= W:
        ans = max(ans,i)
print(ans)
a,b = map(str,input().split())
b100 = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3])
# print(b)
# print(b100)
print(int(int(a)*b/100))


### FIXED CODE ###

a,b = map(str,input().split())
b100 = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3])
# print(b)
# print(b100)
print((int(a)*b100)//100)
for i in range(10000):
 x = int(input())
  if (x == 0):
    break
  print("Case ",i+1, ": ",x)


### FIXED CODE ###

for i in range(10000):
  x = int(input())
  if (x == 0):
    break
  print("Case " + str(i+1) + ": " + str(x))
a=int(input())
s=input()

if a>=3200:
    print(s)
else if a<3200:
    print("red")

### FIXED CODE ###

a=int(input())
s=input()

if a>=3200:
    print(s)
elif a<3200:
    print("red")
k = int(input())

def hantei(n):
    string = str(n)
    length = len(string)
    ret = True
    for i in range(length-1):
        if abs(int(string[i]) - int(string[i+1])) > 1:
            ret = False
            break
    return ret

lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta = 2
while len(lst) < k+1:
    new = []
    for i in range(1, 10):
        tasu = i*(10**(keta-1))
        for j in sorted(dic.keys()):
            temp_lst = dic[j]
            bit = 0
            for youso in temp_lst:
                num = tasu + youso
                if hantei(num):
                    new.append(num)
                    bit = 1
                elif bit == 1:
                    break
    dic[keta] = new.copy()
    lst.extend(new)
    keta += 1

print(lst[k])

### FIXED CODE ###

k = int(input())

def hantei(n):
    string = str(n)
    length = len(string)
    ret = True
    for i in range(length-1):
        if abs(int(string[i]) - int(string[i+1])) > 1:
            ret = False
            break
    return ret

lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta = 2
while len(lst) < k+1:
    new = []
    for i in range(1, 10):
        tasu = i*(10**(keta-1))
        for j in sorted(dic.keys()):
            temp_lst = dic[j]
            bit = 0
            for youso in temp_lst:
                num = tasu + youso
                if hantei(num):
                    new.append(num)
                    bit = 1
                elif bit == 1:
                    break
    dic[keta] = new.copy()
    lst.extend(new)
    keta += 1

print(lst[k])
if h1 <= h2:
    time = h2 * 60 + m2 - h1 * 60 + m1
else:
    time = (h2+24) * 60 + m2 - h1 * 60 + m1
if k >= time:
    print(0)
else:
    print(time - k)

### FIXED CODE ###

h1, m1, h2, m2, k = map(int, input().split())
 
if h1 <= h2:
    time = h2 * 60 + m2 - h1 * 60 - m1
else:
    time = (h2+24) * 60 + m2 - h1 * 60 - m1
if k >= time:
    print(0)
else:
    print(time - k)
letters = eval(input("Enter: "))
for i in letters:
  print("Yes" if (i[2]==i[3] and i[4]==i[5]) "Yes" if letters=="coffee-like" else "No")

### FIXED CODE ###

l = input()
print("Yes" if (l[2]==l[3] and l[4]==l[5]) else "No")
flag=0
while flag==0:
    a,b=[int(i) for i in input().split()]
    if a=0,b=0:
        flag=1
        break
    else:
        for i in range(a):
        print("#"*b)

### FIXED CODE ###


flag=0
while flag==0:
    a,b=[int(i) for i in input().split()]
    if a==0 and b==0:
        flag=1
        break
    else:
        for i in range(a):
            print("#"*b)
    print("")
n = int(input())
s = str(input())
MOD = 10**9 + 7

if s[0] == "W" or s[-1] == "W":
    print(0)
    exit()

kai = [1 for _ in range(n+1)]
for i in range(1, n+1):
    kai[i] = (kai[i-1] * i) % MOD

ans = 1
count = 0
pre = ""
for i in range(2*n):
    if s[i] == pre:
        count += 1
    else:
        count += 1
        ans *= kai[count]
        ans %= MOD
        count = 0
    pre = s[i]
ans *= kai[n]
ans %= MOD
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ss = [1 if s == 'W' else 0 for s in S]

def mul(a, b):
    return (a * b) % (10**9 + 7)

ans = 1
num = 0
for s in ss:
    if num % 2 == s:
        num += 1
    else:
        ans = mul(ans, num)
        num -= 1

if num > 0:
    ans = 0

for i in range(2, N + 1):
    ans = mul(ans, i)

print(ans)
N = int(input().rstrip())
v = input().rstrip().split(" ")
v.sort()
#print(v)
a = (int(v[0])+int(v[1])) / 2
i = 2
while i <= (N-1):
  a = (a + int(v[i])) / 2
  i += 1
print(a)

### FIXED CODE ###

a = input()
a = int(a)
if a >= 3200:
  s = input()
  print(s)
else:
  print('red')
n=int(input())
k=int(input())
N=map(int,input().split())
count=0
for n1 in n:
  if N>k:
    count+=1
  ekse:
    count+=0
pribt(count)


### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
count = 0
for i in h:
    if i >= K:
      count+=1
print(count)
s=list(input())
booler=True
while s!=[] and booler==True:
  if s[-5]=="d" and s[-4]=="r" and s[-3]=="e" and s[-2]=="a" and s[-1]=="m":
    for i in range(5):
      del s[-1]
  elif s[-6]=="e" and s[-5]=="r" and s[-4]=="a" and s[-3]=="s" and s[-2]=="e" and s[-1]=="r":
    for i in range(6):
      del s[-1]
  elif s[-5]=="e" and s[-4]=="r" and s[-3]=="a" and s[-2]=="s" and s[-1]=="e":
    for i in range(5):
      del s[-1]
  elif s[-7]=="d" and s[-6]=="r" and s[-5]=="e" and s[-4]=="a" and s[-3]=="m" and s[-2]=="e" and s[-1]=="r":
    for i in range(7):
      del s[-1]
  else:
    booler=False
if booler:
  print("YES")
else:
  print("NO")
  


### FIXED CODE ###

s=list(input())
booler=True
while s!=[] and booler==True:
  if s[-5]=="d" and s[-4]=="r" and s[-3]=="e" and s[-2]=="a" and s[-1]=="m":
    for i in range(5):
      del s[-1]
  elif s[-5]=="e" and s[-4]=="r" and s[-3]=="a" and s[-2]=="s" and s[-1]=="e":
    for i in range(5):
      del s[-1]
  elif s[-6]=="e" and s[-5]=="r" and s[-4]=="a" and s[-3]=="s" and s[-2]=="e" and s[-1]=="r":
    for i in range(6):
      del s[-1]
  elif s[-7]=="d" and s[-6]=="r" and s[-5]=="e" and s[-4]=="a" and s[-3]=="m" and s[-2]=="e" and s[-1]=="r":
    for i in range(7):
      del s[-1]
  else:
    booler=False
if booler:
  print("YES")
else:
  print("NO")
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
    H, W = map(int, input().split())
    m = []
    for _ in range(H):
        l = input()
        m.append(l)
    edge = []
    v = H * W
    for i in range(H):
        for j in range(W):
            t = i * H + j
            edge.append([10 ** 9] * v)
            if m[i][j] == '.':
                if i > 0 and m[i-1][j] == '.':
                    edge[t][(i-1) * H + j] = 1
                if j > 0 and m[i][j -1] == '.':
                    edge[t][i * H + j - 1] = 1
                if i < H-1 and m[i+1][j] == '.':
                    edge[t][(i + 1)*H + j] = 1
                if j < W - 1 and m[i][j+1] == '.':
                    edge[t][i * H + j + 1] = 1
    G = csgraph_from_dense(edge, null_value=10**9)
    d = floyd_warshall(G)
    m = 0
    for i in range(v):
        for j in range(v):
            if d[i][j] != float('inf') and d[i][j] > m:
                m = d[i][j]
    print(int(m))
main()
    


### FIXED CODE ###

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
    H, W = map(int, input().split())
    m = []
    for _ in range(H):
        l = input()
        m.append(l)
    edge = []
    v = H * W
    for i in range(H):
        for j in range(W):
            t = i * W + j
            edge.append([10 ** 9] * v)
            if m[i][j] == '.':
                if i > 0 and m[i-1][j] == '.':
                    edge[t][(i-1) * W + j] = 1
                if j > 0 and m[i][j -1] == '.':
                    edge[t][i * W + j - 1] = 1
                if i < H-1 and m[i+1][j] == '.':
                    edge[t][(i + 1)*W + j] = 1
                if j < W - 1 and m[i][j+1] == '.':
                    edge[t][i * W + j + 1] = 1
    G = csgraph_from_dense(edge, null_value=10**9)
    d = floyd_warshall(G)
    m = 0
    for i in range(v):
        for j in range(v):
            if d[i][j] != float('inf') and d[i][j] > m:
                m = d[i][j]
    print(int(m))
main()
import sys

def maybe_check(A,n):
    maybe_list = []
    for i in range(1, n+1):
        left = abs(i - n)
        right = (n -1 )- left
        maybe_list.append(abs(left - right))

    pattern =  len(set([x for x in maybe_list if maybe_list.count(x) != 1]))

    for i in A:
        if i in maybe_list:
            maybe_list.remove(i)
        else:
            return 0

    return (2 ** pattern) % div


args = sys.argv
n = int(args[1])
A = map(int,args[2:])
div = 10 ** 9 + 7
print maybe_check(A, n)


### FIXED CODE ###

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

def maybe_check(n,A):
    try:
        if n <= 0 or n > 100000:
            raise

        div = 1000000007
        maybe_list = [abs(abs(i - n) - ((n -1 ) - abs(i - n))) for i in range(1, n+1)]
        maybe_list.sort()
        A.sort()
        if A !=  maybe_list:
            raise

        pattern = len([num for num,count in Counter(maybe_list).items() if count != 1])
        return (2 ** pattern) % div

    except:
        return 0


_n = int(raw_input())
_A = map(int,raw_input().split())

print maybe_check(_n,_A)
c = input()
if c in ['a', 'i', 'u', 'e', 'o']:
	print('vowel')
else
 	print('consonant')


### FIXED CODE ###

c = input()
if c in ['a', 'i', 'u', 'e', 'o']:
	print('vowel')
else:
 	print('consonant')
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split( )))
ans = []

for i in range(n):
    for _ in range(a[i]):
        ans.append(i+1)
for i in range(h):
    for j in range(w):
        if i%2:
            print(ans[h*i+j], end = " ")
        else:
            print(ans[h*i+w-j-1],end = " ")
    print()
        



### FIXED CODE ###

h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split( )))
ans = []

for i in range(n):
    for _ in range(a[i]):
        ans.append(i+1)
for i in range(h):
    if not i%2:
        print(*ans[w*i:w*i+w])
    else:
        print(*ans[w*i+w-1:w*i-1:-1])
from fractions import *
n = int(input())
s = input()

x = 0
ans = 0
for i in range(N):
    if s[i] == 'I':
        x += 1
    else:
        x -= 1
    ans = max(x, ans)

print(ans)

### FIXED CODE ###

from fractions import *
n = int(input())
s = input()

x = 0
ans = 0
for i in range(n):
    if s[i] == 'I':
        x += 1
    else:
        x -= 1
    ans = max(x, ans)

print(ans)
l = list(map(input().split()))
print(l[0]-l[1]+1)

### FIXED CODE ###

l = list(map(int,input().split()))
print(l[0]-l[1]+1)
x = input()
pon = ['0', '1', '6', '8']
if x[-1] if pon:
  print('pon')
elif x[-1] == '3':
  print('bon')
else:
  print('hon')

### FIXED CODE ###

x = input()
pon = ['0', '1', '6', '8']
if x[-1] in pon:
  print('pon')
elif x[-1] == '3':
  print('bon')
else:
  print('hon')
import unittest

from D import run, primes


class TestSample(unittest.TestCase):
    def test_run(self):
        self.assertEqual(run(5), '11 31 41 61 71')
        self.assertEqual(run(6), '11 31 41 61 71 101')
        self.assertEqual(run(7), '11 31 41 61 71 101 131')

    def test_primes(self):
        self.assertEqual(primes(5), [2, 3, 5])
        self.assertEqual(primes(20), [2, 3, 5, 7, 11, 13, 17, 19])


if __name__ == '__main__':
    unittest.main()


### FIXED CODE ###

def run(N):
    p_list = primes(555555)
    # 選択した素数が、5で割って余りが1のもののみ選択すれば、必ず合成数になる
    ret = []
    for p in p_list:
        if p % 5 == 1:
            ret.append(p)
        if len(ret) == N:
            break
    return ' '.join([str(p) for p in ret])


def primes(n):
    '''
    エラトステネスの篩にて、素数のリストを作成
    '''
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]


def main():
    N = int(input())
    print(run(N))


if __name__ == '__main__':
    main()
import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for _ in range(W+1) ] for _ in range(N + 1)] 

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))
~                   

### FIXED CODE ###

import sys 
sys.setrecursionlimit(2147483647)

N,W = map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for _ in range(W+1) ] for _ in range(N + 1)] 

for i in range(1,N + 1): 
    for j in range(W + 1): 
        if j - A[i-1][0] >= 0:
            res1 = dp[i - 1][j - A[i-1][0]] + A[i - 1][1]
            res2 = dp[i - 1][j]
            dp[i][j] = max(res1,res2)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(max(dp[N]))
n=inupt()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

### FIXED CODE ###

from math import sqrt

N = int(input())
for i in range(int(sqrt(N)), 0, -1):
    if N % i == 0:
        j = N // i
        print(i + j - 2)
        break
n = int(input())
a = [input() for _ in range(n)]
sep=''
b = [sep.join(sorted(a[i])) for i in range(n)]
dic = {letters: b.count(letters) for letters in set(b)}

ans=0
for i in dic.values():
  ans+=i*(i-1)//2
print(ans

### FIXED CODE ###

#python3
n = int(input())
s = [str(input()) for _ in range(n)]
sep = ''
dic = dict()
for string in s:
  tmp = sep.join(sorted(string))
  if tmp in dic:
    dic[tmp] += 1 
  else :
    dic[tmp] = 1
ans = 0
for i in dic.values(): 
  ans += i*(i-1)//2
print(ans)
a,b=map(int,input().split())

if abs(a-b)<2:
    print("Brown")
elif:
    print("Alice")

### FIXED CODE ###

a,b=map(int,input().split())
 
if abs(a-b)<2:
    print("Brown")
else:
    print("Alice")
from collections import deque
h, w =map(int, input().split())
s = [input() for i in range(h)]
s_x, s_y = 0, 0
##ある場所を塗る。その上でBFS。最大値を求める。
#最短経路で辿り着く時、塗りつぶす手は最大になる。
#最短経路の時は、通るますが考えうる中で一番少ないからねえ。そりゃそうか。
max = 0
c = [[0] * w for i in range(h)]
#cを定義する時は、横に並べてからそれを縦に並べる。つまり、列数を指定してから、その外で
#行数を指定する。ただ、要素にアクセスするときは、c[行番号][列番号]
#外側ほど、左側の要素になる？
def BFS():
    q = deque()
    q.append((s_x, s_y))

    while len(q) > 0:
        y, x = q.popleft()
        if y == h - 1 and x == w - 1:
            return c[y][x]
        if x < w - 1:
            if s[y][x+1] == '.' and c[y][x+1] == 0:
                q.append((y, x+1))
                c[y][x+1] = c[y][x] + 1
        if x > 0:
            if s[y][x-1] == '.' and c[y][x-1] == 0:
                q.append((y, x-1))
                c[y][x-1] = c[y][x] + 1
        if y < h - 1:
            if s[y+1][x] == '.' and c[y+1][x] == 0:
                q.append((y+1, x))
                c[y+1][x] = c[y][x] + 1
        if y > 0:
            if s[y-1][x] == '.' and c[y-1][x] == 0:
                q.append((y-1, x))
                c[y-1][x] = c[y][x] + 1

area = h*w
blunk_num_origin = 0
for ch1 in s:
    for ch2 in ch1:
        if ch2 == '#':
            blunk_num_origin += 1

min_grid = BFS()
sol = area-blunk_num_origin-2-(min_grid-1)
print(area,min_grid,blunk_num_origin)
print(sol)


### FIXED CODE ###

from collections import deque
h, w =map(int, input().split())
s = [input() for i in range(h)]
s_x, s_y = 0, 0
##ある場所を塗る。その上でBFS。最大値を求める。
#最短経路で辿り着く時、塗りつぶす手は最大になる。
#最短経路の時は、通るますが考えうる中で一番少ないからねえ。そりゃそうか。
max = 0
c = [[0] * w for i in range(h)]
#cを定義する時は、横に並べてからそれを縦に並べる。つまり、列数を指定してから、その外で
#行数を指定する。ただ、要素にアクセスするときは、c[行番号][列番号]
#外側ほど、左側の要素になる？
def BFS():
    q = deque()
    q.append((s_x, s_y))

    while len(q) > 0:
        y, x = q.popleft()
        if y == h - 1 and x == w - 1:
            return c[y][x]
        if x < w - 1:
            if s[y][x+1] == '.' and c[y][x+1] == 0:
                q.append((y, x+1))
                c[y][x+1] = c[y][x] + 1
        if x > 0:
            if s[y][x-1] == '.' and c[y][x-1] == 0:
                q.append((y, x-1))
                c[y][x-1] = c[y][x] + 1
        if y < h - 1:
            if s[y+1][x] == '.' and c[y+1][x] == 0:
                q.append((y+1, x))
                c[y+1][x] = c[y][x] + 1
        if y > 0:
            if s[y-1][x] == '.' and c[y-1][x] == 0:
                q.append((y-1, x))
                c[y-1][x] = c[y][x] + 1

    return(-1)

area = h*w
blunk_num_origin = 0
for ch1 in s:
    for ch2 in ch1:
        if ch2 == '#':
            blunk_num_origin += 1

min_grid = BFS()
if min_grid == -1:
    print(min_grid)
else:
    sol = area-blunk_num_origin-2-(min_grid-1)
    #print(area,min_grid,blunk_num_origin)
    print(sol)
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(input().split())

SET = set()
ans = []
for i in range(1, K+1):
    lis = []
    s = set()
    for j in range(i):
        for a in As:
            if a in s:
                lis = lis[:lis.index(a)]
                s = set(lis)
            else:
                s.add(a)
                lis.append(a)
    string = ' '.join(lis)
    if string in SET:
        break
    SET.add(string)
    ans.append(string)

print(ans[K%(i-1)-1])

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
double_As = As*2
idx_dic = {}
idx_lis = [N+1]*(2*N)
for i in range(N*2-1, -1, -1):
    a = double_As[i]
    if a in idx_dic:
        idx_lis[i] = idx_dic[a]+1
    idx_dic[a] = i
doubling = [[0]*N for _ in range(60)]
accum = [[0]*N for _ in range(60)]
doubling[0] = [i%N for i in idx_lis[:N]]
accum[0] = [a-i for i, a in enumerate(idx_lis[:N])]
for i in range(1, 60):
    for j in range(N):
        doubling[i][j] = doubling[i-1][doubling[i-1][j]]
        accum[i][j] = accum[i-1][j] + accum[i-1][doubling[i-1][j]]
now = 0
cum = 0
cnt = 0
for i in range(59, -1, -1):
    if cum + accum[i][now]>N*K:
        continue
    else:
        cum += accum[i][now]
        now = doubling[i][now]
ans = []
while cum<N*K:
    if cum+accum[0][now]<=N*K:
        cum += accum[0][now]
        now = doubling[0][now]
    else:
        ans.append(As[now])
        now += 1
        cum += 1
print(*ans)
def count(x):
    if len(child_list[x]) > 0:
        for index in child_list[x]:
            total_list[index] += total_list[x]
            count(index)

n, q = map(int, input().split())
child_list = [[] for _ in range(n)]
position_list = [10 * 6] * n
position_list[0] = 1
input_list = []
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a < b:
        a, b = b, a
    input_list.append([b, a])
input_list.sort()
for a, b in input_list:
    if position_list[a] < position_list[b]:
        a, b = b, a
    position_list[a] = position_list[b] + 1
    child_list[b].append(a)
total_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    total_list[p - 1] += x

count(0)
print(*total_list)

### FIXED CODE ###

n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)
def sub_k(string, I, K):
    temp = []
    for i in range(len(string)):
        if i-1+I == len(string):
            continue
        temp.append(string[i:i+I])
    return sorted(set(temp))[0:K]

def main(string, K):
    result = []
    for i in range(K):
        result += sub_k(string, i+1, K-i)
    print(sorted(set(result))[K-1])

string = input()
K = int(input())
main(string, K)

### FIXED CODE ###

def sub_k(string, I, K):
    temp = []
    for i in range(len(string)):
        if i-1+I == len(string):
            break
        temp.append(string[i:i+I])
    return sorted(set(temp))[0:K]

def main(string, K):
    result = []
    for i in range(K):
        result += sub_k(string, i+1, K-i)
    print(sorted(set(result))[K-1])

string = input()
K = int(input())
main(string, K)
m = [1,2,3]
a = int(input())
b = int(input())

m.pop(a-1)
m.pop(b-1)
print(m[0])

### FIXED CODE ###

m = [1,2,3]
a = int(input())
b = int(input())

m.pop(m.index(a))
m.pop(m.index(b))
print(m[0])
import numpy as np
sys.setrecursionlimit(10**4+1)
H,N = map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

memo = [10**4+1 for i in range(H+1)]

def memorize(H,memo,A,B,N):
    if H<= 0:
        return 0
    else:
        if memo[H]!=10**4+1:
            return memo[H]
        cost_min = 10**4+1
        for i in range(N):
            cost = B[i] + memorize(H-A[i],memo,A,B,N)
            cost_min = min(cost_min,cost)
        memo[H] = cost_min
        return cost_min
        
print(memorize(H,memo,A,B,N))

### FIXED CODE ###

import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])
A,B=map(int,input().split())
A*=100
B+=100
for i in range(2000):
  t*=100
  if A==t*8//100 and B==t//10:
    print(i)
    exit()
print(-1)

### FIXED CODE ###

A, B = map(int, input().split())
for i in range(20000):
    if int(i*0.08) == A and int(i * 0.1) == B:
        print(i)
        exit()
print(-1)
K,S=map(int,input().split())
b=sum(0<=S-x-y<=K  for x in range(K+1)for y in range(K+1))
print(sum

### FIXED CODE ###

K,S=map(int,input().split())
b=sum(0<=S-x-y<=K  for x in range(K+1)for y in range(K+1))
print(b)
s=int(input())
w=int(input())
if(s<=w):
  print("unsafe")
else:
  print("safe")

### FIXED CODE ###

s,w=(int(x) for x in input().split())
if(s<=w):
  print("unsafe")
else:
  print("safe")