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):
def m():
    s = input()
    k = int(input())
    a = set()
    for i in range(len(s)):
        for j in range(5):
            a.add(s[i:i+j+1])
    b = list(a)
    b.sort()
    return b[k-1]

print(m())

Solution (Python):
s = input()
K = int(input())
S = set()
for i in range(1, K+1):
    S |= set([s[n:n+i] for n in range(0, max(len(s)-i+1, 0))])
print(sorted(list(S))[K-1])

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

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

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

Solution (Python):

"""
Created on Fri Jul  6 22:20:31 2018
ABC097A
@author: maezawa
"""

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

perm = []

n = len(s)
for i in range(1, 6):
    for j in range(n-i+1):
        perm.append(s[j:j+i])
    
ans_array = sorted(set(perm))

print(ans_array[k-1])

Solution (Python):
s = input()
K = int(input())
str_len = len(s)
substrings = []

def get_substrings(substr_len):
    if substr_len == K + 1:
        return
    else:
        for i in range(0, str_len + 1 - substr_len):
            sub_s = s[i:i+substr_len]
            if not(sub_s in substrings):
                substrings.append(sub_s)
        get_substrings(substr_len + 1)

get_substrings(1)
substrings.sort()

print(substrings[K - 1])

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

l = len(s)
substr = []

for i in range(l):
    for k in range(K):
        substr.append(s[i:i+k+1])
        if i+k+1 >= l: break

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

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

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

substr = []

for i in range(n):
    for j in range(i, i+K):
        substr.append(s[i:j+1])

substr = sorted(list(set(substr)))
print(substr[K-1])

Solution (Python):
if __name__ == '__main__':
    s = input()
    K = int(input())

    subs = []
    for i in range(len(s)):
      for j in range(K):
            try:
                subs.append(s[i:i+j+1])
            except:
                break
    subs = set(subs)
    print(sorted(list(subs))[K-1])

Solution (Python):

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

    ss = []
    for i in range(0, len(s)):
        for j in range(i, i + k + 1):
            if i == j:
                continue
            if len(ss) == 6:
                if ss[-1] > s[i:j]:
                    ss[-1] = s[i:j]
                    ss = list(set(ss))
                    ss.sort()
            else:
                ss.append(s[i:j])
                ss = list(set(ss))
                ss.sort()

    print(ss[k-1])

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
K = int(input())
s_list = []
for i in range(len(S)):
	for j in range(i + 1, i + K + 1):
		s_list.append(S[i:j])
sub_set = set(s_list)
substring = list(sub_set)
substring.sort()
print(substring[K-1])

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

sss = set()
M = len(s)
for end in range(1, K+1):
    for i in range(M):
        sss.add(s[i:(i+end)])

ans = sorted(sss)
print(ans[K-1])

Solution (Python):


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

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

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

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

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

Solution (Python):
from collections import defaultdict
s=input()
K=int(input())


def calc(s, K):
    a = defaultdict(list)
    for i, c in enumerate(s):
        a[c].append(i)
    result = set()
    for i in range(ord('a'), ord('z')+1):
        for j in a[chr(i)]:
            for l in range(min(K, len(s[j:]))):
                result.add(s[j:j+l+1])
        if len(result) >= K:
            return sorted(list(result))[K-1]

print(calc(s, K))

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

list = []
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    tmp = s[i:j]
    if len(list)>=K:
      if tmp>list[-1]:
        break
      else:
        if not tmp in list:
          list.append(tmp)
          list.sort()
          list = list[:K]
    else:
      if not tmp in list:
        list.append(tmp)
        list.sort()
        if len(list)>K:
          list = list[:K]

print(list[K-1])

Solution (Python):
s = input()
k = int(input())
l = []
for i in range(len(s)):
    l.append(s[i:])
    l.sort()
    if len(l) > 5:
        l.pop()

p = set()
for i in l:
    for j in range(1,len(i)+1):
        p.add(i[:j])

print(sorted(list(p))[k-1])

