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

#4
n,k=map(int,input().split())
s=str(input())

import numpy as np
line = np.zeros([2*n,],dtype=np.int)
counter1 = 0
counter0 = 0
ind = 0
for i in range(n):
    c = int(s[i])
    if ind%2 ==0:
        if c == 1:
            counter1 += 1
        else:
            counter0 += 1
            line[ind] = counter1
            counter1 = 0
            ind+=1
    elif ind%2 ==1:
        if c == 0:
            counter0 += 1
        else:
            counter1 += 1
            line[ind] = counter0
            counter0 = 0
            ind+=1

if ind%2 ==0:
        line[ind] = counter1
        ind+=1
elif ind%2 ==1:
        line[ind] = counter0
        ind+=1
        
if ind%2 ==0:
        line[ind] = 0
        ind+=1
line = line[:ind]    
#print(line)

if (len(line)//2)<=k:
    print(n)
else:
    maxchain = 0
    for i in range(0,len(line)-(2*k+1)+1,2):
        chain = sum(line[i:i+2*k+1])
        if chain>maxchain:
            maxchain=chain
    print(maxchain)

### FIXED CODE ###

#4
n,k=map(int,input().split())
s=str(input())

import numpy as np
line = np.zeros([2*n,],dtype=np.int)
counter1 = 0
counter0 = 0
ind = 0
for i in range(n):
    c = int(s[i])
    if ind%2 ==0:
        if c == 1:
            counter1 += 1
        else:
            counter0 += 1
            if ind == 0:
                line[ind] = counter1
            else:
                line[ind] = line[ind-1]+counter1
            counter1 = 0
            ind+=1
    elif ind%2 ==1:
        if c == 0:
            counter0 += 1
        else:
            counter1 += 1
            line[ind] = line[ind-1] + counter0
            counter0 = 0
            ind+=1

if ind%2 ==0:
        if ind == 0:
                line[ind] = counter1
        else:
                line[ind] = line[ind-1]+counter1
        ind+=1
elif ind%2 ==1:
        line[ind] = line[ind-1] + counter0
        ind+=1
        
if ind%2 ==0:
        line[ind] = line[ind-1]
        ind+=1
        
line[1:ind+1]  = line[:ind]   
line[0] = 0 
line = line[:ind+1]
#print(line)

if (len(line)//2)<=k:
    print(n)
else:
    maxchain = 0
    for i in range(0,len(line)-2*k,2):
        chain = line[i+2*k+1]-line[i]
        #print(chain)
        if chain>maxchain:
            maxchain=chain
    print(maxchain)
### BUGGY CODE ###

import heapq

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse = True)

flg = 0
heap = []

for i in range(N):
	heapq.heappush(heap, [- A[i] * F[i], A[i], F[i]])
	
for i in range(K):
	score, tmp_A, tmp_F = heapq.heappop(heap)
	if tmp_A > 0:
		tmp_A -= 1
		heapq.heappush(heap, [- tmp_A * tmp_F, tmp_A, tmp_F])
	else:
		flg = 1
		break
		
if flg:
	print(0)
else:
	ret = heapq.heappop(heap)
	print(-1 * ret[0])	

### FIXED CODE ###

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

A.sort()
F.sort(reverse = True)

ng = -1
ok = 10 ** 12

while ok - ng > 1:
	mid = (ok + ng) // 2
	ctr = 0
	for i in range(N):
		ctr += max(0, A[i] - mid // F[i])
	if ctr <= K:
		ok = mid
	else:
		ng = mid

print(ok)
### BUGGY CODE ###

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = sorted(a,reverse=True)
m = b[0]
if b[0] == b[1] and b[0] == m:
    for i in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            print(max(b[1:]))
        else:
            print(max(a))

### FIXED CODE ###

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
A = max(a)
b = sorted(a,reverse=True)
import collections
c = collections.Counter(a)
if c[A] >= 2:
    for i in range(n):
        print(A)
else:
    for i in range(n):
        if a[i] == A:
            print(b[1])
        else:
            print(A)
### BUGGY CODE ###

n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [1]
c = a[1]
d = 0
length = 0
first = 0
ans = 0

while c not in b:
    b += [c]
    c = a[c]
    d = c
    
if d != 0:
    length = len(b) - b.index(d)
    first = b.index(d)
if k <= first:
    ans = b[k]
elif d == 0:
    ans = 1
else:
    ans = b[(k - first) % length + first]
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
t = [0 for i in range(n+1)]
b = [1]
c = a[1]
d = 0
e=1
length = 0
first = 0
ans = 0


while t[d] < 1:
    t[d]=e
    b += [c]
    c = a[c]
    d = c
    e+=1

if d != 0:
    length = e - t[d]
    first = b.index(d)
if k <= first:
    ans = b[k]
elif d == 0:
    ans = 1
else:
    ans = b[(k - first) % length + first]
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

def resolve():
    N, Q = map(int, input().split())

    AB = [[int(x) for x in input().split()] for _ in range(N - 1)]
    PX = [[int(x) for x in input().split()] for _ in range(Q)]

    graph = [[] for _ in range(N + 1)]
    for a, b in AB:
        graph[a].append(b)
        graph[b].append(a)

    value = [0] * (N + 1)
    for p, x in PX:
        value[p] += x

    def dfs(v, parent):
        for i in graph[v]:
            if i == parent:
                continue
            value[i] += value[v]
            dfs(i, v)

    dfs(1, 0)
    return print(*value[1:])

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split())

AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

value = [0] * (N+1)
for p, x in PX:
  value[p] += x

def dfs(v, parent):  
  for i in graph[v]:
    if i == parent:
      continue
    value[i] += value[v]
    dfs(i, v)

dfs(1, 0)    
ans = ' '.join(map(str, value[1:]))
print(ans)
### BUGGY CODE ###

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

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

for i in range(1, N):
  k = min(i, K)
  for j in range(1, k+1):
    cost = abs(H[i-j] - H[i])
    dp[i] = min(dp[i], dp[i-j]+cost)
    if cost == 0:
      break

print(dp[N-1])

### FIXED CODE ###

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

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

for i in range(1, N):
  k = min(i, K)
  for j in range(1, k+1):
    cost = abs(H[i-j] - H[i])
    dp[i] = min(dp[i], dp[i-j]+cost)
    if cost == 0:
      break

print(dp[N-1])
### BUGGY CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if b == 0:
        return a
    elif a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_m(a, b, *args):
    ret = gcd(a, b)
    for value in args:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    A = deque(string_to_int(inputs[1]))

    if N == 2:
        return max(A)

    max_num = 0
    for _ in range(0, len(A)):
        tmp = A.popleft()
        result = gcd_m(*A)
        if result > max_num:
            max_num = result
        A.append(tmp)
    return max_num


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


### FIXED CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if b == 0:
        return a
    if a == 0:
        return b
    elif a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_m(*args):
    if len(args) == 0:
        return 0
    if len(args) == 1:
        return args[0]
    if len(args) >= 2:
        ret = gcd(args[0], args[1])

    for value in args[2:]:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    # A = [0] + (string_to_int(inputs[1])) + [0]
    A = string_to_int(inputs[1])

    if N == 2:
        return max(A)

    left_gcd_memo = deque([0])
    right_gcd_memo = deque([0])

    for v in A:
        left_gcd_memo.append(gcd(left_gcd_memo[-1], v))
    left_gcd_memo.append(0)
    for v in reversed(A):
        right_gcd_memo.appendleft(gcd(right_gcd_memo[0], v))
    right_gcd_memo.appendleft(0)

    max_gcd = 0
    for i in range(0, len(A)):
        left = left_gcd_memo[i]
        right = right_gcd_memo[i+2]
        g = gcd(left_gcd_memo[i], right_gcd_memo[i+2])
        max_gcd = g if g > max_gcd else max_gcd

    return max_gcd


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 4 * n] * n

