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())

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


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

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

t=[]
for i in range(0,min(len(s),5)):
  for j in range(n-i):
    t.append(s[j:j+i+1])
t=list(set(t))
t.sort()
print(t[K-1])

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    t = str(input().rstrip('\n'))
    s = collections.Counter(t).most_common()
    k = int(input().rstrip('\n'))
    s.sort()
    d = {}
    for key, v in s:
        for i in range(len(t)):
            if t[i] == key:
                for j in range(i + 1, i + 6):
                    d[t[i:j]] = 1
        if len(d) >= k:
            print(sorted(d.items())[k-1][0])
            exit()


if __name__ == '__main__':
    slove()

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

abc = collections.defaultdict(list)

for i in range(len(s)):
  for j in range(1,K+1):
    if i+j <= len(s):
        abc[s[i:i+j]].append(i)


abc = list(abc.items())
abc.sort(key=lambda x: x[0])

print(abc[K-1][0])

Solution (Python):
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      for k in range(K):
        if j+k == len(s):
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break

Solution (Python):
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      temp = []
      for k in range(5):
        if j+k == len(s) or len(temp)>=K:
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    k = int(input().rstrip('\n'))
    d = []
    for i in range(len(s)):
        for j in range(i + 1, min(i + 1 + k, len(s) + 1)):
            d.append(s[i:j])
    import collections
    d = sorted(collections.Counter(d).most_common())
    print(d[k-1][0])


if __name__ == '__main__':
    main()

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

substr = []
N = len(s)

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

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

Solution (Python):
s=input()
k=int(input())
sng=len(s)
t=sorted(s)
mini=[]

koho=[t[0]]
itimo=[t[0]]
now=0
while len(koho)<=4 and now!=len(t):
    if koho[-1]!=t[now]:
        koho.append(t[now])
        itimo.append(t[now])
    now+=1


swit=[]
for i in range(sng):
    if s[i] in itimo:
        swit.append(5)
    if len(swit)>0:
        for sw in swit:
            
            sin=s[i-(5-sw):i]
            if sin!="":
                koho.append(s[i-(5-sw):i+1])
    swit2=[]
    for sw in range(len(swit)):
        if swit[sw]>0:
            swit2.append(swit[sw]-1)
    swit=swit2

koho=sorted(koho)
mae=koho[0]
now=1
koho2=[koho[0]]
while now<len(koho):
    if koho[now]!=mae:
        mae=koho[now]
        koho2.append(koho[now])
    now+=1

print(koho2[k-1])

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

s = input()
n = len(s)
k = I()
q = []
for i in range(n):
    heappush(q,(s[i],i))
d = defaultdict(lambda : 1)
while k:
    si,i = heappop(q)
    if d[si]:
        k -= 1
        d[si] = 0
    if not k:
        print(si)
        quit()
    if i < n-1:
        si += s[i+1]
        i += 1
        heappush(q,(si,i))

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

substrings = []

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

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

substrings = []

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

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

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

cnt = 0
uni = set()
for i in range(1, K+1):
    for j in range(len(s)):
        if len(s) - (j+i) < 0: break
        uni.add(s[j:j + i])

print(sorted(list(uni))[K-1])

Solution (Python):
s=input()
st=set()
for i in range(len(s)):
  for j in range(6):
    st.add(s[i:i+j])
print(sorted(st)[int(input())])

Solution (Python):
s = input()
K = int(input())
l = ['zzzzzzzzzzzzzzz','zzzzzzzzzzzzzzz','zzzzzzzzzzzzz','zzzzzzzzzzzz','zzzzzzzzz']
N = len(s)

for i in range(K+1):
    for j in range(N-i):
        tmp = s[j:j+i+1]
        if tmp not in l:
            l.append(tmp)
        l.sort()
        l = l[0:5]


l.sort()



ans = l[K-1]
print(ans)

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

P = []
len_s = len(S)
for k in range(1, K+1):
    for i in range(len_s-k+1):
        P.append(S[i:i+k])
P.sort()

ans = P[0]
cnt = 1
i = 1
while cnt < K:
    if ans != P[i]:
        ans = P[i]
        cnt += 1
    i += 1

print(ans)

