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):
import sys

input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


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

    N = len(s)
    total = 0
    for al in AL:
        induces = []
        for i in range(N):
            if al == s[i]:
                induces.append(i)
        if not induces:
            continue
        match = [al]
        for i in range(1, 5):
            for idx in induces:
                if idx + i < N:
                    match.append(s[idx:idx + i + 1])
        match = set(match)
        match = sorted(match)
        if total + len(match) >= K:
            ans = match[K - 1 - total]
            break
        else:
            total += len(match)
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

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

a = []
for i in range(n):
    for j in range(i+1,n+1):
        if j - i > k:break
        a.append(s[i:j])
b = sorted(set(a))
print(b[k-1])

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


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

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter
s = input()
k = int(input())
n = len(s)
bb = Counter(s)
b = list(bb)
b.sort()
a = set([])

for l in range(k):
    for i in range(n):
        if s[i] == b[l]:
            for j in range(5):
                if i + j > n:
                    break
                a.add(s[i:i+1+j])
    if len(a) >= k:
        break
        
b = list(a)
b.sort()
print(b[k-1])

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

ss = sorted(s)
uego = list(set([ss[i] for i in range(len(ss))][:5]))

la = []
for i in range(len(s)):
  if s[i] in uego:
    for j in range(5):
      if i+j >= len(s):
        break
      la.append(s[i:i+j+1])
la = list(set(la))
la.sort()
print(la[K-1])

Solution (Python):
s = str(input())
k = int(input())
lis = []
for u in range(6):
	for i in range(len(s)):
		try:
			if s[i:i+u] == "":
				continue
			if s[i:i+u] not in lis:
				lis.append(s[i:i+u])
		except:
			continue
lis.sort()
print(lis[k-1])

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

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

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

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

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

Solution (Python):
s = input()
k = int(input())
n = len(s)
rank = ["zzzzzz"]*k
for i in range(n):
  for j in range(i+1, min([i+k+1, n+1])):
    key = s[i:j]
    for r in range(k):
      if key == rank[r]:
        break
      if key < rank[r]:
        for r2 in range(r, k):
          key2 = rank[r2]
          rank[r2] = key
          key = key2
        break
print(rank[k-1])

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

Solution (Python):
s=input();k=int(input());q=[]
for i in range(len(s)):
 for j in range(k):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k]
print(q[-1])

Solution (Python):
s,k=open(0);k=int(k);q=[];N=len(s)
for i in range(N):
 for j in range(min(k,N-1-i)):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k]
print(q[-1])

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


def ins(x):
    if len(smallests) == k and x > smallests[-1]:
        return
    if x in smallests:
        return
    smallests.append(x)
    smallests.sort()
    while len(smallests) > k:
        smallests.pop()


def solve():
    for i in range(len(s)):
        for size in range(1, k + 1):
            if i + size > len(s):
                break
            ins(s[i : i + size])
    return smallests[-1]


print(solve())

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

lst = []
for i in range(n):
	for j in range(1, 6):
		tmp = s[i:i+j]
		lst.append(tmp)

lst = list(set(lst))
lst.sort()

print(lst[k-1])

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()
K=int(input())
ans = []

from collections import defaultdict
dic = defaultdict(list)
for i in range(len(S)):
  dic[S[i]].append(i)

sortedS = sorted(dic.items(),key = lambda x:x[0])



ans = set()
for candi in sortedS:
  ch,inds = candi[0],candi[1]

  for i in inds:
    for j in range(K):
      ans.add(S[i:i+j+1])
  if len(ans) >= K:
    break
      
print(sorted(list(ans))[K-1])

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

N = len(S)
Q = set()
for i in range(N):
    Q.add(S[i])
    if i<N-1:Q.add(S[i:i+2])
    if i<N-2:Q.add(S[i:i+3])
    if i<N-3:Q.add(S[i:i+4])
    if i<N-4:Q.add(S[i:i+5])