Solution (Python):
from collections import defaultdict

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

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for code in range(ord('a'),ord('z')+1):
    for right in d[chr(code)]:
        for sl in range(min(K,len(s[right:]))):
            sub.add(s[right:right+sl+1])
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break

Solution (Python):
from collections import defaultdict

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

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for i in range(26):
    for j in d[chr(ord('a')+i)]:
        for k in range(min(K,len(s[j:]))):
            sub.add(s[j:j+k+1])


    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break

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

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

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

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

Solution (Python):
import heapq
from itertools import accumulate, groupby, islice
 
s = input()
n = int(input())
 
gens = [accumulate(s[i:]) for i in range(len(s))]
sm = heapq.merge(*gens)
res, _ = next(islice(groupby(sm), n-1, n))
print(res)

Solution (Python):
s = raw_input()
k = int(input())
l = len(s)
arr = []

for i in range(l):
	for j in range(1,min(6,l-i+1)):
		arr.append(s[i:i+j])

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

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

t = set()

for i in range(len(s)):
  tt = ""
  for j in range(i, min(i+5, len(s))):
    tt+=s[j]
    t.add(tt)

print(sorted(t)[k-1])

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

l =[]

for i in range(len(s)):
    tmp = ''
    for j in range(i, len(s)):
        if j > i + 4: break
        tmp += s[j]
        l.append(tmp)
l.sort()

l2 = []
for x in l:
    if len(l2) > 6:
        break
    if x not in l2:
        l2.append(x)


ans = l2[K - 1]

print(ans)

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())
sub = set(S)
for step in range(2, 6):
    for i in range(0, len(S) - step + 1):
        sub.add(S[i:i+step])
print(sorted(sub)[K - 1])

Solution (Python):
import heapq
from itertools import groupby, islice

s = input()
n = int(input())

def substrings_starting_at(i):
  return (s[i:j+1] for j in range(i, len(s)))

gens = [substrings_starting_at(i) for i in range(len(s))]
sm = heapq.merge(*gens)
res, _ = next(islice(groupby(sm), n-1, n))
print(res)

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

Solution (Python):
s = input()
K = int(input())
sub = {s}
for d in range(1,K+1):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
print(sorted(sub)[K-1])

Solution (Python):
s = input()
K = int(input())
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
print(sorted(sub)[K-1])

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

chars = sorted(set(s))
lexicon = []

def next_word(cur):
    lexicon.append(cur)
    if len(lexicon) < K:
        for next_c in chars:
            next_w = cur + next_c
            if next_w in s:
                return next_word(next_w)

for char in chars:
    next_word(char)

print(lexicon[K-1])

Solution (Python):
s = input()
l_s = list(s)
K = int(input())
if K == 1:print(min(l_s));exit()
elif K == 2:
    idx = s.index(min(l_s))
    if idx < len(s)-1:
        print(s[idx:idx+2])
    else:
        print(sorted(l_s)[1])
    exit()
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
sub = list(sub)
n = len(sub)
for i in range(K):
    for j in range(n-i):
        a, b = sub[-i-1], sub[j]
        if a > b: sub[-i-1], sub[j] = b, a
print(sub[-K])

Solution (Python):
s = input()
K = int(input())
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
sub = list(sub)
n = len(sub)
for i in range(K):
    for j in range(n-i):
        a, b = sub[-i-1], sub[j]
        if a > b: sub[-i-1], sub[j] = b, a
print(sub[-K])

Solution (Python):
s=input()
K=int(input())
 
ans=[]
ans.append(s)
 
 
for i in range(len(s)):
 for j in range(len(s)-i):
  cut_s=s[i:i+j+1]
  ans.append(cut_s)
  ans=sorted(set(ans))
  if len(ans)>K:
   if cut_s==ans[K]:
     ans.pop()
     break;
   ans.pop()
 
answer=ans[K-1]
print(answer)

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

cand_list = []
for i in range(len(s)):
    for j in range(len(s)+1-i):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break
        elif len(cand_list) > k:
            cand_list.pop(len(cand_list) - 1)

print(sorted(cand_list)[k-1])

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

