Problem:
 Score : 300 points    Problem Statement You are given a string s .
Among the different substrings of s , print the K -th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s .
For example, if s  =  ababc , a , bab and ababc are substrings of s , while ac , z and an empty string are not.
Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j} .      Constraints  1  ≤  |s|  ≤  5000  s consists of lowercase English letters.  1  ≤  K  ≤  5  s has at least K different substrings.       Partial Score  200 points will be awarded as a partial score for passing the test set satisfying |s|  ≤  50 .         Input Input is given from Standard Input in the following format:  s  K       Output Print the K -th lexicographically smallest substring of K .        Sample Input 1 aba
4      Sample Output 1 b  s has five substrings: a , b , ab , ba and aba .
Among them, we should print the fourth smallest one, b .
Note that we do not count a twice.       Sample Input 2 atcoderandatcodeer
5      Sample Output 2 andat       Sample Input 3 z
1      Sample Output 3 z

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

N = len(s)
Ans = ["z"*5000]*5
for i in range(N):
    for j in range(i,min(N,i+5)):
        tmp = s[i:j+1]
        for k in range(5):
            if Ans[k] > tmp:
                if not (tmp in Ans):
                    for l in range(4-k):
                        Ans[4-l] = Ans[3-l]
                    Ans[k] = tmp
                    break       
print(Ans[K-1])

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

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

a = sorted(list(set(substring)))

print(a[k - 1])

Solution (Python):
import bisect

def main():
    s = input()
    k = int(input())
    n = len(s)
    dp = []
    for l in range(n):
        for r in range(l + 1, min(n + 1, l + 6)):
            t = s[l:r]
            i = bisect.bisect_right(dp, t)
            if i > 0:
                if t == dp[i - 1]: continue
            if len(dp) < k:
                bisect.insort(dp, t)
            elif t < dp[-1]:
                dp.pop()
                bisect.insort(dp, t)
    print(dp[-1])

main()

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

Solution (Python):
import sys
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline()))
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

s =  sys.stdin.readline().rstrip()
K =  int(sys.stdin.readline())


current = s[0]
cnt = 0
L = []
for stride in range(1, K + 1):
    for i in range(len(s) - stride + 1):
        L.append(s[i:i + stride])

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

Solution (Python):



import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

f = defaultdict(lambda : 0)
s = input()
k = I()
n = len(s)
for i in range(1,k+1):
    for j in range(n-i+1):
        f[s[j:j+i]] = 1
f = sorted(f.items())
print(f[k-1][0])

Solution (Python):



import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

f = defaultdict(lambda : 0)
s = input()
k = I()
n = len(s)
for i in range(1,k+1):
    for j in range(n-i+1):
        f[s[j:j+i]] = 1
f = sorted(f.items())
print(f[k-1][0])

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

substrings = set()
for l in range(k):
    for i in range(len(s) - l):
        substrings.add(s[i:i+l+1])

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

Solution (Python):




s = input().split()[0]
K = int(input().split()[0])

sub_s_list = []
N = len(s)
sorted_char_list = sorted(list(set(s)))
char_N = len(sorted_char_list)




start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
pattern = sorted_char_list[0]
sorted_char_list.remove(pattern)
char_i = 0
j = 1

waiting_list = []

while len(sub_s_list) < 5:
    
    sub_s_len = len(pattern)
    sub_s_list.append(pattern)
    next_list = [s[i:i+sub_s_len+1]
                for i in start_index_list
                if (i <= N - (sub_s_len + 1)) and (s[i:i+sub_s_len] == pattern)]

    if not next_list:
        if min(start_index_list) + sub_s_len > N:
            
            if waiting_list:
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
        else:
            
            next_waiting_list =  [s[i:i+sub_s_len+1] for i in start_index_list
                                    if (i <= N - (sub_s_len + 1))]
            
            waiting_list += next_waiting_list
            waiting_list = list(set(waiting_list))

            if waiting_list:
                waiting_list = sorted(waiting_list)
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
    else:
        waiting_list += next_list
        waiting_list = sorted(list(set(waiting_list)))
        pattern = waiting_list[0]
        waiting_list.remove(pattern)
    

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

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

if __name__ == "__main__":
    main()

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

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

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

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

candidate=set()

mx=min(len(S), 5)
for i in range(1, mx+1):
    for j in range(len(S)-i+1):
        candidate.add(S[j:j+i])

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

