Problem:
 Score : 300 points    Problem Statement You are given a string s .
Among the different substrings of s , print the K -th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s .
For example, if s  =  ababc , a , bab and ababc are substrings of s , while ac , z and an empty string are not.
Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j} .      Constraints  1  ≤  |s|  ≤  5000  s consists of lowercase English letters.  1  ≤  K  ≤  5  s has at least K different substrings.       Partial Score  200 points will be awarded as a partial score for passing the test set satisfying |s|  ≤  50 .         Input Input is given from Standard Input in the following format:  s  K       Output Print the K -th lexicographically smallest substring of K .        Sample Input 1 aba
4      Sample Output 1 b  s has five substrings: a , b , ab , ba and aba .
Among them, we should print the fourth smallest one, b .
Note that we do not count a twice.       Sample Input 2 atcoderandatcodeer
5      Sample Output 2 andat       Sample Input 3 z
1      Sample Output 3 z

Solution (Python):
s=input()
k=int(input())
n=len(s)
koho=[]
for i in range(n):
    for j in range(k):
        if len(s[i:i+j+1])<=k:
            koho.append(s[i:i+j+1])

print(sorted(list(set(koho)))[k-1])

Solution (Python):
s=input()
K=int(input())
l=len(s)
d=[[s[i],l-i] for i in range(len(s))]
d=sorted(d)
h=dict()
ans=0
ca=d[0][0]   

for i in d:
    if(i[0]!=i[0][0]):
        break
    z=min(i[1]+1,6)
    for j in range(1,z):
        if(s[l-i[1]:l-i[1]+j] not in h):
            ans+=1
            h.update({s[l-i[1]:l-i[1]+j]:1})
        else:
            pass


h=sorted(h)
print(h[K-1])

Solution (Python):
def solve(s, k):
    buff = []
    for start in range(len(s)):
        for end in range(1, k+1):
            if start + end > len(s):
                continue
            buff.append(s[start:start+end])
    buff = list(set(buff))
    buff.sort()
    return buff[k-1]

def main():
    s = input()
    k = int(input())
    ans = solve(s, k)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
s=input()
k=int(input())
p=[chr(ord("a")+i)for i in range(26)]
l=[]
for i in range(26):
    if p[i] in s:
        h=[j for j,x in enumerate(s) if x==p[i]]
        for t in range(len(h)):
            for d in range(5):
                if h[t]+d>len(s)-1:
                    break
                else:
                    l.append(s[h[t]:h[t]+d+1])
        else:
            l=list(set(l))
            if len(l)>=k:
                l.sort()
                print(l[k-1])
                break

Solution (Python):
import string


def solve(s, K):
    candidate = set()
    for char in string.ascii_lowercase:
        for i, c in enumerate(s):
            if c == char:
                for j in range(i + 1, min(len(s), i + 5) + 1):
                    candidate.add(s[i:j])
        if len(candidate) >= K:
            break
    return sorted(list(candidate))[K - 1]

if __name__ == "__main__":
    s = input()
    K = int(input())
    print(solve(s, K))

Solution (Python):
s = input()
K = int(input())
c = []
for i in range(len(s)):
    for j in range(1, min(K, len(s)-i)+1):
        c.append(s[i:i+j])
c = list(set(c))
c.sort()
print(c[K-1])

Solution (Python):
import sys
s = raw_input()
K = input()
suffix_array = [s[-i:] for i in range(1, len(s) + 1)]
suffix_array.sort()
cand = set()
for s in suffix_array[:K]:
    for i in range(1, len(s) + 1):
        sub = s[:i]
        cand.add(sub)
        if len(cand) == K:
            print sub
            sys.exit()

Solution (Python):
s=list(input())
t=set()
for i in s:
  t.add(i)
for i in range(len(s)-1):
  t.add(s[i]+s[i+1])
for i in range(len(s)-2):
  t.add(s[i]+s[i+1]+s[i+2])
for i in range(len(s)-3):
  t.add(s[i]+s[i+1]+s[i+2]+s[i+3])