Solution (Python):


s=input()
k=int(input())
ls=len(s)

ans=set(s)
for i in range(2,k+1):
    l=1
    res=s[0:i]
    while l<ls-i+1:
        ans.add(res)
        r=l+i-1
        res=res[1:]+s[r]
        l+=1
    ans.add(res)
ans=sorted(list(ans))
print(ans[k-1])

Solution (Python):
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""

def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
a = [i for i in input()]
n = ip()
minplace = [0]
minlet = a[0]
nextlet = 'z'
nextminplace = []
for i in range(1,len(a)):
    if a[i] < minlet:
        nextlet = minlet
        nextminplace = copy.copy(minplace)
        minlet = a[i]
        minplace.clear()
        minplace.append(i)
    elif a[i] == minlet:
        minplace.append(i)
    elif a[i] < nextlet:
        nextminplace.clear()
        nextlet = a[i]
        nextminplace.append(i)
    elif a[i] == nextlet:
        nextminplace.append(i)
wl = []

for start in minplace:
    word = [a[start]]
    wl.append(''.join(word))
    for i in range(start+1,start+5):
        if i >= len(a): break
        word.append(a[i])
        wl.append(''.join(word))
wl = list(set(wl))

for start in nextminplace:
    word = [a[start]]
    wl.append(''.join(word))
    for i in range(start+1,start+5):
        if i >= len(a): break
        word.append(a[i])
        wl.append(''.join(word))

wl = list(set(wl))
wl.sort()
print(wl[n-1])

Solution (Python):
S = input()
K = int(input())
subs = []
for n in  range(len(S)):
    for l in range(1,K+1):
        subs.append(S[n:n+l])
res = sorted(set(subs))
print(res[K-1])

Solution (Python):
s = input()
K = int(input())
def same_head_num(a,b):
    n = 0
    N = min(len(a),len(b))
    while n < N:
        if a[n] == b[n]:
            n += 1
        else:
            break
    return n

strings = ['']
N = len(s)
for i in range(N):
    strings.append(s[i:])
strings.sort()
for i in range(1,N+1):
    head_n = same_head_num(strings[i-1],strings[i])
    tail_n = len(strings[i]) - head_n
    if tail_n < K:
        K -= tail_n
        continue
    else:
        print(strings[i][:head_n+K])
        break

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

Solution (Python):
import sys

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

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

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

substrings = set()
for len_sub in range(K):
    for start in range(len(s)-len_sub):
        substring = s[start:start+len_sub+1]
        substrings.add(substring)

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

Solution (Python):

def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, k + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

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

substr = []
for n in range(1, k+1):
    for i in range(len(s)-n+1):
        substr.append(s[i:i+n])

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

Solution (Python):
from collections import deque
s=input()
length=len(s)

K=int(input())


left=0
right=0



ss=deque()
for left in range(length+1):
    for right in range(left+1,length+1):
      if len(s[left:right]) <= K:
        ss.append(s[left:right])

myset=set(ss)
for i in range(K):
    tmp=min(myset)
    myset.remove(tmp)
print(tmp)

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

p.sort()
ans = 0
q = ""
for i in p:
    if i>q:
        ans += 1
        q = i
    if ans == k:
        print(q)
        exit()

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

for i in range(len(s)):
    for j in range(K):
        if i+j < len(s):
            t.add(s[i:i+j+1])

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

Solution (Python):
S = input()
K = int(input())
a = {s:[] for s in 'abcdefghijklmnopqrstuvwxyz'}
for i in range(len(S)):
    a[S[i]].append(S[i:i+K])
tmp = []
for c in 'abcdefghijklmnopqrstuvwxyz':
    for s in sorted(a[c]):
        for i in range(1,len(s)):
            if s[:i] in tmp:
                K += 1
        if len(s) >= K:
            print(s[:K])
            exit()
        else:
            K -= len(s)
            for i in range(1,len(s)+1):
                tmp.append(s[:i])

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

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

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

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

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

l = []
n = len(s)

for i in range(n):
    for j in range(6):
        if i + j <= n:
            l.append(s[i:i + j])

l = set(l)
l = sorted(l)

print(l[K])

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

