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 kth_substring(s: str, K: int) -> str:
    kth_word = ''     
    kth_word_len = 0  
    n = len(s)        

    
    while K > 0:
        
        d = set()
        
        
        prev_count = 0
        
        temp = ''
        for c in 'abcdefghijklmnopqrstuvwxyz':
            temp = kth_word + c
            
            
            
            for i in range(n):
                if s[i:].startswith(temp):
                    for j in range(i, n):
                        d.add(s[i:j+kth_word_len+1])
                        if len(d) >= K:
                            break
                if len(d) >= K:
                    break
            if len(d) >= K:
                break
            
            
            prev_count = len(d)

        
        
        
        K -= prev_count + 1
        kth_word = temp
    return kth_word


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

Solution (Python):
s = input()
K = int(input())
n = len(s)
A = []
for i in range(n):
    if n < K:
       for j in range(n-i): 
           A.append(s[i:j+i+1])
    else:
       for j in range(K):
           A.append(s[i:i+j+1])
B = set(A)
C = []
for i in B:
    C.append(i)
C.sort()
print(C[K-1])

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

sub = set()

for i in range(n):
  for j in range(5):
    sub.add(s[i:i+j+1])
print(sorted(sub)[k-1])

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

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

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

k_sub = []
for l in range(1,k+1):
  for i in range(len(s)):
    if i+l<=len(s):
      k_sub.append(s[i:i+l])
    else:
      break
k_sub = sorted(list(set(k_sub)))
print(k_sub[k-1])

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

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

l = []

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

l.sort()
m={l[0][0]}

for x in l:
    for i in range(len(x)):
        m.add(x[:i+1])
        if len(m)>=5:
            break
    if len(m)>=5:
        break

m=list(m)
m.sort()

print(m[K-1])

Solution (Python):
s=input()
K=int(input())
 
def rec(s):
    length=len(s)
    ret=set()
    for depth in range(length):
        string=s[depth]
        ret.add(string)
        for i in range(depth+1,depth+K):
            if i<length:
                string+=s[i]
                ret.add(string)
    return ret
  
ret=rec(s)
print(sorted(ret)[K-1])

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

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

Ans.sort()

L = []
for i in Ans:
  if i not in L:
    K -= 1
    if K == 0:
      print(i)
      exit()
    L.append(i)

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

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

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

res = set()
for i in range(len(S)):
  for j in range(5):
    res.add(S[i:i+j+1])
print(sorted(res)[N-1])

Solution (Python):
str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    for t in range(f + 1, f + 1 + int_k):
        pattern.add(str_s[f:t])
        result = sorted(set(result + list(pattern)))[:int_k]

print(result[-1])

Solution (Python):
from collections import deque
q = deque()
s = input()
k = int(input())
alpha = set(s)
alpha = sorted(alpha)
for i in range(len(s)):
    for a in alpha[:3]:
        if s[i] == a:
            for j in range(k+1):
                q.append(s[i:i+j])
setq = set(q)
setq = sorted(setq)
print(setq[k])

Solution (Python):
s=input()
k=int(input())
list=[]
if len(s)>=5:
    for i in range(1,6):
        for j in range(len(s)-i+1):
            list.append(s[j:j+i])
else:
    for i in range(1,len(s)+1):
        for j in range(len(s)-i+1):
            list.append(s[j:j+i])
list_set_sorted=sorted(set(list))
print(list_set_sorted[k-1])

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

Solution (Python):
def main():
    s = input()
    K = int(input())
    ranks = ["~"] * K
    for l in range(len(s)):
        for r in range(l+1, min(len(s)+1, l+6)):
            target = s[l:r]
            if target in ranks:
                continue
            if target < ranks[K-1]:
                ranks[K-1] = target
            for i in range(K-1, 0, -1):
                if ranks[i] < ranks[i-1]:
                    tmp = ranks[i]
                    ranks[i] = ranks[i-1]
                    ranks[i-1] = tmp
    print(ranks[K-1])


if __name__ == "__main__":
    main()

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

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

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

alphabet = [chr(i) for i in range(97,97+26)]
n1,n2,n3,n4,n5 = 0,0,0,0,0