substr = set()
for i in range(len(s)):
    for j in range(i+1, i+K+1):
        substr.add(s[i:j])

print(sorted(substr)[K-1])

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

substr = set()
for i in range(len(s)):
    for j in range(i+1, i+K+1):
        substr.add(s[i:j])

print(sorted(substr)[K-1])

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

def decompose(s):
    l = []
    N = len(s)
    i = 1
    while i <= N:
        l.append(s[:i])
        i += 1
    l = list(set(l))
    l.sort()
    return l

def answer(slist,smin,k):
    indices = [i for i, x in enumerate(slist) if x == smin]
    ans = []
    for ind in indices:
        ans.extend(decompose(s[ind:min(ind+k,len(s))]))
    ans = list(set(ans))
    ans.sort()
    if len(ans) >= k:
        return ans[k-1]
    else:
        s_temp = slist.copy()
        k -= len(ans)
        for r in range(len(indices)):
            s_temp.remove(min(slist))
        smin = min(s_temp)
        j = answer(slist,smin,k)
        return j

s=answer(list(s),min(list(s)),k)
print(s)

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

Solution (Python):
s = input()
k = int(input())
arr = set()
arr.add(s)
for i in range(len(s)-1):
    if i > 5:
        break
    for j in range(0, len(s)):
        arr.add(s[j:j+i+1])

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

Solution (Python):
string =str(input())
K=int(input())
l=len(string)
substring = set()
for i in range(l):
    for j in range(i+1,i+K+1):
        substring.add(string[i:j])

sublist = list(substring)
sublist.sort()

print(sublist[K-1])

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

l = set([])
for i in range(len(s)):
  for j in range(i, min(len(s),i+K)):
    l.add(s[i:j+1])
l2 = list(l)
l2.sort()
print(l2[K-1])

Solution (Python):
s=input()
K=int(input())
mojiretsu=set()
for i in range(0,len(s)):
    for k in range(1,6):
        mojiretsu.add(s[i:i+k])
ans=sorted(mojiretsu)
print(ans[K-1])

Solution (Python):
import string


lowercase = string.ascii_lowercase

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

substrings = []

stack = list(lowercase)[::-1]

while len(substrings) < K:
    
    v = stack.pop()
    if v in s:
        substrings.append(v)
        for c in list(lowercase)[::-1]:
            stack.append(v+c)

print(substrings[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])


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

Solution (Python):
from sys import stdin


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = set()
    for c in sorted(list(set(s))):
        for x in sorted([s[i:] for i, x in enumerate(s) if x == c]):
            for y in [x[:j + 1] for j in range(len(x))]:
                result.add(y)
                if len(result) == K:
                    print(sorted(list(result))[-1])
                    return


if __name__ == '__main__':
    main()

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

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

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

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

arr = []
sn = len(s)
for i in range(1, K+1):
  for j in range(0, sn):
    if i+j <= sn:
	    arr.append(s[j:i+j])
    else:
      break
unique_arr = sorted(list(set(arr)))

print(unique_arr[K-1])

Solution (Python):
S = input()
K = int(input())
l = len(S)
topk = []
a = []

for i in range(l):
    for j in range(i + 1, i + K + 1):
        if j > l:
            break
        ss = S[i: j]
        a.append(ss)

print(sorted(list(set(a)))[K-1])

Solution (Python):
S=str(input())
K=int(input())
L=len(S)
a=[]
for i in range(L):
    for j in range(K):
        if i+j <= L:
            a.append(S[i:i+j+1])

a=sorted(list(set(a)))

print(a[K-1])

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

words = set()

l = k+1 if len(s) > k else len(s) + 1

for i in range(1,l):
    for j in range(len(s)):

        words.add(s[j:i+j])

sort_word = sorted(words)

print(sort_word[k-1])

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

sub = set()

for i in range(len(s)):
	for j in range(i + 1,i + K + 1):
		sub.add(s[i:j])

ans = list(sorted(sub))

print(ans[K - 1])

Solution (Python):
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    for j in range(0,K):
        substr = s[i:i+j+1]
        if not substr in d and len(substr)<=K:
            d.append(substr)
