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

sub_strings = []
for i in range(len(s)):
  for j in range(1, K+1):
    string = s[i:i+j]
    if string not in sub_strings:
      sub_strings.append(string)
sub_strings.sort()

print(sub_strings[K-1])

Solution (Python):
s=input()
k=int(input())
a=[]
for i in range(len(s)):
    for j in range(1,k+1):
        if i+j<=len(s)+1:
            a.append(s[i:i+j])
        
a=list(set(a))
a.sort()

print(a[k-1])

Solution (Python):
import itertools
s = input()
K = int(input())
dp = []

def substr(x):
    table = {}
    for i, j in itertools.combinations(range(len(x) + 1), 2):
        table[x[i:j]] = 1
    return sorted(table.keys())[:5]

dp = []

if len(s) < 6:
    dp = substr(s)
else:
    dp = substr(s[-5:])
    for i in range(-6, -len(s) -1, -1):
        for j in range(1, 6):
            if not s[i : i + j] in dp:
                dp = sorted(dp + [s[i : i + j]])[:5]
print(dp[K - 1])

Solution (Python):
s = input()
K = int(input())
ans = []
for i in set(s):
    ans.append(i)

if K == 1:
    print(sorted(ans)[0])
else:
    for i in range(2, 6):
        for j in range(len(s) - i + 1):
            ans.append(s[j:j+i])
    ans = list(set(ans))
    ans.sort()
    print(ans[K - 1])

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

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

sub_string = list(set(sub_string))
sub_string.sort()

print(sub_string[K-1])

Solution (Python):
s = input()
K = int(input())
one = list(set(s))
check = 2
if len(s) >= 2:
    while check <= len(s) and check <= 5:
        for i in range(len(s) - check + 1):
            one.append(s[i:i+check])
        check += 1
    one = sorted(set(one))
    print(one[K-1])
    
     
else:
    one = sorted(one)
    print(one[K-1])

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

t = len(s)
u = []
u2 = []
"""for i in range(t):
    u.append([])"""
for i in range(5):
    u.append([])

for j in range(5):
    for i in range(t):
        u[j].append([])

for i in range(t):
    u2.append([])


for j in range(5):
    for i in range(t):
        if j == 0:
            if s[i] not in u2[j]:
                u[j][i].append(s[i])
                u2[j].append(s[i])
                u[j][i].append(i)
        elif j == 1:
            if i + 1 < t:
                if s[i] + s[i + 1] not in u2[j] and s[i] + s[i + 1] not in u2[j - 1]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1])
                            u2[j].append(s[i] + s[i + 1])
                            u[r][i].append(i)
                            break
        elif j == 2:
            if i + 2 < t:
                if s[i] + s[i + 1] + s[i + 2] not in u2[j] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 1] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 2]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2])
                            u[r][i].append(i)
                            break
        elif j == 3:
            if i + 3 < t:
                if s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 1] \
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 2] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 3]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
                            u[r][i].append(i)
                            break
        elif j == 4:
            if i + 4 < t:
                if s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 1]\
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 2]and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 3]\
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 4]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])
                            u[r][i].append(i)
                            break
    """for i in range(t):
    for j in range(k):
        if j == 0:
            u[i].append(s[i])
        elif j == 1:
            u[i].append(s[i] + s[i + 1])
        elif j == 2:
            u[i].append(s[i] + s[i + 1] + s[i + 2])
        elif j == 3:
            u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
        elif j == 4:
            u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])"""
p = [0] * t
n = "z" * 10000
m = -1
l = -1
for i in range(5):
    for j in range(t + 5):
        if j < len(u[0]):
            if u[0][j] != []:
                if u[0][j][0] <= n:
                    n = u[0][j][0]
                    m = u[0][j][1]
                    l = j
    
    if i + 1 == k:
        print(n)
        
        exit()
    else:
        u[0].append(u[1 + p[m]][m])
        p[m] += 1
        u[0][l].pop(0)
        u[0][l].pop(0)
        n = "z" * 10000
        m = -1
        l = -1