Q = sorted(list(Q))
print(Q[K-1])

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Solution (Python):
s = input()
K = int(input())
ls = len(s)
aset = set()

for i in range(ls):
    for k in range(1, K+1):
        if i+k <= ls:
            aset.add(s[i:i+k])

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

Solution (Python):



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


def main():
    n = len(s)
    alpha = [chr(i) for i in range(97, 97+26)]
    d = {x: [] for x in alpha}
    for i in range(n):
        d[s[i]].append(i)

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


if __name__ == "__main__":
    main()

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

cnt = 0
tmp = 0
lst = []
tmp_s = "zzz"

if(len(s)>= 5):
    for i in range(len(s)-4):
        if(tmp_s >= s[i:(i+5)]):
            tmp_s = s[i:(i+5)]

    for j in range(len(tmp_s)):
        for k in range(j+1, len(tmp_s)+1):
            if(tmp_s[j:k] not in lst):
                lst.append(tmp_s[j:k])
        
    lst.sort()
    print(lst[K-1])
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            if(s[i:j] not in lst):
                lst.append(s[i:j])
    lst.sort()
    print(lst[K-1])

Solution (Python):
s = input()
li = list(s)
k = int(input())
tmp = []
for i,l in enumerate(li):
    for kk in range(k):
        
        if i+kk <= len(li):
            tmp.append(''.join(li[i:i+1+kk]))

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

Solution (Python):

import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

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

if __name__ == '__main__':
    main()

Solution (Python):
def resolve():

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

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

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


resolve()

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = Scanner.string()
    k = Scanner.int()
    N = len(S)
    M = set()
    for i in range(N):
        for j in range(k):
            M.add(S[i: i + j + 1])
    M = sorted(list(M))
    print(M[k - 1])


def main():
    
    solve()


if __name__ == "__main__":
    main()

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

n = len(s)
sub = set()

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

sub = sorted(list(sub))

print(sub[k-1])

Solution (Python):
s = input()
K = int(input())
D = {}
n = len(s)
for i in range(K):
  for j in range(n-i):
    D[s[j:j+i+1]] = 1
L = [i for i in D]
L.sort()
print(L[K-1])

Solution (Python):
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()

s=list(input())
K=int(input())
N=len(s)
lst=[]
lstset=set()
for i in range(N):
    for m in range(i+1,min(N+1,i+6)):
        c="".join(s[i:m])
        if not c in lstset:
            lst.append(c)
            lstset.add(c)
lst.sort()
print(lst[K-1])

Solution (Python):


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

st = set()
for start in range(len(s)):
    for len_ in range(1, k + 1):
        st.add(s[start:start + len_])
*a, = sorted(st)
print(a[k - 1])

Solution (Python):



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

if __name__=='__main__':
  main()

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

substring_list = []
for i in range(1, 5+1):
    for start in range(len(s) - i + 1):
        substring_list.append(s[start:start+i])


substring_list = sorted(set(substring_list))
print(substring_list[k-1])

Solution (Python):

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

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

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

st=set()
s_len=len(s)

length=1
while length<=min(s_len,k):
  for i in range(s_len-length+1):
    sub_s=s[i:i+length]
    st.add(sub_s)
  length+=1

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

Solution (Python):
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k-1])

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

sublst=[sorted(list(set([s[i] for i in range(n)])))]
ret=[]

def dfs(l,i):
    if len(sublst)<l+1 and n-l>0:
        sublst.append(sorted(list(set([s[i:i+l+1] for i in range(n-l)]))))
    
    ret.append(sublst[l-1][i])

    if len(ret)>=k:
        return
    
    if l<=n-1:
        for j in range(len(sublst[l])):
            if sublst[l][j][:-1]==sublst[l-1][i]:
                dfs(l+1,j)
    
    if l==1 and len(sublst[0])>i+1:
        dfs(1,i+1)

dfs(1,0)

print(ret[k-1])

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

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

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