d.sort()
print(d[K-1])

Solution (Python):
s =input()
k =int(input())
a =[]
if len(s)==1:
    a.append(s)
else:
    for i in range(len(s)):
        for j in range(i,i+k+1):
            if i!=j:
                a.append(s[i:j])
            else:
                a.append(s[i])
a.sort()
temp=""
cnt,i=0,0
for i in range(len(a)):
    if temp != a[i]:
        cnt += 1
        if cnt ==k:
            break
    temp = a[i]
print(a[i])

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

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, K):
        substring = s[i:i + slen + 1]
        substr_set.add(substring)

print(sorted(substr_set)[K - 1])

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


for j in range(1,K+1):
    for i in range(len(s)):
        listA.append(s[i:i+j])
listA.sort()
x=""
count=0
for i in range(len(listA)):
    if(x!=listA[i]):
        count+=1
        x=listA[i]
    if(count==K):
        print(x)
        break;

Solution (Python):


s=raw_input()
K=int(raw_input())
r=[]
for i in xrange(len(s)):
 for j in xrange(i+1,i+K+1):
  r.append(s[i:j])

r.sort()
l=list(set(r))
l.sort()
print l[K-1]

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

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

Solution (Python):
s = input()
K = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
result = []

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])
    result = list(set(result))
    if len(result) > K:
        break

result.sort()
print(result[K - 1])

Solution (Python):
s = input()
K = int(input())
result = []
for i in range(len(s)):
    for j in range(i + 1, min(i + K + 1, len(s) + 1)):
        result.append(s[i:j])

result = list(set(result))
result.sort()


print(result[K - 1])

Solution (Python):
s = input()
K = int(input())
subs = []
for i in range(0, len(s)):
    for j in range(i + 1, K + i + 1 if i + K <= len(s) else len(s) + 1):
        subs.append(s[i:j])


subs = list(set(subs))

subs.sort()
print(subs[K - 1])

Solution (Python):
s = input()
K = int(input())
subs = []
for i in range(0, len(s)):
    for j in range(i+1, K+i+1 if i + K <= len(s) else len(s)+1):
        subs.append(s[i:j])
        if len(subs)==K:
            break;
subs = list(set(subs))
subs.sort()
print(subs[K-1])

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

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

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

subs = set()

for i in range(len(s)):
    for j in range(i+1,i+K+1):
        subs.add(s[i:j])

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

Solution (Python):
def main(s, K):
    l = list()
    for i in range(len(s)):
        for k in range(1, K + 1):
            sub = s[i:i + k]
            if sub not in l:
                l.append(sub)
    l = sorted(l)
    return l[K-1]

s = input()
K = int(input())
res = main(s, K)
print(res)

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

Solution (Python):
s = input()
n = int(input())
k = len(s)
substrings = set()
for i in range(k):
    for j in range(n):
        substrings.add(s[i:i+1+j])

print(sorted(substrings)[n-1])

Solution (Python):
str = input()
k = int(input())
 
substr = []
for i in range(len(str)):
  substr.extend([str[i:j] for j in range(i+1,i+6)])
 
substr = list(set(substr))
substr.sort()
print(substr[k-1])

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

s_set = set()
for i in range(len(s)):
    for j in range(i + 1, i + K + 1):
        if j > len(s) + 1:
            break
        s_set.add(s[i:j])
s_list = list(s_set)
s_list.sort()
print(s_list[K - 1])

Solution (Python):
if __name__ == '__main__':
    text = input()
    number = int(input())
    dic = []

    for text_len in range(1, min(len(text),number) + 1):
        for ss_len in range(0, len(text) - text_len + 1):
            word = text[ss_len:text_len + ss_len]
            if word not in dic:
                dic.append(word)

    dic = sorted(dic)

    print(dic[number - 1])

Solution (Python):





if __name__ == '__main__':
    s = input()
    k = int(input())
    extracted = set()
    s_len = len(s)

    
    
    for i in range(1, min(k, s_len) + 1):
        for j in range(s_len - i + 1):
            extracted.add(s[j:i + j])

    print(sorted(extracted)[k - 1])