Solution (Python):
hoge=input()
k=int(input())
ans=[]
for i in range(len(hoge)):
  for j in range(5):
    ans.append(hoge[i:1+i+j])
ans=list(set(ans))
ans.sort()
print(ans[k-1])

Solution (Python):
S = input()
K = int(input())
x = set()

for i in range(len(S)):
    for j in range(1,min(len(S) - i + 1, K + 1)):
        x.add(S[i:i + j])

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

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

Solution (Python):
s = input()
k = int(input())
l = sorted(list(set(list(s))))
x = set(list())
for i in l:
    x |= set([s[ii:iii+1] for ii in range(len(s)) for iii in range(ii,min(len(s),ii+5)) if s[ii] == i])
    if len(x) > 5:
        break
x = sorted(x)

print(x[k-1])

Solution (Python):
S = input()
K = int(input())
N = len(S)
subst = set()
for i in range(1,K+1):
    for j in range(N-i+1):
        subst.add(S[j:j+i])
L = sorted(list(subst))
print(L[K-1])

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

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

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    k = f()[0]

    a = set()

    slen = len(s)
    for i in range(slen):
        for j in range(1,k+2):
            if i+j <= slen:
                a.add(s[i: i+j])
    
    a = sorted(a)
    print(a[k-1])


solve()

Solution (Python):
s = input()
K = int(input())
strs = [[] for _ in range(26)]
cnts = [0]*26

for ind,i in enumerate(s):
    if(sum(cnts[:ord(i)-97])>=5):
        continue
    for j in range(1,K+1):
        st = s[ind:ind+j]
        if(not st in strs[ord(i)-97]):
            strs[ord(i)-97].append(st)
            cnts[ord(i)-97]+=1


cnt = 0
num = 0
while(cnt<K):
    cnt += len(strs[num])
    num += 1
num -= 1
cnt -= len(strs[num])
strs[num].sort()
print(strs[num][K-cnt-1])

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

a = []
for i in range(len(S)):
	for l in range(1, len(S) - i + 1):
		s = S[i:i + l]
		
		if s in a:
			continue
		if len(a) < 5:
			a += [s]
			a = sorted(a)
		else:
			if a[-1] < s:
				break
			else:
				a[-1] = s
				a = sorted(a)
print(a[K - 1])

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

Solution (Python):
S = raw_input()
K = input()

ans = []
for i in range(len(S)):
    for j in range(1,K+1):
        if i+j <= len(S):
            if S[i:i+j] not in ans:
                ans.append(S[i:i+j])

ans.sort()

print ans[K-1]

Solution (Python):
s = input()
k = int(input())
N = len(s)
subs = set()
for i in range(1, N):
    l = s[:i]
    r = s[i:]
    if len(l) > k:
        l = l[-k:]
    if len(r) > k:
        r = r[:k]
    while not l == '':
        subs.add(l)
        l = l[1:]
    while not r == '':
        subs.add(r)
        r = r[:-1]
subs.add(s)
subs = sorted(subs)
print(subs[k-1])

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

def find(str):
	lt = []
	for start in range(len(str)):
		for end in range(start + 1, len(str) + 1):
			lt.append(str[start:end])
	lt = list(set(lt))
	lt.sort()

	return lt

s_pt = list(set(list(s)))
s_pt.sort()
ans = []
for i in range(min(5, len(s_pt))):
	ind = [ix for ix, x in enumerate(s) if x == s_pt[i]]
	for j in ind:
		ans += find(s[j:min(j+5, len(s))])
	ans = list(set(ans))
	if len(ans) >= 5:
		break
ans = list(set(ans))
ans.sort()
print(ans[K-1])

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

    cand = set()
    for e,c in enumerate(s):
        for i in range(1, K+1):
            if e+i > len(s): break                
            sub = s[e:e+i]
            cand.add(sub)
    cand = list(cand)
    cand.sort()

    print(cand[K-1])

    
    
if __name__ == "__main__":
    solve()

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

C = list(set(S[i:i + j + 1] for i in range(N) for j in range(K) if i + j < N))
C.sort()
print(C[K - 1])

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

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

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

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

Solution (Python):
s = input()
K = int(input())
S = set()
ans = []

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