for i in range(len(s)-4):
  t.add(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
u=list(t)
u.sort()
print(u[int(input())-1])

Solution (Python):
s = input()
K = int(input())

ans_stack = []

for i in range(len(s)):
    str_length = 1
    while str_length <= K and i+str_length <= len(s):
        if not s[i:i+str_length] in ans_stack:
            ans_stack.append(s[i:i+str_length])
            ans_stack = sorted(ans_stack)[0:K]



        str_length += 1
print(ans_stack[K-1])

Solution (Python):
s = input()
K = int(input())
part_list = []

for i in range(len(s)):
    for j in range(i+1,i+6):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Solution (Python):
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Solution (Python):
def cut_kouho(s, char):
    ret = []
    for i in range(s.count(char)):
        ind = s.find(char)
        ret.append(s[ind:])
        if ind == len(s) -1 :
            break
        s = s[ind+1:]
    
    return ret

s = input()
k = int(input())

if len(s) < 51 and False:
    tmp = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            tmp.append(s[i:j+1])
    a = list(set(tmp))
    a.sort()
    print(a[k-1])
else:
    char = list(set(list(s)))
    char.sort()
    
    nokori = k
    for c in char:
        kouho = cut_kouho(s, c)
        
        kouho = [i[:min(nokori, len(i))] for i in kouho]
        
        
        tmp = []
        for string in kouho:
            for i in range(len(string)):
                tmp.append(string[:i+1])
        a = list(set(tmp))
        a.sort()
        
        if len(a) >= nokori:
            print(a[nokori-1])
            exit()
        else:
            nokori -= len(a)

Solution (Python):
s=input().strip()
K=int(input().strip())
minst='z'
for i in range(len(s)):
    if s[i]<minst:
        minst=s[i]
stset=[]
for i in range(len(s)):
    for j in range(K):
        if i+j<=len(s)-1:
            stset.append(s[i:i+j+1])
stset.sort()
kst=''
ct=0
for i in range(len(stset)):
    if kst!=stset[i]:
        ct+=1
        kst=stset[i]
    if ct==K:
        break
print(kst)

Solution (Python):
s = input()
K = int(input())
se = set()
for i in range(len(s)):
    for j in range(1, min(len(s) - i, 5) + 1):
        se.add(s[i:i+j])
print(sorted(list(se))[K - 1])

Solution (Python):
s = input()
K = int(input())
li = set()
for i in range(len(s)):
    for j in range(1, min(len(s) - i, 5) + 1):
        li.add(s[i:i+j])
print(sorted(list(li))[K - 1])

Solution (Python):
s = input()
K = int(input())

substringset = set()

top5 = sorted(list(set(list(s))))[0:5]

for i in range(0, len(s)):
    c = s[i:i+1]
    if not c in top5:
        continue

    for end in range(i + 1,  i + 6):
        substringset.add(s[i:end])

ret = sorted(list(substringset))[K-1]
print(ret)

Solution (Python):
def main():
    s = input()
    k = int(input())
    substr = []
    for l in range(len(s)):
        for r in range(l+1,len(s)+1):
            if r-l > k:
                break
            substr.append(s[l:r])
    c=sorted(set(substr))

    print(c[k-1])


if __name__ == '__main__':
    main()

Solution (Python):
import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


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


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


def nu():
	return int(input())


def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x


s=input()
k=nu()
n=len(s)
m=k
z=set()
for i in range(n):
	pp=""
	for j in range(i,i+m):
		if(j>=n):
			break
		pp+=s[j]
		z.add(pp)
fin=list(z)
fin.sort()
print(fin[k-1])

Solution (Python):
import heapq

S = input()
K = int(input())

q = []

for i in range(len(S)):
    for j in range(i, min(len(S), i + K) + 1):
        heapq.heappush(q, S[i:j])

last = ''
while K > 0:
    s = heapq.heappop(q)
    if s != last:
        K -= 1
        last = s

print(last)

Solution (Python):
S = input()
K = int(input())
N = len(S)
spyon = set([])
alp = alp2 = alp3 = 'z'
for i in range(N):
    alp = min(alp,S[i])
if N - S.rfind(alp) + 1 < K:
    for i in range(N):
        if S[i] == alp:
            continue
        alp2 = min(alp2,S[i])
if 2*N - S.rfind(alp)- S.rfind(alp2) + 2 < K:
    for i in range(N):
        if S[i] == alp or S[i] == alp2:
            continue
        alp3 = min(alp3,S[i])

for i in range(N):
    if S[i] != alp and S[i] != alp2 and S[i] != alp3:
        continue
    for j in range(6):
        spyon.add(S[i:i+j])
print(sorted(spyon)[K])

Solution (Python):


def solve():
    s = input()
    k = int(input())
    subs = sorted([s[i:] for i in range(len(s))])

    cnt = 0
    checked = set()
    for sub in subs:
        for i in range(len(sub)):
            term = sub[:i+1]
            if term not in checked:
                cnt += 1
                checked.add(term)
                if cnt == k:
                    print(term)
                    return


solve()

Solution (Python):
s = input()
K =int(input())

ll = []

for i in [1,2,3,4,5]:
    for j in range(len(s)-i+1):
        ll.append(s[j:j+i])
ll.sort()

now = ll[0]
K -= 1
counter = 1
while K!= 0:
    if ll[counter] != now:
        K-=1
        now = ll[counter]
        counter += 1
    else:
        counter += 1
print(now)

Solution (Python):
import re
""" 
よく分からないけれど1つWA
--> reはnon-overlapping にマッチする 
"""

s = input()
K = int(input())

substrings = []
min_s = ''
while True:
    if min_s == '':
        temp_min_s = min(list(s))
    else:
        temp_min_s = min(list(re.sub('[%s]' % min_s, '', s)))
    min_s += temp_min_s

    word_len = 1
    while word_len < K+1:
        if re.search('%s[a-z]{%d}' % (temp_min_s, word_len-1), s) == None:
            break
        substrings.extend(list(set(re.findall('(?=(%s[a-z]{%d}))' %\
                (temp_min_s, word_len-1), s))))
        
        word_len += 1

    if len(substrings) >= K:
        print(sorted(substrings)[K-1])
        exit()

Solution (Python):
s = input()
K = int(input())
b = set(s)
for i in range(len(s)):
    for j in range(2, 6):
        b.add(s[i:i + j])
print(sorted(b)[K - 1])

Solution (Python):


def main():
    s = input()
    k = int(input())

    n = len(s)
    substrings = set()
    for i in range(n):
        maxlen = min(5, n - i)
        for l in range(1, maxlen + 1):
            ss = s[i:i + l]
            substrings.add(ss)

    li = list(sorted(list(substrings)))
    print(li[k - 1])

main()

Solution (Python):
s = input()
K = int(input())

sn = len(s)
sub = set()

for subl in range(5+1):
    for i in range(len(s)):
        if i+subl <= sn:
            sub.add(s[i:i+subl])

subsort=sorted(sub)

print(subsort[K])

Solution (Python):
s = str(input())
k = int(input())
sub = []
c = 5
if len(s)  < 5:
  c = len(s)
for i in range(c):
  for j in range(len(s)-i):
    sub.append(s[j:j+i+1])

sub = list(set(sub))
sub.sort()
print(sub[k-1])

Solution (Python):

s = input()
k = int(input())

ss = set()
for i in range(len(s)):
    for j in range(i+1,min(len(s)+1,i+k+1)):
        ss.add(s[i:j])
l = sorted(list(ss))


print(l[k-1])

Solution (Python):
s=input()
l=[]
for i in range(97,123):
    c=chr(i)
    ind=0
    while s.find(c,ind)!=-1:
        ind=s.find(c,ind)
        for j in range(1,6):
            if s[ind:ind+j] not in l:
                l.append(s[ind:ind+j])
        ind+=1
    if len(l)>=5:
        break
l.sort()
print(l[int(input())-1])

Solution (Python):


s = input()
k = int(input())
n = len(s)
res = []

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        if s1 not in res:
            for m in range(len(res)):
                if s1 < res[m]:
                    res.insert(m, s1)
                    break
            res.append(s1)
        res = res[0:k]
print(res[-1])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


s = S()
k = I()
n = len(s)
res = []

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        if s1 not in res:
            for m in range(len(res)):
                if s1 < res[m]:
                    res.insert(m, s1)
                    break
            res.append(s1)
        res = res[0:k]
print(res[-1])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


s = S()
k = I()
n = len(s)
res = []

def push(res,s):
    if s not in res:
        for i in range(len(res)):
            if s<res[i]:
                res.insert(i,s)
                break
        res.append(s)
    return(res[0:k])

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        res = push(res,s1)

print(res[-1])

Solution (Python):
s = input()
k = int(input())
t = set()
for i in range(1, min(len(s),k)+1):
    for j in range(len(s)-i+1):
        t.add(s[j:j+i])
print(sorted(list(t))[k-1])

Solution (Python):
s = input()
k = int(input())
l = len(s)

ss = []
for i in range(1, k + 1):
    for j in range(0, l - i + 1):
        ss.append(s[j:j+i])
print(sorted(list(set(ss)))[k - 1])

Solution (Python):
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)