if k >= n:
    ans = abs(h[0] - h[n - 1])
else:
    dp[0] = 0
    for i in range(n - 1):
        j = 1
        while i + j < n:
            if j == k + 1:
                break
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
            j += 1
    ans = dp[n - 1]
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 4 * n] * n

if k >= n:
    ans = abs(h[0] - h[n - 1])
else:
    dp[0] = 0
    for i in range(n - 1):
        j = 1
        while i + j < n:
            if j == k + 1:
                break
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
            j += 1
    ans = dp[n - 1]
print(ans)
### BUGGY CODE ###

import sys
 
n=int(input())
a=[input() for i in range(n)]
 
num = 0
sortedA = []
 
end = len(a) - 1
 
for i in range(0, end):
    if i == 0:
        sortedA.append(''.join(sorted(a[0])))
    for j in range(i + 1, end + 1):
        if i == 0:
            sortedA.append(''.join(sorted(a[j])))
        if sortedA[i] == sortedA[j]:
            num = num + 1
print(num)

### FIXED CODE ###

import sys
import collections

n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]

ans = 0
for v in collections.Counter(a).values():
    if v != 1:
        ans += v * (v - 1) // 2
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

count = 0
tmp = - 10 ** 10
for i in range(N):
    # print ('i', i)
    if A[i] == -10 ** 11:
        continue
    if tmp == -10 ** 10:
        tmp = A[i]
        count += 1
        for j in range(i + 1, N):
            if tmp < A[j]:
                tmp = A[j]
                A[j] = - 10  ** 11
            if j == N - 1:
                tmp = - 10 ** 10