S = sys.stdin.buffer.readline().decode().rstrip()
K = int(sys.stdin.buffer.readline())

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

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

subs = []

for i in range(0,K + 1):
  for j in range(0,len(s) - i):
    sub = s[j:j + i + 1]
    subs.append(sub)
    
subs = sorted(list(set(subs)))

print(subs[K - 1])

Solution (Python):
s = input()
k = int(input())
li = []
l = 0
r = min(len(s), 5)

while l != r:
    s1 = s[l:r]
    for i in range(1,len(s1)+1):
        s2 = s1[:i]
        li.append(s2)

    if r < len(s):
        r += 1
    l += 1

li = list(set(li))
li.sort()

print(li[k-1])

Solution (Python):
from collections import Counter
s = str(input())
K = int(input())
st = set()
for l in range(1,K+1):
    for i in range(len(s)-l+1):
        st.add(s[i:i+l])
print(sorted(list(st))[K-1])

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

Solution (Python):

s = input()
K = int(input())
st = set()
for i in range(5):
    for j in range(len(s)-i):
        st.add(s[j:j+i+1])
ls = list(st)
print (sorted(ls)[K-1])

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    
    S = Scanner.string()
    K = Scanner.int()
    m = []
    N = len(S)
    for i in range(N):
        for j in range(i, min(i+K, N)):
            m.append(S[i: j + 1])
    m = sorted(set(m))
    print(m[K-1])


if __name__ == "__main__":
    main()

Solution (Python):
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def slv(S, K):
    d = set([])
    for i in range(len(S)):
        for j in range(i + 1, i + 1 + K):
            d.add(S[i:j])

    return sorted(d)[K - 1]


def main():
    S = read_str()
    K = read_int()
    
    
    print(slv(S, K))


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
k=int(input())
n=len(s)
ans=dict()
for i in range(n):
  t=str()
  for j in range(min(5,n-i)):
    t+=s[i+j]
    ans[t]=0
ans=sorted(list(ans.keys()))
print(ans[k-1])

Solution (Python):
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor


"""
need to consider the case that ticket is not enough to lower everything
"""

s = gw()
K = gi()
ss = set()

for i in range(len(s)):
    for k in range(1, K + 1):
        if i + k > len(s):
            break
        ss.add(s[i:i + k])

sl = []
for st in ss:
    sl.append(st)
sl.sort()
print(sl[K - 1])

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

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

l = list(s)
l.sort()

print(l[K-1])

Solution (Python):


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



seta = set()

for i in range(len(s)):
    for j in range(1,6):
        seta.add(s[i:i+j])
        
lista = sorted(list(seta))



print(lista[K-1])

Solution (Python):
s,k=open(0)
n=len(s)-1
k=int(k)
t=set()
for a in s[:n]:
  t.add(a)
for a,b in zip(s,s[1:n]):
  t.add(a+b)
for a,b,c in zip(s,s[1:],s[2:n]):
  t.add(a+b+c)
for a,b,c,d in zip(s,s[1:],s[2:],s[3:n]):
  t.add(a+b+c+d)
for a,b,c,d,e in zip(s,s[1:],s[2:],s[3:],s[4:n]):
  t.add(a+b+c+d+e)
print(sorted(t)[k-1])

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

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

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

Solution (Python):
s = list(input())
n = len(s)
k = int(input())
if k > n:
    K = n
else:
    K = k
anset = set()
for lenght in range(1,K+1):
    for i in range(n - lenght + 1):
        anset.add("".join(s[i:i+lenght]))
anset = list(anset)
anset.sort()
print(anset[k-1])

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

D = {c:[] for c in "abcdefghijklmnopqrstuvwxyz"}
for i,c in enumerate(s):
    D[c].append(i)

ans = []
for I in D.values():
    t = []
    for l in range(1,K+1):
        for i in I:
            if i+l < len(s)+1:
                t.append(s[i:i+l])
    ans += sorted(list(set(t)))
    if len(ans)>=K:
        break