while len(List) < K:
    for a in range(n1,26):
        if alphabet[a] in s:
            break
    if not alphabet[a] in List:
        List.append(alphabet[a])
    
    if len(List) >= K:
        continue

    num = s.index(alphabet[a])
    if num == len(s)-1:
        n1 = a+1
        continue

    for b in range(n2,26):
        sumple1 = alphabet[a] + alphabet[b]
        if sumple1 in s:
            break
    if not sumple1 in List:
        List.append(sumple1)

    if len(List) >= K:
        continue

    if not sumple1 in s:
        n1 += 1
        n2,n3,n4,n5 = 0,0,0,0
        continue
        
    num = s.index(sumple1)
    if num == len(s)-2:
        n2 = b+1
        continue

    for c in range(n3,26):
        sumple2 = sumple1 + alphabet[c]
        if sumple2 in s:
            List.append(sumple2)
            break

    if len(List) >= K:
        continue
    
    if not sumple2 in s:
        n1 += 1
        n2,n3,n4,n5 = 0,0,0,0
        continue
    
    num = s.index(sumple2)
    if num == len(s)-3:
        n3 = c+1
        continue

    for d in range(n4,26):
        sumple3 = sumple2 + alphabet[d]
        if sumple3 in s:
            List.append(sumple3)
            break

    if len(List) >= K:
        continue
        
    num = s.index(sumple3)
    if num == len(s)-4:
        n4 = d+1
        continue

    for e in range(n5,26):
        sumple4 = sumple3 + alphabet[e]
        if sumple4 in s:
            List.append(sumple4)
            break

    if len(List) >= K:
        continue
        
answer = List[K-1]

print(answer)

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

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

Solution (Python):
import sys
 
 
def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(list(set(sub)))
  print(sub[K-1])
 
 
if __name__ == '__main__':
  main()

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

ss = []
m = min(len(s), k)
for i in range(len(s)):
    for j in range(1, m+1):
        if i+j > len(s):
            continue
        ss.append(s[i: i+j])
ss = sorted(list(set(ss)))
print(ss[k-1])

Solution (Python):

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

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

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

ss = []
for i in range(len(s)):
    for j in range(i+1, i+k+1):
        if s[i:j] not in ss:
            ss.append(s[i:j])
ss = sorted(ss)
print(ss[k-1])

Solution (Python):
import sys


def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(list(set(sub)))
  print(sub[K-1])


if __name__ == '__main__':
  main()

Solution (Python):


import copy
import numpy as np
import random


s = list(str(input()))
k = int(input())

substrings = []
for length in range(1,len(s)+1):
    if length > 5:
        break
    for i in range(len(s)-length+1):
        word = "".join(s[i:i+length])
        
        if word in substrings:
            pass
        else:
            substrings.append(str(word))

substrings.sort()

print(substrings[k-1])

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

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

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

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

check = []
a = min(len(s),k)
for i in range(len(s)):
    for j in range(a):
        if i <= i+j <=len(s)+1:
            check.append(s[i:i+j+1])
            
print(sorted(set(check))[k-1])

Solution (Python):

import sys
import itertools



def solve(lines):
    S = lines.pop(0)
    K = int(lines.pop(0))
    n = 0
    skip = []
    res = []
    while K > 0:
        min_idx = 0
        min_str = "z"
        for i,x in enumerate(S):
            if i in skip:
                continue
            if min_str > x:
                min_str = x
                min_idx = i
            elif min_str == x:
                l = len(S[i:])
                if S[min_idx:min_idx+l] > S[i:]:
                    min_str = x
                    min_idx = i
                elif S[min_idx:min_idx+l] == S[i:]:
                    skip.append(i)
        skip.append(min_idx)
        res = S[min_idx:]
        if len(res) >= K:
            print(res[:K])
            sys.exit(0)
        else:
            K -= len(res)
    sys.exit(1)






lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

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

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

Solution (Python):
S = input()
K = int(input())
a = list(set(S))
a.sort()

k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1,6):
                if i+j <= len(S):
                    k.append(S[i:i+j])
                else:
                    break
    l += 1

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

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

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

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

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

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

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

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

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

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

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

sub_str = []
for i in range(len(s)):
    for j in range(k+1):
        if i +1  <= i + j <= len(s):
            sub_str.append(s[i:i+j])

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

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

check = []
for i in range(len(s)):
    for j in range(k+1):
        if i +1  <= i + j <= len(s):
            check.append(s[i:i+j])

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

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