Solution (Python):
s = input()
k = int(input())
a = set()
for i in range(len(s)):
    for j in range(1, min(5, len(s) - i) + 1):
        a.add(s[i:i+j])
a = sorted(a)
print(a[k - 1])

Solution (Python):
from bisect import *

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

def reads():
  return [int(x) for x in input().split()]

s = input()
K = read()
L = len(s)
sbs = sorted(set(s[i:i+j] for i in range(L) for j in range(1, K+1) if i + j <= L))
print(sbs[K-1])

Solution (Python):
s = input()
k = int(input())

words = set()
for i in range(len(s)):
    for j in range(i,i+k):
        words.add(s[i:j+1])
words = sorted(words)
print(words[k-1])

Solution (Python):
s=input()
k=int(input())

se=set()
for i in range(len(s)):
	for j in range(i,i+5):
		se.add(s[i:j+1])
print(sorted(list(se))[k-1])

Solution (Python):
import heapq
from itertools import islice

def substrings(s):
    heap = [s[i:] for i in range(len(s))]
    heapq.heapify(heap)
    popSet = set()

    while True:
        sub = heapq.heappop(heap)
        for i in range(1, len(sub) + 1):
            subi = sub[:i]
            if subi not in popSet:
                yield subi
                popSet.add(subi)