print(ans[K-1])

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


D={}

if(len(s)<=1):
    for i in range(1,len(s)+1):
        for j in range(len(s)):
            if D.get(s[j:j+i],None) == None:
                D[s[j:j+i]]=1
    D=sorted(D)
    print(D[N-1])
    exit()
else:
    t=sorted(s)
    i=0
    k=0
    for c in t:
        if(c!=k):
            i=0
            if(len(D)>=5):
                break
        k=c
        while(i<len(s)):
            if(s[i]==c):
                break
            i+=1
        j=i+1
        while(j<=min(len(s),i+5)):
            D[s[i:j]]=1
            j+=1
        i+=1
    
    D=sorted(D)
    print(D[N-1])
    exit()

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

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

print(ans[K])

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    al = [chr(i) for i in range(97, 97 + 26)]
    s = str(readline().rstrip().decode('utf-8'))
    k = int(readline())
    ans = collections.defaultdict(int)
    for alv in al:
        for i, v in enumerate(s):
            if alv == v:
                for j in range(i + 1, i + k + 1):
                    ans[s[i:j]]
        if len(ans) > k:
            break
    print(sorted(ans.items())[k-1][0])


if __name__ == '__main__':
    solve()

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

S=[]
for n in range(len(s)):
    for i in range(1,len(s)-n+1):
        if len(S)<5:
            S.append(s[n:i+n])
            S = list(set(S))
            S.sort()
        elif S[4]>s[n:i+n]:
            S.append(s[n:i+n])
            S = list(set(S))
            S.sort()
        else:
            break
S=list(set(S))
S.sort()

print(S[K-1])

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

Solution (Python):


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

dp=[[[[[0]*27 for i in range(27)] for i in range(27)] for i in range(27)] for i in range(27)]

for i in range(len(s)):
    for j in range(5):
        temp=list(map(lambda x:ord(x)-96,s[i:i+j+1]))+[0,0,0,0,0]
        
        dp[temp[0]][temp[1]][temp[2]][temp[3]][temp[4]]=1
        
    

for a in range(len(dp)):
    for b in range(len(dp[a])):
        for c in range(len(dp[a][b])):
            for d in range(len(dp[a][b][c])):
                for e in range(len(dp[a][b][c][d])):
                    if dp[a][b][c][d][e]==1:
                        if K==1:
                            print(chr(a+96 if a!=0 else 0)+(chr(b+96) if b!=0 else "")+(chr(c+96) if c!=0 else "")+(chr(d+96) if d!=0 else "")+(chr(e+96) if e!=0 else ""))
                            exit()
                        else:
                            K-=1

Solution (Python):
s = list(input())
n = len(s)
k = int(input())
if k > n:
    K = n
else:
    K = k
anset = set()
for lenght in range(1,K+1):
    for i in range(n - lenght + 1):
        anset.add("".join(s[i:i+lenght]))
anset = list(anset)
anset.sort()
print(anset[k-1])

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

for i in range(5):
    for j in range(n-i):
        ls.add(s[j:j+i+1])

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

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

Solution (Python):
def main():
    s=input()
    m=int(input())
    tank=[]
    n=len(s)
    alpha=[chr(i) for i in range(97, 97+26)]
    for i in range(26):
        for j in range(n):
            if alpha[i]==s[j]:
                for k in range(min(n-j,m)):
                    if s[j:j+k+1] not in tank:
                        tank.append(s[j:j+k+1])
        if len(tank)>=m:
            break
    tank.sort()
    print(tank[m-1])
    
if __name__ == "__main__":
    main()

Solution (Python):

import sys

M = 'zzzzzz'

def dfs(s, K, N, r, a, ss):
    m = a[r]
    for i in range(N):
        if s[i] == m:
            t = ''
            for j in range(i, min(i+K, N)):
                t += s[j]
                if t in ss:
                    continue
                if t >= ss[-1]:
                    break
                ss.pop()
                ss.append(t)
                list.sort(ss)
    if ss[-1] == M:
        return dfs(s, K, N, r+1, a, ss)
    return ss[-1]