Solution (Python):
import re

str = input()
k = int(input())

strl = list(set([c for c in str]))
strl.sort()

substring = []
for h in strl:
	compiled = re.compile(h)
	st = 0
	m = compiled.search(str, st)
	while m:
		sub = m.start()
		for i in range(sub, min(len(str), sub+5)):
			t = str[sub:i+1]
			if(not (t in substring)):
				substring.append(t)
		st = sub + 1
		m = compiled.search(str, st)
	
	if(len(substring)-len(strl) >= k-1):
		break


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

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

temp = set()

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

Solution (Python):





if __name__ == '__main__':
    s = input()
    k = int(input())
    extracted = list()
    s_len = len(s)

    for i in range(1, min(k, s_len) + 1):
        start = 0
        ended = i

        for j in range(s_len - i + 1):
            sub_str = s[start:ended]

            if sub_str not in extracted:
                extracted.append(sub_str)

            start += 1
            ended += 1

    sorted_extracted = sorted(extracted)
    print(sorted_extracted[k - 1])

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

Solution (Python):
s=input()
K=int(input())
if len(s)<5:
    s_len = len(s)
else:
    s_len = 5
ans=list()
for length in range(1,s_len + 1):
    for pos in range(0,len(s)-length+1):
        tmp = s[pos:pos+length]
        if tmp not in ans:
            ans.append(tmp)
    ans.sort()
    if len(ans)>5:
        del ans[5:len(ans)+1]


print(ans[K-1])

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










S = set()

for i in range(1, k+1):
    for j in range(len(s)-i+1):
            S.add(s[j:j+i])

T = sorted([x for x in S])

print(T[k-1])

Solution (Python):
str=input()
K=int(input())
s=set()
for scope in range(1,K+1):
    for f in range(len(str)-scope+1):
        s.add(str[f:f+scope])
print(sorted([x for x in s])[K-1])

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

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

print(sorted([i for i in sub])[K - 1])

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

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

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

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

array = []
for i in range(0, k):
    for j in range(0, len(s)-i):
        array.append(s[j:j+i+1])

print(sorted(set(array))[k-1])

Solution (Python):
s = input()
k = int(input())
substrings = set()
s_list = []
for i in range(len(s)):
    for j in range(i+1, i+6):
        substrings.add(s[i:j])
s_list = list(substrings)
s_list.sort()
print(s_list[k-1])

Solution (Python):
from string import ascii_lowercase

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

sub_set = set()
append_cnt = 0

for top_c in ascii_lowercase:
    for idx, c in enumerate(s):
        if c == top_c:
            for i in range(1, 6):
                sub_set.add(s[idx:idx+i])
    if len(sub_set) >= K:
        break

print(sorted(sub_set)[K-1])

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

for t in range(len(s)):
    for k in range(1,K+1):
        try:
            D.append(s[t:t+k])
        except:
            ValueError

print(list(sorted(set(D)))[K-1])

Solution (Python):
str = input()
K = int(input())
len = len(str)
se = set()
for k in range(1,min(5,len)+1):
  for i in range(len+1-k):
    se.add(str[i:i+k])
lis = list(se)

lis.sort()
print(lis[K-1])

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

substrings = []
for i in range(len(s)):
    for j in range(len(s)-i+1):
        
        if j <= K and s[i:i+j] != '':
            substrings.append(s[i:i+j])
substrings = sorted(set(substrings))
print(substrings[K-1])

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

Solution (Python):


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

l = len(s)
all = set()
for i in range(l):
    cnt = 0
    for j in range(i, l):
        all.add(s[i:j + 1])
        cnt += 1
        if cnt >= k:
            break

print(sorted(all)[k - 1])

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

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

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

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


candidates = []

for i in range(len(s)):
  for j in range(i + 1, len(s) + 1):
    if not s[i:j] in candidates:
      candidates += [s[i:j]]
    if len(s[i:j]) >= k:
      break

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

Solution (Python):

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