print(sorted(list(S))[K-1])

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

Solution (Python):
import numpy as np
import math




























def main():
    s = input()
    K = int(input())
    str_lists = []
    for str_num in range(1, K + 1):
        for i in range(len(s)):
            str_ = s[i: i + str_num]
            if str_ not in str_lists:
                str_lists.append(str_)
    str_lists = sorted(str_lists)
    print(str_lists[K - 1])
    
            

if __name__ == '__main__':
    main()

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

a = set()
for i in range(1, 6):  
    for j in range(n - (i - 1)):  
        a.add(s[j:j + i])
print(sorted(a)[K - 1])

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

l = len(s)
o = []
for j in range(1,6):
    for i in range(l):
        a = s[i:i+j]
        if not(a in o):
            o.append(a)

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

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

Solution (Python):
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, min(len(s)+1, i+6)):
                ans.append(s[i:k])
        ans = set(ans)
        ans = list(ans)
        cnt = len(ans)
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

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

Solution (Python):

l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

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

l2=[]

a=''
for x in l:
  if x in s:
    a=x
    for i in range(len(s)):
      if s[i]==a:
        for j in range(6):
          l2.append(''.join(s[i:i+j]))

l2=list(set(l2))
l2.remove('')
l2.sort()
print(l2[K-1])

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

res = []
charGram = [[''.join(s[i:i + n]) for i in range(len(s) + 1 - n)] for n in range(1,K + 1)]

for i in range(len(charGram)):
    res += charGram[i]

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

Solution (Python):
from sys import stdin
s=stdin.readline().rstrip()
K=int(stdin.readline().rstrip())
subs=[]
for i in range(K):
  for j in range(0, len(s)-i):
    subs.append(s[j:j+i+1])
subs=list(set(subs))
subs.sort()
print(subs[K-1])

Solution (Python):
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            if (j+1 - i) > k:
                break

            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

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

Solution (Python):
s = input()
k = int(input())
n = len(s)
s_list = []
if n > k:
    for i in range(n-k+1):
        s_list.append(s[i:i+k])
else:
    s_list.append(s)
ans_list = []
for ss in s_list:
    for i in range(len(ss)+1):
        for j in range(i+1, len(ss)+1):
            t = ss[i:j]
            ans_list.append(t)
ans_list = list(set(ans_list))
ans_list.sort()
print(ans_list[k-1])

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

t = []

for i in range(len(s)):
    string = ""
    if i < 4:
        for j in range(0,i+1):
            string = s[i-j] + string
            if string not in t:
                t.append(string)
            else:
                continue
    else:
        for j in range(0,5):
            string = s[i-j] + string
            if string not in t:
                t.append(string)
            else:
                continue
t.sort()
print(t[n-1])

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

t = []

for i in range(len(s)):
    string = ""
    if i < 4:
        for j in range(0,i+1):
            string = s[i-j] + string
            if string not in t:
                t.append(string)
            else:
                continue
    else:
        for j in range(0,5):
            string = s[i-j] + string
            if string not in t:
                t.append(string)
            else:
                continue
t.sort()
print(t[n-1])

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

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

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

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

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

Solution (Python):
s=input()
k=int(input())
ms=min(s)
l=[]
for i in range(len(s)):
    if s[i]==ms:
        for j in range(1,k+1):
            l.append(s[i:i+j])
l=list(set(l))
if len(l)<k:
    ls=list(set(s))
    ls.sort()
    ms=ls[1]
    for i in range(len(s)):
        if s[i]==ms:
            for j in range(1,k+1):
                l.append(s[i:i+j])
            l=list(set(l))
    if len(l)<k:
        ms=ls[2]
        for i in range(len(s)):
            if s[i]==ms:
                for j in range(1,k+1):
                    l.append(s[i:i+j])
                l=list(set(l))
l.sort()
print(l[k-1])

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

for i in range(len(s)):
    S.add(s[i])
    for j in range(i+1, K+i+1):
        ss = ''
        if j >= len(s):
            continue
        ss = s[i] + s[i+1:j+1]
        S.add(ss)
        
S = list(S)
S.sort()

print(S[K-1])