if __name__ == "__main__":
    s = input()
    k = int(input())
    print(list(islice(substrings(s), k))[k - 1])

Solution (Python):
s = input()
k = int(input())

sub = ["zzzzz" for i in range(k)]


def compare(sub_word):
    for i in range(len(sub)):
        
        if sub_word == sub[i]:
            return
        if sub_word < sub[i]:
            
            for j in reversed(range(i, k - 1)):
                sub[j + 1] = sub[j]
            sub[i] = sub_word
            return


count = 0
for i in range(len(s)):
    for j in range(i, min(i + k, len(s))):
        compare(s[i:j + 1])
print(sub[-1])

Solution (Python):
s = input().strip()
K = int(input())

indices = [0]*5
substrings = [sorted(list(set([s[i:i+l] for i in range(len(s)-l+1)])))[:5]+['zzzzz'] for l in range(1,6)]
for k in range(K):
    s = min(substrings[l][i] for l, i in enumerate(indices))
    
    indices[len(s)-1] += 1
    if k == K-1:
        print(s)

Solution (Python):
s = input().rstrip()
k = int(input())
result = []
for i in range(len(s)):
  for j in range(i+1,i+k+1):
    if j <= len(s) and s[i:j] not in result:
      result.append(s[i:j])
result.sort()
print(result[k-1])

Solution (Python):
from sys import stdin, stdout

s = stdin.readline().strip()
k = int(stdin.readline())
challengers = []

for i in range(len(s)):
    cur = ''
    for j in range(i, min(i + 5, len(s))):
        cur += s[j]
        challengers.append(cur)

challengers.sort()

for i in range(len(challengers)):
    if not i or challengers[i - 1] != challengers[i]:
        k -= 1
    
    if not k:
        stdout.write(challengers[i])
        break

Solution (Python):
s = input()
K = int(input())
print(sorted(set([s[j:j+i] for j in range(len(s)) for i in range(1,K+1)]))[K-1])

Solution (Python):
s = input()
K = int(input())
ls = []

for i in range(1,K+1):
    for j in range(len(s)):
        ls.append(s[j:j+i])
