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):
from collections import defaultdict
import string
s = input()
K = int(input())
location = defaultdict(list)
for i, s_i in enumerate(s):
    location[s_i].append(i)
count = 0
s_list = []
for c in string.ascii_lowercase[:26]:
    if location[c] == []:
        continue
    for idx in location[c]:
        for i in range(K):
            if idx + i + 1 > len(s):
                break
            if s[idx:idx+i+1] in s_list:
                continue
            s_list.append(s[idx:idx+i+1])
    count += 1
    if count == K:
        break
s_list.sort()
print(s_list[K-1])

Solution (Python):

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


case = []
append = case.append
for i in range(1, K + 1):
    for idx in range(0, len(s) - (i - 1)):
        if s[idx:idx + i] not in case:
            append(s[idx:idx + i])
case.sort(reverse=True)

print(case[-K])

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

Solution (Python):
S = input()
N = len(S)
K = int(input())
cnt = {i: [] for i in range(N)}
for i in range(N):
    for j in range(N - i):
        s = S[j:j+i+1]
        l = len(s)
        if s not in cnt[l-1]:
            cnt[l-1].append(s)
    if i > K:
        break
ttl = []
for k, v in cnt.items():
    ttl.extend(v)
ttl.sort()
print(ttl[K-1])

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

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

Solution (Python):
import re

s = input()
n = len(s)
k = int(input())
l = []
for i in range(26):
  m_list = [m.start() for m in re.finditer(chr(ord('a')+i), s)]
  
  
  for start in m_list:
    c=1
    while start + c <= n and c <= 5:
      if not s[start:start+c] in l:
        l.append(s[start:start+c])
      c += 1
  if len(l) >= k:
    break

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

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

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
K = ir()
cand = set()
length = len(S)
for i in range(length):
    for j in range(1, 6):
        cand.add(S[i:i+j])

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

Solution (Python):
def main():
    S = input()
    k = int(input())
    setS = set(list(S))
    count = 0
    ans = []
    for j in range(1, k + 1):
        for i in range(len(S) - j + 1):
            ans.append(S[i:i + j])
    ans = sorted(list(set(ans)))
    print(ans[k - 1])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    
    
    l = sorted(list(set(s)))

    
    cnd = []

    

    
    
    
    
    

    def f(sub):
        cnd.append(sub)
        if len(sub) <= K: 
            
            for i in l:
                nx = sub+i
                
                if nx in s:
                	f(nx)
    
    for i in l:
        f(i)
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    
    
    l = sorted(list(set(s)))

    
    cnd = []

    

    
    
    
    
    

    def f(sub):
        cnd.append(sub)
        if len(sub) <= K: 
            
            for i in l:
                nx = sub+i
                
                if nx in s:
                    return f(nx)
    
    for i in l:
        f(i)
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    
    
    
    l = sorted(list(set(s)))
    
    cnd = []
    
    def f(sub):
        cnd.append(sub)
        if len(sub) < K: 
            
            for i in l:
                nx = sub+i
                if nx in s:
                    return f(nx)
    for i in l:
        f(i) 
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    
    
    
    l = sorted(list(set(s)))
    
    cnd = []
    
    def f(sub):
        cnd.append(sub)
        if len(sub) < K: 
            
            for i in l:
                nx = sub+i
                if nx in s:
                    f(nx)
    for i in l:
        f(i) 
    print(cnd[K-1])
if __name__ == '__main__':
    main()

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

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

ans = sorted(set(subs_list))
print(ans[k-1])

Solution (Python):
s = list(input())
K = int(input())
t = sorted(list(set(s[:]))) 
p = set()
for i in range(len(s)):
    for j in range(1, K+1):
        if i+j <= len(s):
            p.add("".join(s[i:i+j]))

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

Solution (Python):
s = input()
k = int(input())
c = []
for i in range(len(s)):
    for j in range(k): c.append(s[i:i+j+1])
c.sort()
pre = ''
for x in c:
    if pre == x: continue
    k -= 1
    if k == 0:
        print(x)
        break
    pre = x

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