Solution (Python):
def 解():
    sS = input().rstrip()




    iK = int(input())
    iL = len(sS)
    iC = 0

    for s in sorted(set(sS)):
        d = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        d.add(sS[i:i+j])
            aS = sorted(d)
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    d.add(sS[i:i+j])
            aS = sorted(d)
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()

Solution (Python):
def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()

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

st = [s[i:i+j+1] for i in range(len(s)) for j in range(k+1)]
se = set(st)
a = list(se)
a.sort()
print(a[k-1])

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

for i in range(len(S)) :
    for k in range(K+1) :
        sub = S[i:k+i]
        P.add(sub)
P = sorted(list(P))
print(P[K])

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
k = ni()

lens = len(s)

subset = set()

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

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
k = ni()

lens = len(s)

subset = set()

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

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

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

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

Solution (Python):
s=input()
k=int(input())
mydict=set()
while(1):
    tmp=[]
    for i in range(0,len(s)):
        if(s[i] in mydict):
            continue
        if(len(tmp)==0):
            tmp.append(i)
            continue
        if(s[i] < s[tmp[0]]):
            tmp=[i]
        elif(s[i] == s[tmp[0]]):
            tmp.append(i)
    for i in tmp:
        for j in range(k):
            try:
                mydict.add(s[i:i+j+1])
            except:
                pass
    if(len(mydict)>=k):
        break

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

Solution (Python):
s=input()
k=int(input())
l=[]
for v in range(len(s)):
  if s[v] not in l:
    l.append(s[v])
if k>1:
  for w in range(len(s)-1):
    if s[w:w+2] not in l:
      l.append(s[w:w+2])
if k>2:
  for x in range(len(s)-2):
    if s[x:x+3] not in l:
      l.append(s[x:x+3])
if k>3:
  for y in range(len(s)-3):
    if s[y:y+4] not in l:
      l.append(s[y:y+4])
if k>4:
  for z in range(len(s)-4):
    if s[z:z+5] not in l:
      l.append(s[z:z+5])
l.sort()
print(l[k-1])

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

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

def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(min(len(s), i + 5), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))

Solution (Python):
s = raw_input()
K, = map(int, raw_input().split())
L = len(s)
a = ["zzzzzz"]*5
b = {}
for i in range(L):
  for j in range(i+1,L+1):
    sij = s[i:j]
    if sij < a[4]:
      if sij not in b:
        a.append(sij)
        a.sort()
        a = a[:5]
        b[sij] = 1
    else:
      break
print a[K-1]

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

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

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

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

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

Solution (Python):

s=str(input())
K=int(input())
s_all=[]
s_ans=[]
for i in range(K):
    for j in range(len(s)-i):
        s_all.append(s[j:j+i+1])
sorted_s_all=sorted(s_all)
for i in range(len(sorted_s_all)):
    if i==0:
        s_ans.append(sorted_s_all[i])
    elif sorted_s_all[i]!=sorted_s_all[i-1]:
        now=sorted_s_all[i]
        before=sorted_s_all[i-1]
        s_ans.append(sorted_s_all[i])
print(str(s_ans[K-1]))

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