Solution (Python):
s = input()
K = int(input())
ss = []
for l in range(1, min(K, len(s))+1):
  ss += sorted({ s[i:i+l] for i in range(0, len(s)-l+1) })[:K]
r = sorted(ss)[K-1]
print(r)

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

cond = True
a = []
ind = 0
while ind <= min(K-1,len(list(set(S)))-1):
	temp = sorted(list(set(S)))[ind]

	for i in range(len(S)):
		if S[i] == temp:
			a.append(S[i:min(i+K,len(S))])

	ind += 1

a = sorted(a)

ans = []
j = 0
k = 1
while len(ans) < K:
	if a[j][:k] not in ans:
		ans.append(a[j][:k])
	k += 1
	if k > len(a[j]):
		k = 1
		j += 1

print(ans[-1])

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

A = []
for i in range(n):
    A.append(s[i:])

A.sort()


B = []

for i in range(min(k, len(A))):
    for j in range(1, len(A[i])+1):
        B.append(A[i][:j])

B.sort()


co = 1
i = 1
mae = B[0]
while co < k:
    
    if mae != B[i]:
        co += 1
        mae = B[i]
    i += 1
print(mae)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

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

substring_set = set()
for i in range(len_s):
    for j in range(min([K, len_s-i])):
        substring_set.add(S[i:i+j+1])

sorted_list = sorted(list(substring_set))
print(sorted_list[K-1])

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

substring_set = set()
for i in range(len(S)):
    substring = []
    for j in range(min([K, len(S)-i])):
        substring.append(S[i+j])
        substring_set.add(''.join(substring))

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

Solution (Python):

def get_substring(a: str, x: int) -> set:
    ret = set()
    for i in range(N - x + 1):
        ret |= {a[i : i + x]}
    return ret


def main():
    global N
    S = input()
    K = int(input())
    N, x = len(S), set()
    for i in range(1, K + 1):
        x |= get_substring(S, i)
    ans = sorted(x)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from functools import reduce
from operator import or_


def get_substring(a: str, x: int) -> set:
    ret = set()
    for i in range(N - x + 1):
        ret |= {a[i : i + x]}
    return ret


def main():
    global N
    S = input()
    K = int(input())
    N = len(S)
    x = reduce(or_, [get_substring(S, i) for i in range(1, K + 1)])
    ans = sorted(x)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from string import ascii_lowercase

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

sbst = set()
for char in ascii_lowercase:
    if len(sbst) > 5 :
        break
    for i, c in enumerate(s):
        if c == char :
            for j in range(min(5,len(s)-i)) :
                sbst.add(s[i:i+j+1])

abst = list(sbst)
abst.sort()

print(abst[k-1])

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	
	if len(res[0])==n:
		print(res[0])
		chk=1    
	for i in range(1,n-1): 
		if chk==0 and len(res[i])==n:
			print(res[i][0:n-i+1])
			chk=1
			break
	if chk==0 and len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Solution (Python):
s = input()
k = int(input())
n = len(s)
heads = []
d = set()
for c in s:
    d.add(c)

for key in d:
    heads.append(key)

heads.sort()
ind = 0
ans = []
while True:
    if ind > len(heads)-1:
        break
    head = heads[ind]
    p = set()
    for i in range(len(s)):
        if s[i] == head:
            p.add(i)
    
    ext = 0
    while True:
        flag = False
        dis = -1
        for key in p:
            if key+ext > n-1:
                flag = True
                dis = key
        if flag:
            p.discard(dis)
            
            
        if not p:
            break
        for key in p:
            temp = s[key]
            for j in range(1,ext+1):
                temp += s[key+j]
            
            if temp not in ans:
                ans.append(temp)
        ext += 1
        if ext > 5:
            break
        if len(ans) >= 500:
            break
    if len(ans) >= 500:
        break
    else:
        ind += 1


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

Solution (Python):
import sys
s = input()
k = int(input())
alphabets = list(sorted(set(s)))
if k == 1:
  print(alphabets[0])
  sys.exit()

def l2s(list, alphabets):
  return ''.join(alphabets[i] for i in list)