k = set(k)
k = list(k)
k.sort()

print(k[p-1])

Solution (Python):
s=input()
k=int(input())
s_list=[]
for p in range(len(s)):
    for q in range(min(5,len(s[p:]))):
        if(not(s_list.__contains__(s[p:p+q+1]))):
                s_list.append(s[p:p+q+1])
s_list_sort=sorted(s_list)
print(s_list_sort[k-1])

Solution (Python):
strn=input()
K = int(input())
wordindex=[]
minindex=list(set(strn))
minindex.sort()
def IndexPoint(index,word):
    return [i for i,x in enumerate(index) if x == word]
while len(wordindex) < K:
    for m in minindex:
        point = IndexPoint(strn,m)
        for p in point:
            tmp = ""
            for i in range(p,min(len(strn),p+K+1)):
                tmp += strn[i]
                wordindex.append(tmp)
wordindex = list(set(wordindex))
wordindex.sort()
print(wordindex[K-1])

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])
print(sorted(set(L))[K-1])

Solution (Python):
def solve(s, K):
    import heapq
    import re

    seen = set(s)
    pq = list(seen)
    heapq.heapify(pq)

    while True:
        t = heapq.heappop(pq)
        K -= 1
        if K==0:
            return t
        pattern = t + "."

        matched = re.findall(pattern, s)
        for sub in matched:
            if sub not in seen:
                seen.add(sub)
                heapq.heappush(pq, sub)


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


main()

Solution (Python):

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

cand = []
for l in range(1, K+1):
    for i in range(len(S) - l + 1):
        cand.append(S[i:i+l])

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

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

Solution (Python):


from collections import defaultdict

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

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

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        if len(S)-j+1 >= K:
            for l in range(1, K+1):
                cand.append(S[j:j+l])
        else:
            for l in range(1, len(S)-j+1):
                cand.append(S[j:j+l])
    cand = list(set(cand))
    if len(cand) >= K:
        break
    i += 1
cand = sorted(cand)
print(cand[K-1])

Solution (Python):
a0 = list(input())
k = int(input())
a = a0+['O', 'O', 'O', 'O']
b = sorted(set(a0))[:3]
A = set()

for w in b:
    for i, x in enumerate(a0):
        if x == w:
            for m in range(1, 6):
                A.add(tuple([a[i+k] for k in range(m)]+['O']*(6-m)))

A = sorted(A)
j = A[k-1].index('O')
ans = list(A[k-1])[:j]
print(''.join(ans))

Solution (Python):


















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


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

dic = set()

for i in range(len(s)):
  for j in range(1, 6):
    if len(s[i:i+j])>0:
      dic.add(s[i:i+j])

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

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

Solution (Python):
def main():
    s = input()
    K = int(input())
    sk = []
    for i in range(len(s)):
        for j in range(1, K + 1):
            ss = s[i:i + j]
            if ss not in sk:
                sk.append(ss)
    print(sorted(sk)[K - 1])


main()

Solution (Python):
S = list(raw_input())

K = input()

data = []
for i in range(len(S)):
    for j in range(1,K+1):
        if i+j <= len(S):
            sample = ''
            counter = 1
            while counter <= j:
                sample += S[i+counter-1]
                counter += 1
            if sample not in data:
                data.append(sample)
        else:
            break

data.sort()

print data[K-1]

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

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    
chars=chars|subset(s[max(l-10,0):],0)
for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)



'''
for i in range(l):
    n=i+1 
    for j in range(l-i):
        chars.add(s[j:j+n])
        
'''

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

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

d = {}
for i in range(len(S)):
    for j in range(i+1,i+K+1):
        s = S[i:j]
        if s in d.keys():
            pass
        else:
            d[s] = 0

d = sorted(d.keys())
print(d[K-1])

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

Solution (Python):
s = list(input())
k = int(input())
l = [[i] for i in range(len(s))]
a = [''.join([s[i] for i in x]) for x in l]
for _ in range(k):
    m = min(a)
    for i,x in enumerate(a):
        if x==m and l[i][-1]+1<len(s):
            l[i].append(l[i][-1]+1)
        elif x==m:
            l.pop(i)
    a = [''.join([s[i] for i in x]) for x in l]
print(m)

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

Ans = []
for k in range(5):
    for i in range(len(S)-k):
        s = S[i:i+k+1]
        if s not in Ans:
            Ans.append(s)

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