D = []
if len(s) >= 5:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
    for i in range(len(s)-2):
        if s[i]+s[i+1]+s[i+2] not in D:
            D.append(s[i]+s[i+1]+s[i+2])
    for i in range(len(s)-3):
        if s[i]+s[i+1]+s[i+2]+s[i+3] not in D:
            D.append(s[i]+s[i+1]+s[i+2]+s[i+3])
    for i in range(len(s)-4):
        if s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4] not in D:
            D.append(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
elif len(s) == 4:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
    for i in range(len(s)-2):
        if s[i]+s[i+1]+s[i+2] not in D:
            D.append(s[i]+s[i+1]+s[i+2])
    for i in range(len(s)-3):
        if s[i]+s[i+1]+s[i+2]+s[i+3] not in D:
            D.append(s[i]+s[i+1]+s[i+2]+s[i+3])
elif len(s) == 3:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
    for i in range(len(s)-2):
        if s[i]+s[i+1]+s[i+2] not in D:
            D.append(s[i]+s[i+1]+s[i+2])
elif len(s) == 2:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
else:
    for i in range(len(s)):
        D.append(s[i])
D.sort()
print(D[K-1])

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

que = []
heapq.heapify(que)
subs = set([])
for char in range(97, 97+26):
    char = chr(char)
    for i, ss in enumerate(s):
        if ss == char:
            heapq.heappush(que, (ss, i))
    while len(que) > 0:
        sub, i = heapq.heappop(que)
        if not sub in subs:
            subs.add(sub)
            k -= 1
            
            if k == 0:
                print(sub)
                exit()
        
        i_end = i+len(sub)+1
        if i_end > len(s):
            continue
        else:
            heapq.heappush(que, (s[i:i+len(sub)+1], i))

Solution (Python):
def run(s, K):
    sub_list = []
    for i in range(len(s)):
        for j in range(i, i+K):
            if j+1 > len(s):
                break
            sub_list.append(s[i:j+1])
    sub_list = sorted(set(sub_list))
    return sub_list[K-1]


def main():
    s = input()
    K = int(input())
    print(run(s, K))


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
K = int(input())
L = []
for i in range(len(s)):
    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()
n = len(s)
s = s + ' '
k = int(input())
l = []
for i in range(1, k+1):
    for j in range(n - i + 1):
        l.append(s[j:j + i])
ans = sorted(list(set(l)))[k - 1]
print(ans)

Solution (Python):

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

dict_set = set([])


for strlen in range(1,K+1):
    for j in range(len(s)-strlen+1):
        
        dict_set.add(s[j:j+strlen])

dict_list = sorted(list(dict_set))

print(dict_list[K-1])

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

for i in range(len(s)):
    for k in range(6):
        if s[i:min(i+k,len(s))] not in dict:
            dict.append(s[i:min(i+k,len(s))])
dict.sort()
print(dict[K])

Solution (Python):
s = input()
n = len(s)
k = int(input())
l = set()
for t in range(1,k+1):
  for i in range(max(n-t+1,0)):
    l.add(s[i:i+t])
a = list(l)
a.sort()
print(a[k-1])

Solution (Python):
s = input()
l = []
L = len(s)
for i in range(len(s)):
    l.append(s[i])
    l.append(s[i:min(i+2,L)])
    l.append(s[i:min(i+3,L)])
    l.append(s[i:min(i+4,L)])
    l.append(s[i:min(i+5,L)])
l = sorted(set(l))

print(l[int(input())-1])

Solution (Python):
s=input()
k=int(input())
n=len(s)
d=set()


for i in range(n):
    for j in range(i,min(n,i+5)):
        d.add(s[i:j+1])
ans=sorted(list(d))
print(ans[k-1])

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

t = sorted(set(s))[0:K]

l = sorted(set(s))[0:K]

for i in range(min(K,len(t))):
    w = t[i]
    for j in range(len(s)):
        if s[j]==w:
            for k in range(2,6):
                l.append(s[j:j+k])

l = sorted(set(l))

print(l[K-1])

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

c = []
c += list(s)
for j in range(2,6):
    for i in range(len(s)-j+1):
        c.append(s[i:i+j])

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

Solution (Python):
s = list(input())
K = int(input())
j = 0
candidate = []
while True:
    if j > 26:
        break
    for i in range(len(s)):
        if s[i] == chr(ord("a") + j):
            for k in range(1, min(6, len(s) - i + 1)):
                candidate.append(s[i:i + k])
    j += 1
i = 1
candidate.sort()
while i < len(candidate):
    if candidate[i] == candidate[i - 1]:
        del candidate[i]
        i -= 1
    i += 1

for i in candidate[K - 1]:
    print(i, end = "")
print()

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

n = len(s)
substring = []
for i in range(n):
    for j in range(i+1, min(n+1, i+k+1)):
        substring.append(s[i:j])

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

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

dic={}
for i in range(len(s)):
    dic[s[i:]]=1
arr=sorted(dic)
dic={}

for x in arr:
    for i in range(0,len(x)):
        tmp = x[:i+1]
        if dic.get(tmp,0)==0:
            K-=1
            dic[tmp]=1
        else:
            continue
        if K==0:
            print(x[:i+1])
            break
    if K<0:
        break

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

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

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

x = [[s[j:j+i+1] for j in range(len(s)-i)] for i in range(5 if len(s)>=5 else len(s))]

s_set = []
for i in x:
	s_set.extend(i)

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

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

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

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

t = sorted(list(t))
print(t[k])

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


def compare(a, b):
    ll = [a, b]
    ll = sorted(ll)
    return ll[0] == a


db = []
for length in range(1, k + 1):
    for start in range(l + 1 - length):
        candidate = s[start:start+length]
        if len(db) >= 5:
            if compare(candidate, db[-1]):
                if candidate not in db:
                    db.append(candidate)
                    db = sorted(db)
                    db = db[:5]
        else:
            if candidate not in db:
                db.append(candidate)
                db = sorted(db)

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

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

Solution (Python):


S = input()
k = int(input())
T = set()

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

T = list(T)
print(sorted(T)[k-1])

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

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

sub = []

for i in range(len(s)):
    for j in range(1,6):
        if s[i:i+j] not in sub:
            sub.append(s[i:i+j])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])