def insert(t):
    global que
    for i in range(len(que)):
        if t < que[i]:
            que.insert(i, t)
            if len(que) > 5:
                que = que[:5]
            return
        if que[i] == t:
            return
    if len(que) < 5:
        que.append(t)

for i in range(len(s)):
    for j in range(i+1, min(len(s)+1, i+6)):
        t = s[i:j]
        insert(t)

print(que[k-1])

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

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

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


c = set()
for i in range(n):
    
    t = s[i:i+5]
    for j in range(1,5+1):
        
        c.add(t[:j])

c = list(c)
c.sort()

print(c[k-1])

Solution (Python):
s = list(input())
K = int(input())
sub_list = []
for i in range(1, min(K+1, len(s)+1)):
    for j in range(len(s) - i + 1):
        sub = "".join(s[j:j+i])
        if sub not in sub_list:
            sub_list.append(sub)
sub_list.sort()
print(sub_list[K-1])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

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

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

if __name__ == '__main__':
	main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


s = input()
K = INT()


substr = []

for l in range(len(s)):
	r = l+1
	while r < len(s)+1:
		
		if bisect(substr, s[l:r]) == 5:
			break
		elif s[l:r] in substr:
			r += 1
		elif s[l:r] not in substr:
			insort(substr, s[l:r])
			substr = substr[:5]
			if s[l:r] in substr:
				r += 1



print(substr[K-1])

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

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

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

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

ans = []

for i in range(min(K, N)):
  for j in range(N-i):
    ans.append(s[j:j+i+1])
  
ans.sort()
count = 0
now = '0'
for i in range(len(ans)):
  if ans[i] != now:
    count += 1
    now = ans[i]
    if count == K:
      print(now)
      exit()

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

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

Solution (Python):
s = input()
k = int(input())
lst = sorted(list(set(s)))
tank = []
for tg in lst:
    for i in range(len(s)):
        if s[i]==tg:
            for j in range(k):
                if i+j<=len(s) and (s[i:i+j+1] not in tank):
                    tank.append(s[i:i+j+1])
    if len(tank) >= k:
        break
tank.sort()
print(tank[k-1])

Solution (Python):
s = input()
k = int(input())
se = set()
for i in s:
    se.add(i)
if len(s) > 1:
    for i in range(len(s)-1):
        se.add(s[i]+s[i+1])
if len(s) > 2:
    for i in range(len(s)-2):
        se.add(s[i]+s[i+1]+s[i+2])
if len(s) > 3:
    for i in range(len(s)-3):
        se.add(s[i]+s[i+1]+s[i+2]+s[i+3])
if len(s) > 4:
    for i in range(len(s)-4):
        se.add(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
se = sorted(se)
print(se[k-1])

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

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

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

Solution (Python):
import sys
S = list(sys.stdin.readline().rstrip())
K = int(sys.stdin.readline().rstrip())
res = []
for k in range(K):
    for i in range(len(S)- k):
        res.append("".join(S[i:i+k+1]))
res = list(set(res))
res.sort()
print(res[K - 1])

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

S = input()
N = len(S)
K = getN()

lista = set()
for i in range(N):
    for j in range(i, min(N, i + K)):
        lista.add(S[i:j + 1])
lista = sorted(list(lista))
print(lista[K - 1])

Solution (Python):
s,K = open(0).read().split()
K = int(K)
ss = set()
temp = set([''])
for x in s:
    temp = set([''.join((y,x)) for y in temp if len(y) <= 4])
    ss = ss | temp
    temp.add('')
l = list(ss)
l.sort()
print(l[K-1])

Solution (Python):
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if len(string)>k:
            break
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Solution (Python):

import sys
input = sys.stdin.readline









S = input().rstrip()
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())
Ans = []

while len(Ans) < K:
    for i in range(26):
        if chr(97+i) in S and chr(97+i) not in Ans:
            f = chr(97 + i)
            Ans.append(f)
            break

    for i, s in enumerate(S):
        if s == f:
            for j in range(2, 2 + 10):
                if i + j > len(S):
                    break
                if S[i:i+j] not in Ans:
                    Ans.append(S[i:i+j])
    Ans.sort()
print(Ans[K-1])

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