print(sorted(set(ls))[K-1])

Solution (Python):
s = input()
K = int(input()) 

alpha = "abcdefghijklmnopqrstuvwxyz"
substring = ''
L = []
for i in alpha:
    indeces = [key for key, x in enumerate(s) if x == i]
    for j in indeces:
        for k in range(j,j+K):
            substring += s[j:k+1] + ','
    L += substring.split(',')[:-1] 
    if len(set(L)) >= K:
        break
    substring = ""
print(sorted(set(L))[K-1])

Solution (Python):
S = str(input())
K = int(input())
 
sub = set()
for i in range(1,min(K, len(S))+1):
    for j in range(len(S)-i+1):
        sub.add(S[j:j+i])
m=list(sub)
m.sort()
print(m[K-1])

Solution (Python):
s = input()
K = int(input())

substrings = []
for i in range(1,6):
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])

Solution (Python):
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])

Solution (Python):
s = input()
K = int(input())
l = len(s)
dic = {}
for i in range(l):
	if not s[i] in dic:
		dic[s[i]] = []
	for j in range(1,6):
		if i + j > (l):
			break
		else:
			dic[s[i]].append(s[i:i+j])

lst = list(dic.keys())
lst.sort()
for c in lst:
	dic[c] = sorted(set(dic[c]))
	l = len(dic[c])
	if K > l:
		K -= l
	else:
		print(dic[c][K-1])
		exit(0)

Solution (Python):
substrs = set()
string = input()
k = int(input())

for i in range(len(string)):
	for j in range(i, i+5):
		substrs.add(string[i:j+1])

substrs = sorted(list(substrs))
for i,s in enumerate(substrs):
	if i == k-1:
		print(s)
		break

Solution (Python):
s = input()
K = int(input())
L = set([])
for i in range(len(s)):
    for j in range(i+1,min(i+6,len(s)+1)):
        L.add(s[i:j])
print(sorted(L)[K-1])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    k = I()
    l = len(s)
    t = set()
    for i in range(1,k+1):
        for j in range(l-i+1):
            t.add(s[j:j+i])

    return sorted(list(t))[k-1]



print(main())

Solution (Python):
s = input()
k = int(input())


def enumerate_substring(k, s):
    s_list = list(s)
    for i in range(1, k + 1):
        for j in range(len(s)):
            if j + i < len(s):
                s_list.append(s[j:j + i + 1])
    s_list = list(set(s_list))
    s_list.sort()
    return s_list


s_list = enumerate_substring(k, s)
print(s_list[k - 1])

Solution (Python):
import numpy as np

s = input()
K = int(input())
L = len(s)

candidate = []

for l in range(1, K + 1):
    for j in range(0, L - l + 1):
        candidate.append(s[j:j+l])

candidate = list(set(candidate))
print(np.sort(candidate)[K-1])

Solution (Python):
import numpy as np

s = input()
K = int(input())
L = len(s)

candidate = []

for l in range(1, K + 1):
    for j in range(0, L - l + 1):
        candidate.append(s[j:j+l])

candidate = list(set(candidate))
print(np.sort(candidate)[K-1])

Solution (Python):
s = input()
k = int(input())

l = [s[i:min(i+k,len(s))] for i in range(len(s))]

l.sort()

count = k
ll = []
flag = True

for x in l:
    if not flag:
        break
    else:
        for i in range(len(x)):
            tmp = x[:i+1]
            if tmp not in ll:
                count -= 1
                if count == 0:
                    print(x[:i+1])
                    flag = False
                else:
                    ll.append(tmp)
            else:
                pass

Solution (Python):
import numpy as np
import heapq


def ii():
    return int(input())


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


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    s = input()
    K = ii()

    sub = []
    for i in range(len(s)):
        sub.append(s[i:])

    heapq.heapify(sub)
    minsub = heapq.heappop(sub)

    if len(minsub) >= K:
        print(minsub[:K])
        return

    cand = []
    for i in range(1, len(minsub)+1):
        cand.append(minsub[:i])
    K -= len(minsub)
    assert K > 0

    while K > 0:
        minsub_ = heapq.heappop(sub)
        for i in range(1, len(minsub_)+1):
            if not minsub_[:i] in cand:
                cand.append(minsub_[:i])
                K -= 1
                if K == 0:
                    print(minsub_[:i])
                    return

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
K = int(input())
 
 
L = []
 