Solution (Python):
s = input()
K = int(input())
sub = []
for i in range(0,5):
    for j in range(0,len(s)-i):
        sub.append(s[j:j+i+1])
        
subset = set(sub)
sub2 = list(subset)

sub2.sort()

print(sub2[K-1])

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

alphabet = ["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"]

count = 0

for alp in alphabet:
    ss = []
    
    if alp in s:
        pos = [i for i, x in enumerate(s) if x == alp]
        
        for i in pos:
            for j in range(1,6):
                if i+j == len(s) + 1:
                    break
                else:
                    ss.append(s[i:i+j])
        ss = list(set(ss))
        ss.sort()
        
        if K - count <= len(ss):
            print(ss[K - count -1])
            break
        else:
            count += len(ss)

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

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

Solution (Python):
import string


def make_string(string, flag_matched=False, N=5000):
    if string[-1] == 'z':
        string = string[:-1]
        flag_matched = False
    if flag_matched == False or len(string) == N:
        string = string[:-1] + chr(ord(string[-1] )+1)
    else:
        string += 'a'
    return(string)


S = input()
k = int(input())

N = len(S)
if N <= 50:

    A = []

    for i in range(N):
        for j in range(1, N+1-i):
            A.append(S[i:i+j])

    A = list(set(A))
    A.sort()

    print(A[k-1])

else:

    c = 0
    q = 'a'

    while True:
        if q in S:
            c += 1
            if c == k:
                break
            else:
                q  = make_string(q, True, N)
        else:
            q  = make_string(q, False, N)

    print(q)

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

Solution (Python):
s = input()
k = int(input())
alphabets = sorted(set(list(s)))


res = set()

prefix = 0
while len(res)<k:
    
    res.add(alphabets[prefix])
    for i in range(len(s)):
        
        if s[i]==alphabets[prefix]:
            
            length = 2
            while length<=k:
                if i+length>len(s):
                    break
                res.add(s[i:i+length])
                length += 1
    prefix += 1

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

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

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


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

Solution (Python):
from collections import Counter
S = input()
K = int(input())
N = len(S)
d = []
for i in range(N):
  for j in range(i,min(i+5,N)):
    d.append(S[i:j+1])
print(sorted(Counter(d))[K-1])
quit()

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

D = []
m = []

chars = list(set(list(s)))
chars.sort()

for n in range(3):
    if chars != []:
        m.append(min(chars))
        chars = chars[1:]

m.reverse()

t = m.pop()
D.append(t)

while len(D) < K:
    p = re.compile(t + '[a-z]')
    ma = list(set(p.findall(s)))
    ma.sort()
    if ma == []:
        if D.index(t) < len(D)-1:
            t = D[D.index(t)+1]
        else:
            t = m.pop()
            D.append(t)
    else:
        D.append(ma[0])
        t = ma[0]

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

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def main():
    s = input()
    K = int(input())
    c = Counter(s)

    se = set()
    for k, v in sorted(c.items()):
        for i in range(len(s)):
            for n in range(1, 6):
                if s[i] == k and i + n <= len(s):
                    se.add(s[i:i+n])
        if len(se) > K:
            break

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