j = 1
list = [0, 0]
while True:
  t = l2s(list, alphabets)
  if s.find(t) != -1:
    j += 1
    if k == j:
      print(t)
      sys.exit()
    list.append(0)
  else:
   list[-1] += 1
   while list[-1] == len(alphabets):
     list.pop()
     list[-1] += 1

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



s = str(input())
K = I()
n = len(s)

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

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

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

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

Solution (Python):
s = input()
l = int(input())
char = []
if len(s) == 1:
    print(s)
else:
    for i in range(len(s)):
        char.append(s[i])
    charset = set(char)
    ans = []
    for i in charset:
        for j in range(len(s)):
            if i == s[j]:
                for k in range(1, 6):
                    ans.append(s[j:j+k])
    ansset = sorted(list(set(ans)))
    print(ansset[l-1])

Solution (Python):

import sys


def solve(s: str, K: int):
    sl = set()

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

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

    return



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))  
    solve(s, K)

if __name__ == '__main__':
    main()

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


if __name__ == "__main__":
    resolve()

Solution (Python):

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline


S = input().rstrip()
K = int(input())

N = len(S)

ret = []
for nums in range(1, K+1):
    for i in range(N):
        s = S[i:i+nums]
        ret.append(s)

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

Solution (Python):
s=list(input())
words=[]
for i in range(len(s)):words.append("".join(s[i:]))
words=sorted(words)

record=[]
k=int(input())
for i in words:
    for j in range(len(i)):
        if "".join(i[:j+1]) not in record:
            record.append("".join(i[:j+1]))
    if len(record)>=k:
        print(record[k-1])
        exit()

Solution (Python):
import collections
def main():
    s = input()
    K = int(input())
    d = collections.defaultdict(int)
    idx = collections.defaultdict(list)
    n = len(s)
    for i in range(n):
        idx[s[i]].append(i)

    cand = set()
    for c in sorted(idx.keys())[:K]:
        cand.add(c)
        for i in idx[c]:
            for l in range(1, K+1):
                cand.add(s[i:i+l])

    cand = sorted(list(cand))
    return cand[K-1]

if __name__ == '__main__':
    print(main())

Solution (Python):




from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit

setrecursionlimit(10**6)

s=stdin.readline().rstrip()
k=int(stdin.readline().rstrip())
ans=set()
for i in range(len(s)):
    for j in range(len(s)):
        if j>=k:
            break
        ans.add(s[i:i+j+1])
print(sorted(ans)[k-1])

Solution (Python):
s = input()
k = int(input())
x = 0
substr = set()
while x < k:
    x += 1
    for i in range(len(s) - x + 1):
        if s[i:i+x] not in substr:
            substr.add(s[i:i+x])
substr = list(substr)
substr.sort()
print(substr[k-1])

Solution (Python):
import collections
s = input()
k = int(input())
d = []
dd = collections.defaultdict(list)
for i in range(len(s)):
    d.append(s[i])
    dd[s[i]] += [1]
for ke in sorted(d.copy()):
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d.append(s[i:j])
                dd[s[i:j]] += [1]
    if len(dd) >= k:
        d = sorted(collections.Counter(d))
        print(d[k-1])
        exit()

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

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

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

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

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

substring.sort()
print(substring[k - 1])

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

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

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

substring.sort()
print(substring[k-1])

Solution (Python):
s=input()
K=int(input())
n=len(s)
se=set()
for i in range(n):
    se.add(s[i:i+1])
    se.add(s[i:i+2])
    se.add(s[i:i+3])
    se.add(s[i:i+4])
    se.add(s[i:i+5])
l=list(se)
l.sort()
print(l[K-1])

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

substrings = []

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

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

for i in range(1, len(s) + 1):
    if i >= k+1:
        break
    for j in range(len(s) - i + 1):
        word = s[j:j+i]
        if word not in a:
            a.append(word)


a.sort()

print(''.join(a[k-1]))

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

kouho = []

tmp = 0

flag = False

for i in range(k):
    if flag == True:
        break
    for j in range(len(s)):
        if tmp >= k:
            flag = True
            break
        tmp += 1
        kouho.append(s[i:i+j+1])
        
kouho.sort()
tmp = 0

flag = False

for i in range(len(s)):
    for j in range(2*k):
        for l in range(k):
            if s[i:i+j+1] == kouho[l]:
                break
            elif s[i:i+j+1] < kouho[l]:
                kouho.insert(l,s[i:i+j+1])
                break
            else:
                continue