for i in range(1, K+1):
    for j in range(len(s)-i+1):
        L.append(s[j:j+i])
 
M = sorted(list(set(L)))
 
print(M[K-1])

Solution (Python):
s = input()
K = int(input())
 
 
L = []
 
for i in range(1, K+1):
    for j in range(len(s)-i+1):
        L.append(s[j:j+i])
 
M = sorted(list(set(L)))
 
print(M[K-1])

Solution (Python):
s = input()
K = int(input())


L = []

for i in range(1, K+1):
    for j in range(len(s)-i+1):
        L.append(s[j:j+i])

M = sorted(list(set(L)))

print(M[K-1])

Solution (Python):
s = list(input())
K = int(input())

subs = list()

for k in range(K):
	for i in range(len(s) - k):
		subs.append("".join(s[i : i + k + 1]))

subs = sorted(set(subs))
print(subs[K - 1])

Solution (Python):
s = input()
k = int(input())

t = list()
for i in range(len(s)):
    for j in range(k):
        t.append(s[i:i+j+1])
print(sorted(set(t))[k-1])

Solution (Python):
s = input()
k = int(input())

t = set()
for i in range(len(s)):
    for j in range(k):
        t.add(s[i:i+j+1])
print(sorted(t)[k-1])

Solution (Python):
S = input()
K = int(input())
L = len(S)

arr = [S[:j] for j in range(1, min(K, L)+1)]
for i in range(1, L):
  arr2 = [S[i:i+j] for j in range(1, min(K, L-i)+1)]
  arr = sorted(set(arr + arr2))
  arr = arr[:min(K, len(arr))]

print(arr[K-1])

Solution (Python):
def main():
    s = input()
    k = int(input())
    
    l = []
    for i in range(0, len(s)):
        for j in range(0, min(len(s)-i, k)):
            sub = s[i:i+j+1]

            if sub not in l:
                l.append(sub)

    l.sort()
    
    print(l[k-1])

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
k = int(input())
sub = set([])
L = len(s)
for i in range(L) :
    for j in range(1, k+1) :
        if i + j <= L :
            sub.add(s[i:i+j])

sub = list(sub)
sub.sort()
print(sub[k-1])

Solution (Python):
s=input()
K=int(input())

ans=set()
for i in range(len(s)):
  for j in range(i+1,i+K+1):
    if j<=len(s):
      ans.add(s[i:j])
ans=list(sorted(ans))
print(ans[K-1])

Solution (Python):
s = input()
k = int(input())

list = {}

for i in range(len(s)):
    for j in range(i + 1,i + 6):
        if(s[i:j] not in list):
            list[s[i:j]] = 0

keys = sorted(list.keys())

print(keys[k - 1])

Solution (Python):


s=input()
K=int(input())
l=len(s)

S=set([])

for i in range(l):
    for j in range(i,min(l,i+5)):

        S.add(s[i:j+1])
print(list(sorted(S))[K-1])

Solution (Python):
s = input()
K = int(input())


def brute_force(s, K):
    substring_set = set()

    
    for start in range(len(s)):
        
        for length in range(1, 6):
            substring = s[start:start+length]
            substring_set.add(substring)

    substring_list = sorted(list(substring_set))
    print(substring_list[K - 1])

brute_force(s, K)

Solution (Python):
s = input()
k = int(input())

s1 = []
for i in range(len(s)):
    for j in range(i + 1, i + k + 1):
        s1.append(s[i:j])
s1.sort()
substring = []
i = 0
while len(substring) <= 4:
    try:
        if s1[i] not in substring:
            substring.append(s1[i])
        i = i + 1
    except:
        break
print(substring[k - 1])

Solution (Python):
s = list(input())
k = int(input())
sub = []
sub += s[:]
 
for j in range(2,k+1):
    charGram = [''.join(s[i:i+j]) for i in range(len(s)-1)]
    sub += charGram
sub = list(set(sub))
print(sorted(sub)[k-1])