Solution (Python):
s = input()
K = int(input())
substring = set()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for alp in alphabet:
    st = s[:]
    if len(substring) >= 5:
        break
    i = st.find(alp)
    while i > -1:
        for j in range(5):
            substring.add(st[i:i+j+1])
        st = st[i+1:]
        i = st.find(alp)
print(sorted(substring)[K-1])

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

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

Solution (Python):
import string, heapq

def solve():
    s = input()
    s_len = len(s)
    k = int(input())
    alpha = string.ascii_lowercase
    subs = []
    for a in alpha:
        a_indexs = [i for i, x in enumerate(s) if x == a]
        for index in a_indexs:
            for i in range(index, min(index+5, s_len)):
                sub = s[index:i+1]
                if sub in subs:
                    continue
                else: 
                    heapq.heappush(subs, s[index:i+1])                
        if len(subs) >= k:
            break
    for i in range(k-1):
        heapq.heappop(subs)
    print(heapq.heappop(subs))

if __name__ == "__main__":
    solve()

Solution (Python):
s=input()
K=int(input())
substring=set()
for start in range(len(s)):
    for end in range(start+1,min(len(s)+1,start+K+1)):
        substring.add(s[start:end])
print(sorted(list(substring))[K-1])

Solution (Python):
s=input()
K=int(input())
substring=set()
for start in range(len(s)):
    for end in range(start+1,min(len(s)+1,start+K+1)):
        substring.add(s[start:end])
print(sorted(list(substring))[K-1])

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



sub = {s[i:j] for i in range(len(s)) for j in range(i+1,i+K+1)}
sub = sorted(sub)
print(sub[K-1])

Solution (Python):
S = input()
k = int(input())
A = []

for i in range(len(S)):
    for j in range(i + 1, i + 1 + k):
        A.append(S[i : j])
    
sortA = sorted(list(set(A)))
print(sortA[k - 1])

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

Solution (Python):
from collections import Counter

def ngram(text, n):
    return [text[i:i+n] for i in range(len(text) - n + 1)]

text = input()
k = int(input())
candidates = set()
for n in range(1,6):
    
    candidates |= set(ngram(text,n))

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

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

def main(s, k):
    tmp = set()
    for i in range(1, 6):
        tmp = tmp | n_gram(s, i)
    substr = sorted(list(tmp))
    print(substr[k-1])

if __name__ == '__main__':
    main(input(), int(input()))

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

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

for i in range(len(s)+1):
    for j in range(i+1,i+K+1):
        if j >len(s):
                break
        else:
                substring.append(s[i:j])

setsubstring = list(set(substring))
setsubstring.sort()

print(setsubstring[K-1])

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

Solution (Python):


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

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):
s = input()
K = int(input())
N = len(s)
ans = []

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

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

Solution (Python):
S = input()
k = int(input())
A = []

for i in range(len(S)):
    for j in range(i+1, i+k+1):
        A.append(S[i : j])
        
ans  = sorted(list(set(A)))
print(ans[k-1])

Solution (Python):
s = input()
k = int(input())
c = len(s)
d = 0
a = []
d = min(c,5)
for i in range(d):
  b = [s[j:i+j+1] for j in range(c-i)]
  b = list(set(b))
  a = a + b
a.sort()
print(a[k-1])

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

l=list(s)

import collections
c=collections.Counter(l)
li=c.most_common()
from operator import itemgetter
li.sort(key=itemgetter(0))

co=0
p=[]
for i in range(min(5,len(li))):
    for j in range(len(s)):
        if l[j]==li[i][0]:
            for e in range(min(len(s)-j,k)):
                co+=1
                p.append(s[j:j+e+1])

q=collections.Counter(p)
ans=q.most_common()
ans.sort(key=itemgetter(0))   

print(ans[k-1][0])

Solution (Python):
s = input()
k = int(input())
subs = []

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

print(list_subs[k - 1])

Solution (Python):
s = input()
k = int(input())
subs = []

for i in range(len(s)):
    for j in range(k):
        subs.append(s[i:i+j+1])

subs = sorted(list(set(subs)))
print(subs[k-1])

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

for i in range(len(S)):
  for j in range(K):
    ans.append(S[i:i+j+1])
  
ans = list(set(ans))
ans.sort()