def solve(s: str, K: int):
    ss = [M] * K
    a = sorted(list(set(s)))
    N = len(s)
    return dfs(s, K, N, 0, a, ss)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)
    K = int(next(tokens))
    print(solve(s, K))

if __name__ == '__main__':
    main()

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

if K==1:
  print(sorted(S)[0])
  exit()

ans=[]
if K<=len(S):
  s0=sorted(S[:-K+1])[0]
  for j,e in enumerate(S[:-K+1]):
    if e==s0:
      for i in range(1,K+1):
        a="".join(S[j:j+i])
        if a not in ans:
          ans.append(a)
      
sl=S[-K+1:]
for i in range(K-1):
  for j in range(i+1,K):
    a="".join(sl[i:j])
    if a not in ans:
      ans.append(a)

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

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

Solution (Python):
s=input()
k=int(input())
uselist=[]
count=0
checker=0
alphabet="abcdefghijklmnopqrstuvwxyz"
while count<=5 and checker<=26:
    for i in alphabet:
        for j in range(len(s)):
            if s[j]==i:
                uselist.append((j,i))
                count+=1
        checker+=1
anslist=[]
for some in uselist:
    count=0
    for j in range(some[0],len(s)):
        anslist.append(s[some[0]:j+1:])
        count+=1
        if count>5:
            break
            
anslist=sorted(set(anslist))

print(anslist[k-1])

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines























def main():
    s=input().rstrip().decode('utf-8')
    n=len(s)
    se0=set()
    t=sorted(s)
    for i in range(5):
        try:
            se0.add(t[i])
        except:
            pass
    se=se0
    for i in range(2,6):
        for j in range(n-i+1):
            try:
                if s[j] in se0:
                    se.add(s[j:j+i])
            except:
                pass
    li=sorted(list(se))
    k=int(input())
    print(li[k-1])


if __name__ == '__main__':
    main()

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

a = list()

ch = 0
cn = 0
for i in range(1,27):
    b = set()
    for j in range(len(s)):
        if(ord(s[j])==(i+96)):
            for m in range(j,j+k):
                
                b.add(s[j:m+1])
                cn += 1
                

    a.append(list(b))
    

for i in range(26):
    a[i].sort()
    
cn = 0
for i in range(26):
    if(len(a[i])+cn>=k):
        for j in range(len(a[i])):
            cn += 1
            if(cn == k):
                print(a[i][j])
    else:
        cn += len(a[i])

Solution (Python):
s = input()
K = int(input())
n1 = list(s)
n2 = [s[i:i+2] for i in range(len(s)-1)]
n3 = [s[i:i+3] for i in range(len(s)-2)]
n4 = [s[i:i+4] for i in range(len(s)-3)]
n5 = [s[i:i+5] for i in range(len(s)-4)]
cat = list(set(n1 + n2 + n3 + n4 + n5))
cat.sort()

print(cat[K-1])

Solution (Python):
def main():
    s = str(input())
    s += '0'
    k = int(input())
    result = set()
    for i in range(1, 6):
        for j in range(len(s)-i):
            result.add(s[j:j+i])
    out = list(result)
    out.sort()
    print(out[k-1])
if __name__ =='__main__':
    main()

Solution (Python):
s = input()
k = int(input())
subs = []
lens = len(s)
prev = ''
cnt = 0

for i in range(lens):
  for j in range(1,k+1):
    subs.append(s[i:i+j])
subs.sort()
for m in subs:
  if prev != m:
    cnt += 1
  if cnt == k:
    print(m)
    exit()
  prev = m

Solution (Python):
from collections import defaultdict
s=input()
k=int(input())
n=len(s)
l=defaultdict(int)
for i in range(n):
  for j in range(min(5,n),0,-1):
    l[s[i:i+j]]+=1
print(sorted(l)[k-1])