print(kouho[k-1])

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

s2 = ''.join(sorted(set(list(s))))

l = []

for i in range(len(s2)):
  if len(set(l)) >= K:
    
    break
  else:
    for j in range(len(s)):
      if s2[i] == s[j]:
        for k in range(j+1, len(s)+1):
          if k-j > K:
            break
          else:
            l.append(s[j:k])
l = list(set(l))
l.sort()

print(l[K-1])

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

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

    S = set()

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

    print(sort_S[K-1])
main()

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



five_subs = []
for num in range(1,6):
    for idx in range(len(S)-(num-1)):
        tmp_s = S[idx:idx+num]
        
        if len(five_subs) == 0:
            five_subs.append(tmp_s)

        else:
            if tmp_s in five_subs:
                continue
            elif len(five_subs) <= 5:
                five_subs.append(tmp_s)
                five_subs.sort()
                five_subs = five_subs[:5]
            else:
                for sub in five_subs:
                    if sub > tmp_s:
                        five_subs.append(tmp_s)
                        five_subs.sort()
                        five_subs = five_subs[:5]
                        break

print(five_subs[K-1])

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

substrings = set()

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

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

Solution (Python):
from sys import stdin
s = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans = list(s)

for i in range(2,K+1):
    for j in range(0,len(s)-i+1):
        ans.append(s[j:j + i])

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

Solution (Python):

import collections
import itertools
import sys

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

s=input()
k=getint()

substr = set()
for slen in range(1, k+1):
    for i in range(len(s)):
        end = i + slen
        if end <= len(s):
            substr.add(s[i:end])

substr = list(sorted(substr))

print(substr[k-1])

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

subList = set([])

for front in range(0, len(S)):
    for length in range(1, K + 1):
        subList.add(S[front: front + length])

subList = list(subList)
subList.sort()

print(subList[K - 1])

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

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

Solution (Python):
s = input()
k = int(input())
sub = set()
for i in range(0,len(s)):
    j = 1
    while i+j<=len(s) and j<=5:
        sub.add(s[i:i+j])
        j = j + 1
ans = list(sub)
ans.sort()
print(ans[k-1])

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

a = set()

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

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

a = set()

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

Solution (Python):

s = input()
k = int(input())
can = []
for l in range(len(s)):
  for w in range(5):
    try:
      now = s[l:l+w+1]
      if now in can:
        pass
      else:
        can.append(now)
    except:
      pass
can.sort()
print(can[k-1])

Solution (Python):
from itertools import combinations

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

cand = set()
for c in s:
    cand.add(c)
for l, r in combinations(range(len(s)), 2):
    if r - l + 1 > K:
        continue
    cand.add(s[l:r + 1])

cand = list(cand)
cand.sort()

print(cand[K - 1])

Solution (Python):
"""
sの異なる部分文字列のうち、
辞書順でK番目に小さいもの
|s| <= 5000
"""

s = input()
K = int(input())
n = len(s)
substrs = set()
for i in range(n):
    for j in range(K):
        if i + j >= n:
            continue
        substrs.add(s[i:i+j+1])
print(sorted(substrs)[K-1])

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

l = []
for i in range(N):
    for j in range(i+1,min(i+K+1,N+1)):
        s = S[i:j]
        l.append(s)
l = list(set(l))
l.sort()
print(l[K-1])

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


subst = set()
for fil_i in range(1, k+1):
    for ix in range(0, len(s)):
        if ix + fil_i <= len(s):

            subst.add(s[ix: ix + fil_i])
        else:
            break

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

Solution (Python):

import sys, math, fractions, itertools


def solve(s: str, K: int):
    l = []
    for i in range(1, K+1):
        for j in range(len(s)):
            l.append(s[j:j+i])
    l = sorted(list(set(l)))
    print(l[K-1])
    return



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))  
    solve(s, K)

if __name__ == '__main__':
    main()

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

dictionary = []
for i in range(len(s)):
    for j in range(k+1):
        word = s[i:i+j]
        if word not in dictionary:
            dictionary.append(word)
dictionary.sort()
print(dictionary[k])

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

st = set()
for i in range(N):
    for j in range(i+1, min(i+K+1, N+1)):
        st.add(s[i:j])
l = sorted(list(st))

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

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

n = len(s)

ans = set()

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

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

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

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

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