print(ans[K-1])

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

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

Solution (Python):
S = input()
k = int(input())
A = []

for i in range(len(S)):
    for j in range(1, k + 1):
        A.append(S[i : i + j])
        
ans = sorted(list(set(A)))
print(ans[k - 1])

Solution (Python):
s = input()
k = int(input())
arr =[]
for i in range(len(s)):
    for j in range(i,i+5):
        if s[i:j+1] != '' and s[i:j+1] not in arr:
            arr.append(s[i:j+1])
arr = sorted(arr)
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep="",end="/")
    print()   
print(arr[k-1])

Solution (Python):
s = str(input())
K = int(input())
S = set()
anslength = K
while 0 < anslength:
    for i in range(0,len(s)-anslength+1):
        S.add(s[i:i+anslength])
    anslength-=1
LS = list(S)
LS.sort()
print(LS[K-1])

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

sub_list=[]

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

sub_set=set(sub_list)
sub_dict=sorted(sub_set,key=str)

print(sub_dict[K-1])

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

sub_list=[]
i,j=0,1
while True:
    if(i+j>=len(s) and i==len(s)):
        break
    else:
        sub_list.append(s[i:i+j])
        if(j<=K):
            j+=1
        else:
            i+=1
            j=1
set_list=set(sub_list)

dict_list=list(set_list)
dict_list.sort(key=str)

print(dict_list[K-1])

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

c = []


for i in range(len(s)):
    for k in range(1,m+1):
        c.append(s[i:i+k])

b = sorted(list(set(c)))


print(b[m-1])

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

l = sorted(set(list(s)))
r = []
for first in l[:min(len(l),k)]:
    
    for i in range(len(s)):
        if s[i]==first:
            for j in range(1,6):
                r.append(s[i:i+j])
r = sorted(set(r))
print(r[k-1])

Solution (Python):
def main():
    s = input()
    k = int(input())
    ss = set(s)
    for i in range(0, len(s)):
        ss.add(s[i:i + 2])
        ss.add(s[i:i + 3])
        ss.add(s[i:i + 4])
        ss.add(s[i:i + 5])
    print(sorted(iter(ss))[k - 1])


if __name__ == '__main__':
    main()

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

dic = []

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

dic = (list)(set(dic))
dic.sort()


print(dic[k-1])

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

Solution (Python):
s = input()
k = int(input())
c = len(s)
d = 0
a = []
if c < 5:
  d = c
else:
  d = 5
for i in range(d):
  b = [s[j:i+j+1] for j in range(c-i)]
  b = list(set(b))
  a = a + b
a.sort()
print(a[k-1])

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

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

Solution (Python):
a = input()
b = int(input())
ar = set(list(a))
arr = sorted(ar)
br = []
for i in range(len(a)):
    if a[i] == arr[0]:
        try:
            for j in range(1,b+1):
                br.append(a[i:i+j])
        except indexError:
            break
cr = set(br)
if len(cr) < b:
    for i in range(len(a)):
        if a[i] == arr[1]:
            try:
                for j in range(1,b+1):
                    br.append(a[i:i+j])
            except indexError:
                break
dr = set(br)
er = sorted(dr)
print(er[b-1])

Solution (Python):
s = input()
k = int(input())
subset = []

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

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

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

Solution (Python):

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

N = len(s)
num = N * (N + 1) // 2

stat = [1] * N
for i in range(K):
    head = "z" * 5001
    j_head = -1
    
    for j in range(N):
        if j + stat[j] > N: continue
        if s[j : j + stat[j]] < head:
            head = s[j : j + stat[j]]
            j_head = j
    
    for j in range(N):
        if j + stat[j] > N: continue
        if s[j : j + stat[j]] == head: stat[j] += 1

print(head)

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

se = set([])
for i in range(N):
    for k in range(5):
        s = S[i:i+k+1]
        se.add(s)
l = sorted(list(se))
ans = l[K - 1]
print(ans)

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

n = len(s)

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

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

arr = []

for i in range(len(s)):
    for j in range(i,i+5):
        arr += [''.join(s[i:j+1])]

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

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


sub_string=[]
for i in range(len(s)):
  for j in range(1,k+1):
    string = s[i:i+j]
    if string not in sub_string:
      sub_string.append(string)
sub_string.sort()
print(sub_string[k-1])