# print (A)
print (count)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

dp = [-A[0]]
def solve():
    import bisect
    for i in range(1, N):
        a = bisect.bisect_left(dp, -A[i]+0.1) #入れるべき場所
        # print (a)
        if a == len(dp):
            dp.append(-A[i])
        else:
            dp[a] = -A[i]
        # print (dp)
    return len(dp)


print (solve())
### BUGGY CODE ###

#!/usr/bin/env python3
n,k = [int(i) for i in input().split(" ")]
p = [int(i) for i in input().split(" ")]
kita = [0.5*(i+1) for i in range(max(p)+1)]
maxn = 0
for i in range(n-k+1):
    kt = 0
    for j in range(k):
        kt += kita[p[i+j]]
    if kt > maxn:
        maxn = kt
print(maxn)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
maxn = 0
sum = 0
for i in range(n-k+1):
	if i == 0:
		for j in range(k):
			sum += p[j]
		maxn = sum
	else:
		sum -= p[i-1]
		sum += p[i+k-1]
		if maxn < sum:
			maxn = sum
print(0.5*(maxn+k))
### BUGGY CODE ###

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

def solve():
    import sys
    sys.setrecursionlimit(2*10**5)

    N, Q = list(map(int, input().split()))

    tree = [[] for _ in range(N)]  # 木構造
    for _ in range(N-1):
        a, b = list(map(int, input().split()))
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)

    anss = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split()))
        anss[p-1] += x

    def dfs(a, p):
        """
        a:対象番号
        p:親番号
        """
        for b in tree[a]:
            if b == p: continue
            anss[b] += anss[a]
            dfs(b, a)

    dfs(0, -1)

    print(" ".join(map(str, anss)))


if __name__ == "__main__":
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N, Q = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

rin = [[] for _ in range(N)]
for v in a_b:
    rin[v[0]-1].append(v[1]-1)
    rin[v[1]-1].append(v[0]-1)

score = [0 for _ in range(N)]
for ele in p_x:
    score[ele[0]-1] +=ele[1]
#print(score)

def dfs(p, bp=-1):
    for c in rin[p]:
        if c != bp:
            #print(c)
            score[c]+= score[p]
            dfs(c, p)

dfs(0)
print(*score)
### BUGGY CODE ###

import numpy as np

def convert(L):
    dp = np.zeros((L.shape[0],L.shape[1]), dtype='int')
    for i in range(L.shape[0]):
        l=L[i]
        start=0
        end=0
        sum_=0
        for j in range(L.shape[1]):
            if l[j]:
                end += 1
                sum_ += 1
            elif ~l[j]  and sum_ !=0:
                dp[i][start:end] = sum_
                sum_= 0
                start = end + 1
            elif ~l[j] and sum_ ==0:
                start += 1
                end += 1
            #print(i,j,start,end,sum_,l[j])
        if sum_!=0:
            dp[i][start:end+1] = sum_  
    return dp