Solution (Python):
s = input()
K = int(input())
Q = set()
L = len(s)
for i in range(L):
    for j in range(K):
        if i+j+1 <= L:
            Q.add(s[i:i+j+1])
print(sorted(Q)[K-1])

Solution (Python):
import sys
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque








def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)


def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))






def main():

    input_S = input()
    K = I() - 1

    
    

    len_S = len(input_S)
    unique_S = len(set(input_S))
    
    lis = set()
    min_s = 'z'

    if len_S == 1:
        print(input_S)

    else:
        for i in range(5):
            for j in range(len_S):
                if input_S[j] > min_s:
                    continue

                s = input_S[j:j+i+1]
                lis.add(s)

        print(sorted(lis)[K])

   
if __name__ == '__main__':
    main()

Solution (Python):
def suffix_array(s):
    def k(a):
        return s[a:]
    
    x = list(range(len(s)))
    x.sort(key=k)
    return x

def main():
    s = input()
    k = int(input())

    a = suffix_array(s)
    v = set()

    for i in a:
        for j in range(i + 1, len(s) + 1):
            v.add(s[i:j])
            if len(v) == k:
                print(s[i:j])
                return

main()

Solution (Python):
def main():
    string = input().strip()
    k = int(input())
    s = set()
    for char in sorted(set(string)):
        for i in range(len(string)):
            if string[i] == char:
                s.add(string[i])
                s.add(string[i:i+1])
                s.add(string[i:i+2])
                s.add(string[i:i+3])
                s.add(string[i:i+4])
                s.add(string[i:i+5])
        if len(s) >= k:
            print(sorted(s)[k - 1])
            return


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
K = int(input())
sub = set()
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if j - i > 5:
            break
        sub.add(s[i:j])
sub = list(sub)
sub.sort()
print(sub[K-1])

Solution (Python):
s = str(input())
n = int(input())

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        
        if len(cand) == n and tmp > cand[-1]:
            break
        if tmp in cand:
            continue
        cand += [tmp]
        
        cand.sort()
        if len(cand) > n:
            cand.pop()


print(cand.pop())

Solution (Python):
s=input()
k=int(input())

tmp=[s[0]]

for i in range(len(s)):
    for j in range(i,len(s)):
        cur_s=s[i:j+1]
        if cur_s not in tmp:
            if len(tmp)==k:
                if tmp[-1]<cur_s:
                    break
            idx=[ele<cur_s for ele in tmp].count(True)
            if len(tmp)==k:
                tmp=tmp[:idx]+[cur_s]+tmp[idx:-1]
            else:
                tmp=tmp[:idx]+[cur_s]+tmp[idx:]
print(tmp[-1])

Solution (Python):




S = input()
K = int(input())

substrings = []


for n in range(1, K + 1):
    for i in range(0, len(S) + 1 - n):
        substrings.append(S[i:i + n])
substrings.sort()

_ = ""
n = 0
for s in substrings:
    if s == _:
        continue
    n += 1
    if n == K:
        print(s)
        break
    else:
        _ = s

Solution (Python):
s=input()
k=int(input())
s1=list(s)
s2=[s[i:i+2] for i in range(len(s)-1)]
s3=[s[i:i+3] for i in range(len(s)-2)]
s4=[s[i:i+4] for i in range(len(s)-3)]
s5=[s[i:i+5] for i in range(len(s)-4)]
sall=sorted(list(set(s1+s2+s3+s4+s5)))
print(sall[k-1])

Solution (Python):
string = input()
k = int(input())
if len(string) > k:
    substrs = set()
    ls = sorted(list(string))
    for i in range(k):
        for s, c in enumerate(string):
            if c == ls[i]:
                for l in range(1, k+1):
                    substrs.add(string[s:s+l])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])

else:
    substrs = set()
    for leng in range(1, len(string) + 1):
        for s in range(0, len(string) - leng + 1):
            substrs.add(string[s:s+leng])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])

Solution (Python):
s=input()
k=int(input())
ss=set()
l=min(k, len(s))
for i in range(1, l+1):
 for j in range(len(s)-i+1):
  ss.add(s[j:j+i])
print(sorted(list(ss))[k-1])