Solution (Python):
s=input().strip()
k=int(input())
A=[]
for i in range(len(s)):
  for j in range(1,6):
    if i+j<=len(s):
      A.append(s[i:i+j])
B=sorted(list(set(A)))
print(B[k-1])

Solution (Python):


instr = input()
target = int(input())


str_list = []
for i in range(len(instr)):

	
	for j in range(i+1, len(instr)+1):
		
		
		if j-i > target:
			break

		
		str_list.append(instr[i:j])


str_list = list(set(str_list))

str_list.sort()

print(str_list[target-1])

Solution (Python):


instr = input()
target = int(input())


str_list = []
for i in range(len(instr)):

	
	for j in range(i+1, len(instr)+1):
		
		
		if j-i > target:
			break

		
		str_list.append(instr[i:j])

		j += 1
	i += 1


str_list = list(set(str_list))

str_list.sort()

print(str_list[target-1])

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

def n_th_singleton(n, moji):
    min = moji[0]
    min_nth_itimoji = []
    if n >= 2:
        nth_soeji = [j for j in range(len(moji)) if hikaku(moji[j], moji, n_th_singleton(n-1, moji))]
        
        min = moji[nth_soeji[0]]
        for i in nth_soeji:
            if (min >= moji[i]):
                min = moji[i]
                min_nth_itimoji.append(i)
    else:
        for i in range(len(moji)):
            if min >= moji[i]:
                min = moji[i]
                min_nth_itimoji.append(i)
    
    return min_nth_itimoji

def hikaku(singleton, original_moji, soeji_list):
    for j in soeji_list:
        if singleton <= original_moji[j]:
            return False
    return True

def solution(moji, num):
    sucesseive_length = 0
    n = 1
    while sucesseive_length < num:
        n_list = n_th_singleton(n, moji)
        n_sorted_submoji_list = [moji[i:] for i in n_list]
        n_sorted_submoji_list.sort()
        not_choufuku_list = []
        

        j = 0
        while j < len(n_sorted_submoji_list):
            for k in range(1, len(n_sorted_submoji_list[j])+1):
                if (n_sorted_submoji_list[j][:k] not in not_choufuku_list) and sucesseive_length < num:
                    sucesseive_length += 1
                    not_choufuku_list.append(n_sorted_submoji_list[j][:k])
                    
            if sucesseive_length == num:
                    
                return not_choufuku_list[-1]
            j += 1
        
        n += 1


print(solution(mojiretu, K))

Solution (Python):
s=input();print(sorted({s[i:i+j]for i in range(len(s))for j in range(6)})[int(input())])

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

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

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

Solution (Python):



s = input()
k = int(input())
 
 
sub = set()

for i in range(len(s)):
	for j in range(i+1, min(i+6,len(s)+1)):
		sub.add(s[i:j])

sub = list(sub) 
sub.sort()


print(sub[k-1])

Solution (Python):
s = input()
k = int(input())
st = set()
for i in range(len(s)):
    j = 1
    while j <= k and i+j <= len(s):
        st.add(s[i:i+j])
        j += 1
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))

Solution (Python):
s = input()
K = int(input())
list = ["zzz" for i in range(K)]
for i in range(len(s)):
    for j in range(len(s)-i):
        if j > 5:
            continue
        if len(list) < K or s[i : i+j+1] < list[K-1]:
            if not s[i : i+j+1] in list:
                list[K-1] = s[i : i+j+1]
                list.sort()
print(list[K - 1])

Solution (Python):
s = list(input())
k = int(input())
subs = []
for i in range(min(k,len(s))):
  for j in range(len(s)-i):
    subs.append(''.join(s[j:j+i+1]))
subs = list(set(subs))
subs.sort()

print(subs[k-1])

Solution (Python):
import heapq

s=input()
k=int(input())
n=len(s)
ans=set()

for i in range(n+1):
    j=1
    while j<=k and i+j<=n:
        ans.add(s[i:i+j])
        j+=1


ansh=[]
for ss in ans:
    heapq.heappush(ansh,ss)
for _ in range(k-1):
    heapq.heappop(ansh)
print(ansh[0])