H,W=map(int,input().split())
L= np.zeros((H,W),dtype='bool')
for i in range(H):
    L[i]=list(map(lambda x: False if x=="#" else True,list(input()) ))

dp1 = convert(L)
dp2 = convert(L.T).T
ans = dp1+dp2-1
print(np.max(ans))

### FIXED CODE ###

import numpy as np

H,W = map(int,input().split())
temp = np.array([list(input()) for _ in range(H)])
# 周りに壁を、0,1化
map = np.zeros((H+2,W+2),dtype=np.int32)
map[1:-1,1:-1][temp == '.'] = 1

# x軸正方向の集計
def F():
  x = map.copy()
  for row in range(1,H+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形
  x = x.cumsum(axis = 1)
  return x

# y軸
def G():
  x = map.T.copy()
  for row in range(1,W+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形
  x = x.cumsum(axis = 1)
  return x.T

answer = np.zeros_like(map)
# x軸
answer += F()
# 逆順
map = map[:,::-1]
answer += F()[:,::-1]
map = map[:,::-1]

# y軸
answer += G()
# 逆順
map = map[::-1,:]
answer += G()[::-1,:]

answer = np.max(answer) - 3
print(answer)
### BUGGY CODE ###

def gcd(a,b):    #求最大公约数
    if b==0:
        return a
    else:
        return gcd(b,a%b)
a=[]
n=int(input())
mod=1000000007
ans=0
sum=0
s=input().split(" ")
for i in range(0, n):
    k=int(s[i])
    if i==0:
        ans=k
    else:
        u=ans
        ans = ((u * k) // gcd(u, k))
#print(ans)
for i in range(0, n):
    sum=(sum+ans//(int(s[i])))%mod
print(sum)


### FIXED CODE ###

n=int(input())
a=[int(j) for j in input().split()]
t=1
mod=10**9+7
from fractions import*
for i in a:
    t*=i//gcd(t,i)
print(sum(t//i for i in a)%mod)
### BUGGY CODE ###

N, M = map(int, input().split())
a_list = [int(input()) for _ in range(M)]

mod = 1000000007

result = []

for i in range(N+1):
    if i in a_list:
        result += [0]
    elif i == 0 or i == 1:
        result += [1]
    else:
        result += [(result[i-1]+result[i-2]) % mod]
        
print(result[-1])

### FIXED CODE ###

N, M = map(int, input().split())
a_list = [int(input()) for _ in range(M)]

mod = 1000000007

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

def fib(n):
    for i in range(2, n + 1):
        DP[i] = DP[i-1] + DP[i-2]
    
    return DP[n]

ans = 1
x = 0

for a in a_list:
    if a == x:
        ans = 0
        break
    
    ans = (ans * fib((a-1)-x)) % mod
    x = a+1
else:
    ans = (ans * fib(N-x)) % mod
    
print(ans)
### BUGGY CODE ###

s = int(input())


def dfs(n):
    if n <= 2:
        return 0
    elif n == 3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)

        return count


ans = dfs(s)
print(ans)


### FIXED CODE ###

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10 ** 9 + 7


@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif n == 3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)
### BUGGY CODE ###

N=int(input())
a=[int(input())-1 for i in range(N)]

i=0
cnt=1
while a[i]!=0:
    if a[i]==1:
        print(cnt)
        exit()
    cnt+=1
    i=a[i]
print(-1)


### FIXED CODE ###

N = int(input())

a =[0]

for i in range(N):
    a.append(int(input()))


f =[0]*(N+1)

i=1
c = 0
while f[i]==0:
    f[i]=1
    i = a[i]
    c +=1
    if i ==2:
        break
if f[i]==1:
    print(-1)
else:
    print(c)
### BUGGY CODE ###

import sys, math

n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
res = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if s[j] == s[i]:
            continue
        for k in range(j+1, n):
            if s[k] == s[i] or s[k] == s[j] or j-i == k-j:
                continue
            res += 1
print(res)

### FIXED CODE ###

import sys, math

n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
res = 0

r = []
g = []
b = []
for i, c in enumerate(s):
    if c == "R":
        r.append(i)
    if c == "G":
        g.append(i)
    if c == "B":
        b.append(i)


res = len(r) * len(b) * len(g)

def bin_find(tar):
    left = 0
    right = len(b)
    while left < right:
        mid = (left+right) // 2
        if b[mid] < tar:
            left = mid+1
        elif b[mid] > tar:
            right = mid
        else:
            return mid
    return -1

for i in r:
    for j in g:
        diff = i - j
        if diff < 0:
            diff = -diff
        if diff % 2 == 0:
            target = diff // 2 + min(i,j)
            if target < n and s[target] == 'B':
                res -= 1
        target = min(i,j) - diff
        if target >= 0 and s[target] == 'B':
            res -= 1
        target = max(i,j) + diff
        if target < n and s[target] == "B":
            res -= 1

print(res)
### BUGGY CODE ###

from collections import defaultdict, deque

def get_color(id1, id2):
    return edge_colors_dict[(min(id1, id2), max(id1, id2))]

def set_color(color, id1, id2):
    node_list[id1-1].adj_color_dict[id2] = color
    node_list[id2-1].adj_color_dict[id1] = color
    edge_colors_dict[(min(id1, id2), max(id1, id2))] = color

class Node:

    def __init__(self, id, adj_id_list, adj_color_dict):
        self.id = id
        self.adj_id_list = adj_id_list
        self.adj_color_dict = adj_color_dict
    
    def get_min_color(self):
        exist_colors = []
        for color in self.adj_color_dict.values():
            if color != -1:
                exist_colors.append(color)
        color = 1
        while True:
            if not(color in exist_colors):
                return color
            else:
                color += 1

N = int(input())
adj_dict = defaultdict(list)
edge_colors_dict = {}
a, b = [], []
for i in range(N-1):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    adj_dict[ai].append(bi)
    adj_dict[bi].append(ai)
    edge_colors_dict[(ai, bi)] = -1

# node_list[id-1]で, idのnodeにアクセス可能.
node_list = []
for id in range(1, N+1):
    adj_id_list = adj_dict[id]
    adj_color_dict = {}
    for adj_id in adj_id_list:
        adj_color_dict[adj_id] = -1
    node = Node(id, adj_id_list, adj_color_dict)
    node_list.append(node)

open_list = deque()
open_list.append(1)
while True:
    if len(open_list) == 0:
        break
    cur_id = open_list.pop()
    cur_node = node_list[cur_id-1]
    for adj_id in cur_node.adj_id_list:
        if get_color(cur_id, adj_id) == -1:
            open_list.append(adj_id)
            new_color = cur_node.get_min_color()
            set_color(new_color, cur_id, adj_id)

print(len(set(edge_colors_dict.values())))
for (ai, bi) in zip(a, b):
    print(edge_colors_dict[(ai, bi)])

### FIXED CODE ###

from collections import defaultdict, deque

N = int(input())
E = [[] for _ in range(N+1)]
edge_order = []
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
    edge_order.append(b)


# node: (id, parent_id)
root_node = (1, -1)
open_list = deque([root_node])
ans = {}
colors = [-1]*(N+1)
while open_list:
    cur_node = open_list.popleft()
    cur_id, parent_id = cur_node
    adj_id_list = E[cur_id]
    c = 1
    for child_id in adj_id_list:
        if child_id == parent_id:
            continue
        if c == colors[cur_id]:
            c += 1
        colors[child_id] = c
        c += 1
        open_list.append((child_id, cur_id))

print(max(colors))
for i in edge_order:
    print(colors[i])
### BUGGY CODE ###

from copy import deepcopy
import itertools


def read():
    return int(input())


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


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


S = input()
K = read()

substring = set()
for k in range(1, max(K, len(S))+1):
    for i in range(len(S)-k+1):
        substring.add(S[i:i+k])

sub = sorted(list(substring))
print(sub[K-1])


### FIXED CODE ###

from copy import deepcopy
import itertools


def read():
    return int(input())


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


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


S = input()
K = read()

substring = set()
for k in range(1, min(K, len(S))+1):
    for i in range(len(S)-k+1):
        substring.add(S[i:i+k])

sub = sorted(list(substring))
print(sub[K-1])