pri = sorted(set(s))[0]
cnt = s.count(pri)
lind = []
ind = -1
for i in range(cnt):
  tmp = s[ind+1:].find(pri)
  lind.append(tmp+ind+1)
  ind = tmp + ind + 1
setdic = set()
for i in lind:
  for j in range(1,k+1):
    setdic.add(s[i:i+j])
if len(setdic) >= k:
  lians = sorted(list(setdic))
  print(lians[k-1])
else:
  sec = sorted(set(s))[1]
  cnt = s.count(sec)
  lind = []
  ind = -1
  for i in range(cnt):
    tmp = s[ind+1:].find(sec)
    lind.append(tmp+ind+1)
    ind = tmp+ind+1
  setdic2 = set()
  for i in lind:
    for j in range(1,k+1):
      setdic2.add(s[i:i+j])
  if len(setdic)+len(setdic2) >= k:
    lians = sorted(list(setdic2))
    print(lians[k-1-len(setdic)])
  else:
    thr = sorted(set(s))[2]
    cnt = s.count(thr)
    lind = []
    ind = -1
    for i in range(cnt):
      tmp = s[ind+1:].find(thr)
      lind.append(tmp+ind+1)
      ind = tmp+ind+1
    setdic3 = set()
    for i in lind:
      for j in range(1,k+1):
        setdic3.add(s[i:i+j])
    lians = sorted(list(setdic3))
    print(lians[k-1-len(setdic)-len(setdic2)])

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

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

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

Solution (Python):
s = input()
k = int(input())
n = len(s)
substring_set = set([])

for i in range(n):
    for j in range(1,6):
        if i + j <= n:
            substring_set.add(s[i:i+j])
substring_list = list(substring_set)

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

Solution (Python):
from heapq import nsmallest

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)):
        subs.add(s[i:j])
arr = list(subs)
print(nsmallest(K, arr)[-1])

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

Solution (Python):
def get_char_ngram(n, s):
    char_gram = [''.join(s[i:i+n]) for i in range(len(s)-n+1)]
    return char_gram

s = input()
K = int(input())
res = set()
for i in range(1, K+1):
    tmp = set(get_char_ngram(i, s))
    res = res.union(tmp)
res = sorted(list(res))
print(res[K-1])

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

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

    S1 = {}
    for i, s in enumerate(S):
        if not s in S1.keys():
            S1[s] = [i]
        else:
            S1[s].append(i)
    alp = sorted(list(S1.keys()))

    c = 0
    for a in alp:
        aset = set()
        inds = S1[a]
        for d in inds:
            up = min(N-d+1, K+1)
            for i in range(up):
                aset.add(S[d:d+i])
        L = len(aset)-1
        if L >= K-c:
            break
        c += L

    for _ in range(10):
        M = '何だこれはもうやめてくれよ'
        for a in aset:
            if a < M:
                M = a
        aset.discard(M)
        if M == '':
            continue
        c += 1
        if c >= K:
            ans = M
            break

    print(ans)



if __name__=='__main__':
    main()

Solution (Python):
from collections import OrderedDict
s = input()
n = len(s)
k = int(input())

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

print(ans[k - 1])

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

alphabet="abcdefghijklmnopqrstuvwxyz"
arr=[]
for x in alphabet:
    
    for i in range(len(s)):
        
        if s[i]==x:
            
            l=min(K,len(s)-i)
            
            for j in range(l):
                arr.append(s[i:i+j+1])
                
                
    arr=list(set(arr))
    arr.sort()
    
    if len(arr)>=K:
        ans=arr[K-1]
        break
print(ans)

Solution (Python):
s = input()
ls = len(s)
K = int(input())
ss = sorted(set(list(s)))
ssl = len(ss)
kl = []
m = set()
for t in ss[0:min(ssl,K)]:
    kkl = []
    i = 0
    while True:
        if i > ls-1:break
        if s[i] == t:
            kkl.append(s[i:])
        i += 1
    for sub in sorted(kkl):
        lsub = len(sub)
        for i in range(0,lsub):
            m.add(sub[0:i+1])
        if len(m) >=5:break
    if len(m) >=5:break
print(sorted(m)[K-1])

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

ans = []

for i in range(n):
    for j in range(1,k+1):
        if i + j > n:
            continue
        ans.append(s[i:i+j])

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

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




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