S = S()
K = I()
N = len(S)
bag = set()

for i in range(N):
  for j in range(i+1,N+1):
    if S[i:j] not in bag:
      bag.add(S[i:j])
      sortbag = sorted(list(bag))
      if len(sortbag) == 6:
        if S[i:j] not in sortbag[:-1]:
          bag = set(sortbag[:-1])
          break
        bag = set(sortbag[:-1])
print(sorted(bag)[K-1])

Solution (Python):


import sys





import string                                



from collections import defaultdict          








from heapq import nlargest, nsmallest        











def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    k = ii()
    n = len(s)

    d = defaultdict(list)
    for i in range(n):
        d[s[i]].append(i)


    L = list(set([s[i:j] for i in range(n) for j in range(i+1, min(n+1, i+6))]))
    print(nsmallest(k, L)[-1])    
            



if __name__ == "__main__":
    main()

Solution (Python):
def resolve():
	s = input()
	k = int(input())
	cnt = set()
	for i in range(len(s)):
		for j in range(1, k+1):
			if j > k:
				break
			cnt.add(s[i:i+j])
	v = sorted(list(cnt))[k-1]
	print(v)
resolve()

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


d=deque()
for i in range(len(s)):
    d.append(s[i])
comp=[]

for i in range(len(s)):
    buf=deque()
    for j in range(len(d)):
        v=d.popleft()
        buf.append(v)
        if j<5:
            comp.append("".join(buf))
    d=deque()
    for j in range(len(buf)):
        d.append(buf[j])
    d.popleft()
comp=list(set(comp))
comp.sort()
print(comp[K-1])

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

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

Solution (Python):
import sys
from collections import defaultdict

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


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


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

    places = defaultdict(list)
    for i in range(N):
        places[S[i]].append(i)

    places = sorted(places.items(), key=lambda x: x[0])
    words = set()
    for k, v in places:
        for start in v:
            cnt = 0
            for end in range(start + 1, N + 1):
                words.add(S[start:end])
                cnt += 1

                if cnt == 5:
                    break

        if len(words) >= 5:
            break

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


if __name__ == "__main__":
    main()

Solution (Python):
S = input()
N = len(S)
K = int(input())
S_list = sorted(set(list(S)))

memo = {}

for small_char in S_list:
    for i in range(N):
        if S[i] == small_char:
            for j in range(i+1, i+K+1):
                word = S[i:j]
                memo[word] = None
    if len(memo) >= K:
        break

ans_list = sorted(list(memo.keys()))
print(ans_list[K-1])

Solution (Python):
s = input()
k = int(input())
a =[chr(ord('a') + i) for i in range(26)]

tar = set()
alpha_idx = 0
while len(tar) < k:
    alpha = a[alpha_idx]
    for i in range(len(s)):
        if s[i] == alpha:
            for j in range(i+1, min(len(s)+1,i+1+k)):
                tar.add(s[i:j])
    alpha_idx += 1
tar = list(tar)
tar.sort()
print(tar[k-1])

Solution (Python):
S = input()
N = len(S)
K = int(input())
top_k = []
for i in range(N):
    for j in range(i + 1, min([i + K, N]) + 1):
            st = S[i:j]
            top_k.append(st)
            if len(top_k) > K:
                top_k = list(set(top_k))
                top_k.sort()
                top_k = top_k[:K]
top_k.sort()
print(top_k[-1])

Solution (Python):
def main():
    S = input()
    N = len(S)
    K = int(input())
    top_k = []
    for i in range(N):
        for j in range(i + 1, min([i + K, N]) + 1):
            st = S[i:j]
            top_k.append(st)
            if len(top_k) > K:
                top_k = list(set(top_k))
                top_k.sort()
                top_k = top_k[:K]
    top_k.sort()
    print(top_k[-1])


if __name__ == '__main__':
    main()

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pri = lambda x: print(*x, sep='\n')

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

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

Solution (Python):