Solution (Python):
S = [i for i in input()]
K = int(input())
chars = []
i =0
for i in range(len(S)):
    for j in range(1,K+1):
        chars.append("".join(S[i:i+j]))
chars=sorted(set(chars))
print(chars[K-1])

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

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

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        break

key = i

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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

Solution (Python):
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())  
def II(): return int(sys.stdin.readline())  
def IS(): return input()  
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


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

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

a = sorted(set(s))[:5]
for num in range(2,6):
  if len(s) >= num:
    b = sorted(set([s[i:i+num] for i in range(len(s)-num+1)]))[:5]
    a.extend(b)
  else:
    break

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

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

a = sorted(set(s))[:5]
if len(s) >= 2:
  b = sorted(set([s[i:i+2] for i in range(len(s)-1)]))[:5]
  a.extend(b)
if len(s) >= 3:
  c = sorted(set([s[i:i+3] for i in range(len(s)-2)]))[:5]
  a.extend(c)
if len(s) >= 4:
  d = sorted(set([s[i:i+4] for i in range(len(s)-3)]))[:5]
  a.extend(d)
if len(s) >= 5:
  e = sorted(set([s[i:i+5] for i in range(len(s)-4)]))[:5]
  a.extend(e)

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

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

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

print(sorted(list(strs))[K-1])

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

s1 = list(set(s.copy()))
s1.sort()
for i in range(5):
  s.append('')

if(len(s1) >=3):  n1 = 3
else:  n1 = len(s1)
first = []
for i in range(n1):
  first.append(s1[i])

s2 = []
for i in range(n):
  for j in first:
    if(s[i] == j):
      s2.append(s[i]),s2.append(s[i]+s[i+1]),s2.append(s[i]+s[i+1]+s[i+2])
      s2.append(s[i]+s[i+1]+s[i+2]+s[i+3]),s2.append(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
s2 = list(set(s2))
s2.sort()
ans = s2[K-1]
print(ans)

Solution (Python):
from collections import defaultdict
import string
import itertools

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

def it(s):
    subs = sorted(s[i:] for i in range(len(s)))
    writed = set()
    for sub in subs:
        for i in range(len(subs)):
            w = sub[:i+1]
            if w not in writed:
                yield w
                writed.add(w)

for ans in itertools.islice(it(s), k-1, k):
    print(ans)

Solution (Python):
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(input())])

Solution (Python):
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(len(s)*6)})[int(input())])

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

L = sorted(L)

sub = ""
x = 0
for i in L:
	if sub != i:
		sub = i
		x += 1
	
	if x == K:
		print(sub)
		break

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

for i in range(len(s)):
    S.add(s[i])
    S.add(s[i:i+2])
    S.add(s[i:i+3])
    S.add(s[i:i+4])
    S.add(s[i:i+5])

S = sorted(list(S))
print(S[K-1])

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

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

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

Solution (Python):
import sys

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

chars = sorted(set(s))
n = len(s)

for j in range(min(3, len(chars))):
  ans = chars[j]
  K -= 1
  if K == 0:
    print(ans)
    break
  while True:
    places = []
    index = -1
    while True:
      index = s.find(ans, index+1)
      if index == -1:
        break
      places.append(index)
      
    if len(ans) == len(s) - places[0]:
      break

    next_char = 'z' * 6
    for k in places:
      if k >= len(s)-len(ans):
        break
      next_char = min(next_char, s[k+len(ans)])

    ans += next_char
    K -= 1
    if K == 0:
      print(ans)
      sys.exit()

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

Solution (Python):

import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]
    input_raw = read_func().strip().split()
    [K] = [int(input_raw[0])]








    sub_list = set([])
    for i in range(len(S)):
        for j in range(i + 1, i + 6):
            sub_list.add(S[i:j])

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


if __name__ == '__main__':
    main()

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

keys = []
for start in range(len(s)):
  for end in range(start+1, min(start+6, len(s)+1)):
    key = s[start:end]
    if key in keys:
      continue
    if len(keys) < 5:
      keys.append(key)
      keys.sort()
    elif keys[-1] > key:
      keys.append(key)
      keys.sort()
      keys = keys[:-1]
print(keys[k-1])