if __name__ == '__main__':
    main()

Solution (Python):

"""
Created on Tue Aug  7 23:57:38 2018

@author: Yuki
"""

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

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

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

length = len(s)
substring_list = []
for i in range(length):
    for j in range(1,k+1):
        substring_list.append(s[i:i+j])
result = list(set(substring_list))
result.sort()

print(result[k-1])

Solution (Python):

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

S = input()
K = int(input())
li = []
for i in range(len(S)):
	for j in range(1,6):
		li.append(S[i:i+j])

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

Solution (Python):
import numpy as np

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





dic = set()

for l in range(1, K+1):
    for i in range(len(s) - l + 1):
        substr = s[i:i+l]
        dic.add(substr)

lst = sorted(list(dic))

print(lst[K-1])

Solution (Python):
import sys

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

N = len(S)

if(K >= len(S)):
    ans_set = set()
    for i in range(len(S)):
        for j in range(1, K + 1):
            if(i + j > N):
                break
            ans_set.add(S[i:i + j])
    ans = sorted(list(ans_set))
    print(ans[K - 1])
    sys.exit()

alpha = [chr(i) for i in range(97, 97 + 26)]
min_dic = 25
ans_set = set()
for i in range(0, N):
    if(min_dic < alpha.index(S[i:i + 1])):
        continue
    else:
        min_dic = alpha.index(S[i:i + 1])

    for j in range(1, K + 1):
        if(i + j > N):
            break
        ans_set.add(S[i:i + j])

ans = sorted(list(ans_set))
print(ans[K - 1])

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

len_s = len(s)

sub_set = set()
for k in range(1,6):
    for i in range(len_s-k+1):
        sub_set.add(s[i:i+k])
        
sub_list = list(sub_set)
sub_list.sort()
print(sub_list[K-1])

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

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

Solution (Python):
def n_gram(s, n):
	return [s[i:i+n] for i in range(len(s)-n+1)]

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

subs = set()
for k_i in range(1, k+1):
	subs = subs | set(n_gram(s, k_i))
print(sorted(subs)[k-1])

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

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

Solution (Python):

s = input()
K = int(input())
n = len(s)
alpha = list("abcdefghijklmnopqrstuvwxyz")
ans = []
for al in alpha:
    if al in s:
        for i in range(n):
            if al == s[i]:
                for j in range(1,6):
                    if i+j <= n:
                        ans.append(s[i:i+j])
        ans = dict.fromkeys(ans)
        ans = list(ans.keys())
    if len(ans) >= 5:
        break

ans.sort()
try:
    ans.remove("")
except:
    pass
print(ans[K-1])

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

Solution (Python):
s = input()
N = int(input())
len_s = len(s)

sub_set = set()

for start in range(len_s):
    k = 1
    while k <= min(len_s-start, N):
        sub_set.add(s[start:start+k])
        k += 1
        

sub_list = list(sub_set)
sub_list.sort()

print(sub_list[N-1])

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

substr_set = set()

for i in range(1, K + 1) : 
    if i >= len(s) :
        substr_set.add(s)
    else :
        for j in range(len(s) - i + 1) :
            if s != '' :
                substr_set.add(s[j:j+i])
    
sublist = list(substr_set)

sublist.sort()


print(sublist[K - 1])

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

def solve(s,k):
    temp = []
    for i in range(len(s)):
        for j in range(i + 1, i + k + 1):
            if j <= len(s)+1:
                temp.append(s[i:j])
    temp = sorted(set(temp))
    ans = temp[k - 1]
    return ans

print(solve(s,k))

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)


def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))


def to_bin(x):
    return bin(x)[2:]



dp = None

def main():
    S = input()
    K = int(input())

    A = []
    for i in range(len(S)):
        for j in range(i+1, min(i+6, len(S)+1)):
            A.append(S[i:j])

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

main()

Solution (Python):


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

    a = set()

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

if __name__ == '__main__':
    main()