def main():
    s = input()
    N = len(s)
    K = int(input())
    X = set()
    for i in range(1,K+1):
        for j in range(N-i+1):
            X.add(s[j:j+i])
    print(sorted(X)[K-1])

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    s = input()
    K = int(input())
    r = set()
    for i in range(97, 97 + 26):
        for j, v in enumerate(s):
            if v == chr(i):
                for k in range(5):
                    r.add(s[j:j+k+1])
        if len(r) > 5:
            break
    l = list(r)
    l.sort()
    return l[K-1]
print(main())

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

s = input()
K = getN()


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):
from itertools import*;s=input();k=int(input());print(sorted(set(s[i:j]for i,j in combinations(range(len(s)+1),2)if j-i<=k))[k-1])

Solution (Python):
from itertools import*
s = input()
k = int(input())
l = len(s)
print(sorted(set(s[i:j] for i, j in combinations(range(l+1), 2) if j - i <= k))[k-1])

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

from collections import defaultdict 
import itertools 

S = input()
K = ii()
N = len(S)

'''
alphabets = list('abcdefghijklmnopqrstuvwxyz')
l = []

for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            flag = 1
            for j in range(1, min(K+1, N-i+1)):
                l.append(S[i:i+j])

    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()
'''
l = []
for i in range(N):
    for j in range(1, K+1):
        if i+j-1 < N:
            l.append(S[i:i+j])

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

from collections import defaultdict 
import itertools 

S = input()
K = ii()
N = len(S)


alphabets = list('abcdefghijklmnopqrstuvwxyz')
l = []

for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            flag = 1
            for j in range(1, min(K+1, N-i+1)):
                l.append(S[i:i+j])
    
    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()

Solution (Python):
S, k = open(0).read().split()
k = int(k)
x = set(sorted(S)[:min(k, len(S))])
A = set()
for i, c in enumerate(S):
    if c in x:
        s = ''
        for j in range(i, min(i+k, len(S))):
            s += S[j]
            A.add(s)
print(sorted(A)[k-1])

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

cand = []

ilis = sorted(range(len(s)), key=lambda k: s[k])

visited = set()

for i in range(len(s)):
    for j in range(5):
        cand.append(s[ilis[i]:ilis[i]+j+1])

cand.sort()

ret = sorted(list(set(cand)))

print(ret[k-1])

Solution (Python):
S = input()
N = len(S)
K = int(input())
ngrams = set(S)
for n in range(2, 6):
    for i in range(N - n + 1):
        ngrams.add(S[i:i + n])
print(sorted(ngrams)[K - 1])

Solution (Python):

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

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

Solution (Python):
import bisect
s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
  for j in range(k):
    l = s[i:(i+j+1)]
    if l in ans:
      continue
    bisect.insort_left(ans,l)
  ans = ans[:k]
print(ans[-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())

ans = []
table ={}

for i in range(len(S)):
    for j in range(i, len(S)+1):
        if (j-i)>=6:
            break
        if i==j:
            s = S[i]
            if s in table:
                continue
            table[s] = 1
            ans.append(s)
            continue
        if S[i:j]=="":
            continue
        s = S[i:j]
        if s in table:
            continue
        table[s] = 1
        ans.append(s)

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

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

ans = []
table ={}

for i in range(len(S)):
    for j in range(6):
        if i==j:
            s = S[i]
            if s in table:
                continue
            table[s] = 1
            ans.append(s)
            continue
        if S[i:i+j]=="":
            continue
        s = S[i:i+j]
        if s in table:
            continue
        table[s] = 1
        ans.append(s)

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

Solution (Python):
A="abcdefghijklmnopqrstuvwxyz"
S=input()
k=int(input())
n=len(S)

C=[]

for a in A:
    now=""
    cnt=0
    if not a in S:
        continue
    for i in range(n):
        if S[i]==a:
            for j in range(5):
                if i+j<n:
                    C.append(S[i:i+j+1])
                else:
                    break
    C.sort()
    for c in C:
        if now!=c:
            now=c
            cnt+=1
        if cnt==k:
            break
    if cnt==k:
        break
print(now)

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

words = []

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

words.sort()

ans = set()

for word in words:
    for i in range(len(word)):
        ans.add(word[:i+1])
    if len(ans) >= 5:break
lst = list(ans)
lst.sort()

print(lst[K-1])

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