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

Solution (Python):
def main():
    s = input()
    K = int(input())
    lst = sorted(set(s))
    ans = []

    def dfs(c):
        if len(ans) < K:
            ans.append(c)
            for li in lst:
                if c + li in s:
                    dfs(c + li)

    for li in lst:
        dfs(li)
    print(ans[-1])
    return


main()

Solution (Python):
def main():
    s = input()
    K = int(input())
    lst = sorted(set(s))
    ans = []

    def dfs(c):
        ans.append(c)
        if len(ans) < K:
            for li in lst:
                if c + li in s:
                    return dfs(c + li)

    for li in lst:
        dfs(li)
    print(ans[K - 1])
    return


main()

Solution (Python):
def main():
    s = input()
    K = int(input())
    print(sorted({s[i:j]
                  for i in range(len(s))
                  for j in range(i + 1, min(i + K + 1, len(s) + 1))})[K - 1])
    return


main()

Solution (Python):
import sys
input = sys.stdin.readline
S = set()
s = list(input().rstrip())
K = int(input())
for i in range(len(s)):
    for j in range(i+1, i+K+1):
        if "".join(s[i:j]) not in S:
            S.add("".join(s[i:j]))
S = list(S)
S.sort()
print("".join(S[K-1]))

Solution (Python):
import sys

input = sys.stdin.readline


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

    dic = []
    dic_set = set()
    for i in range(len(S)):
        j = 0
        tmp = ""
        while i + j < len(S) and j < 5:
            tmp += S[i + j]
            if tmp not in dic_set:
                dic.append(tmp)
                dic_set.add(tmp)
            j += 1

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline


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

    dic = []
    for i in range(len(S)):
        j = 0
        tmp = ""
        while i + j < len(S) and j < 5:
            tmp += S[i + j]
            if tmp not in dic:
                dic.append(tmp)
            j += 1

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



    
    
    


if __name__ == '__main__':
    main()

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

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

Solution (Python):
def main():
    s = input()
    k = int(input())
    l = set()
    ls = len(s)
    clist = sorted(list(set(list(s))))
    ladd = l.add
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        ladd(i)
        for j in range(len(x)):
            idx = x[j]
            xxx = s[idx]
            c = 0
            for t in range(idx+1,ls):
                xxx = xxx +s[t]
                ladd(xxx)
                c += 1
                if c > k:
                    break
        if len(l) >= k:
            l = list(l)
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
K = int(input())
letters = []
for i in range(len(s)):
    for j in range(6):
        if(i + j > len(s)): break
        if(s[i:i + j] != ''): letters.append(s[i:i + j])
l = list(dict.fromkeys(letters))
l.sort()
print(l[K - 1])

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

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

al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    while (i + cnt <= N):
        if cnt == 7:
            break
        ans_list.append(S[i:i+cnt])
        cnt += 1

ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        while (i + cnt <= N):
            if cnt == 7:
                break
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))


ans_list.sort()

print(ans_list[K-1])

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

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

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

Solution (Python):

s = input()
K = int(input())
len_s = len(s)

result = []

for i in range(len_s):
  for j in range(i+1, i+1+5):
    x = s[i:j]
    result.append(x)

result = sorted(result)
len_r = len(result)

if len_r == 1 or K == 1:
  print(result[0])
  exit()

index = 0
for i in range(1, len_r):
  if result[i] != result[i-1]:
    index += 1
  if index == K-1:
    print(result[i])
    exit()

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

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

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

N = len(s)
words = set()
for i in range(N):
    for j in range(i+1, i+K+1):
        w = s[i:j]
        if w not in words:
            words.add(w)

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

Solution (Python):
import collections

S = str(input())
len_S = len(S)
K = int(input())
lst = []

for i in range(len_S):
	j = 1
	while i + j <= len_S:
		if j == 6: break
		lst.append(S[i : i + j])
		j += 1
lst.sort()

if K == 1:
	print(lst[0])
else:
	ctr = 1
	for i in range(1, len(lst)):
		if lst[i] != lst[i - 1]:
			ctr += 1
		if ctr == K:
			print(lst[i])
			break

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

li=set()

for p in range(5):
  for i in range(len(s)-p):
    li.add(s[i:i+1+p])
li=list(li)
li.sort()

print(li[k-1])

Solution (Python):
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,min(i+5,len(s))):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()

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


subl = list(set(sub))

subl.sort()

 
print(subl[K-1])

Solution (Python):
import collections

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

l = len(s)
sub = set()

if l <= 50:
    for i in range(l):
        for j in range(i+1):
            sub.add(s[j:i+1])
    
    subl = list(sub)
    subl.sort()
    
    print(subl[K-1])

else:
    cl = collections.Counter(s).most_common()
    cl.sort(key=lambda x: x[0])
    
    d = 0
    while len(sub) < K:
        be = cl[d][0]
        for i in range(l):
            if s[i] == be:
                for j in range(K):
                    sub.add(s[i:min(i+j+1,l)])
        d += 1
    
    subl = list(sub)
    subl.sort()
    print(subl[K-1])

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

alpha = [0] * 27
for s in S:
  alpha[ord(s) - ord("a")] += 1

answer = []
for a in range(27):
  if alpha[a]:
    for i in range(N):
      if S[i] == chr(a+ord("a")):
        for j in range(1, 6):
          if i + j > N:
            break
          answer.append(S[i:i+j])
    answer = list(set(answer))
    if len(answer) >= K:
      answer.sort()
      print(answer[K-1])
      exit()

Solution (Python):
s = list(input())
k = int(input())
candidate = []
for i in range(len(s)):
    for j in range(k+1):
        candidate.append(s[i:i+j])
for i in range(len(candidate)):
    candidate[i] = "".join(candidate[i])
candidate = list(set(candidate))

candidate.sort()
print(candidate[k])

Solution (Python):
s = list(input())
k = int(input())
candidate = []
for i in range(len(s)):
    for j in range(k+1):
        candidate.append(s[i:i+j])
for i in range(len(candidate)):
    candidate[i] = "".join(candidate[i])
candidate = list(set(candidate))
def sort_key(x):
    while len(x) < 5:
        x += "_"
    return x
candidate.sort(key = sort_key)
print(candidate[k])

Solution (Python):


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

result = []

len_s = len(s)
for i in range(len_s):
  for j in range(min(len_s, 5)):
    if s[i:i+j+1]:
      result.append(s[i:i+j+1])

ans = []
for res in sorted(result):
  if not res in ans:
    ans.append(res)
    if len(ans) == K:
      print(ans[K-1])
      exit()

Solution (Python):
s = input()
k = int(input())
lst = []
m = min(5,len(s))
while True:
    if m<=0:
        break
    for i in range(len(s)-m+1):
        q = s[i:i+m]
        if not q in lst:
            lst.append(q)
    m -= 1

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

Solution (Python):


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

substr = set()
for i in range(len(s)):
    for j in range(1,6):
        if i + j <= len(s):
            substr.add(s[i:i+j])
substrlist = list(substr)
substrlist.sort()
print(substrlist[K-1])

Solution (Python):

import sys


def solve(s: str, K: int):

    candidate = set()
    N = len(s)
    for length in range(1,K+1):
        for i in range(N):
            if i+length>N:
                break
            candidate.add(s[i:i+length])
    
    candidate = sorted(list(candidate))
    print(candidate[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):

import sys


def solve(s: str, K: int):

    index_dict = {}
    for i in range(len(s)):
        if index_dict.get(s[i]) == None:
            index_dict[s[i]] = [i]
        else:
            index_dict[s[i]].append(i)

    value_list = sorted(set(list(s)))
    candidate = set()

    for string in value_list:
        index = index_dict[string]
        for i in index:
            tmp_s = ""
            for j in range(i,len(s)):
                if len(tmp_s) > K:
                    break
                tmp_s += s[j]
                candidate.add(tmp_s)
        if len(candidate) >= K:
            break
    candidate = list(candidate)
    candidate.sort()
    print(candidate[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())
a=set()

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

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

for i in range(K):
    for j in range(len(s)-i):
        a.append(s[j:j+i+1])
a.sort()
cnt=1
i=1
while cnt<K:
    if a[i]!=a[i-1]:
        cnt+=1
    i+=1
print(a[i-1])

Solution (Python):
import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)

def main():
    res = set()
    for l in range(n):
        for r in range(l, min(l+k, n)):
            res.add(s[l:r+1])

    return sorted(res)[k-1]

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

Solution (Python):
s=input()
k=int(input())
n=len(s)
l = []
for i in range(n):
    l.append(s[i])
for i in range(n-1):
    l.append(s[i:i+2])
for i in range(n-2):
    l.append(s[i:i+3])
for i in range(n-3):
    l.append(s[i:i+4])
for i in range(n-4):
    l.append(s[i:i+5])

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

Solution (Python):
from string import ascii_lowercase
s = input()
k = int(input())

sub = []
l = [[] for _ in range(5)]

for i in range(min(len(s),5)):
    if i == 0:
        for c in ascii_lowercase:
            if s.find(c) != -1:
                l[i].append(c)
                sub.append(c)
            if len(l[i]) >= k:
                break
    else:
        for ss in l[i-1]:
            for c in ascii_lowercase:
                tmp = ss + c
                if s.find(tmp) != -1:
                    l[i].append(tmp)
                    sub.append(tmp)
            if len(l[i]) >= k:
                break

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

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


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

l.sort()

print(l[k-1])

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

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

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

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

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

n = len(s)
strs = set([])

for i in range(n):
    for j in range(i+1, min(i+k+1,n+1)):
        strs.add(s[i:j])
strs = list(strs)
strs.sort()
print(strs[k-1])

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

Solution (Python):

s = input()
len_s = len(s)
k = int(input())
substring_list = []
sappend = substring_list.append
for i in range(len_s):
    for j in range(5):
        sappend(s[i:min(i+1+j,len_s)])
substring_set = set(substring_list)
print(sorted(substring_set)[k-1])

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

subs = []

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

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

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

A = []
for i in range(len(s)):
    for j in range(k):
        if i+j+1 > len(s):
            continue
        tmp = s[i:i+j+1]
        A.append(tmp)

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

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

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

substr = set()

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

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

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


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

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

Solution (Python):

import sys


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

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()
l=len(s)
k=int(input())
x=set()
for i in range(1,min(l,k)+1):
    for j in range(l-i+1):
        x.add(s[j:j+i])
x=sorted(list(x))
print(x[k-1])

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

one = []
check = set()

for s in S:
    if s not in check:
        one.append(s)
        check.add(s)

ans = set()
one.sort(reverse=True)
for i in range(5):
    if not one:
        break
    first = one.pop()
    ans.add(first)
    for j, s in enumerate(S):
        if s == first:
            length = 1
            while j+length < l and length < 5:
                length += 1
                string = S[j: j+length]
                ans.add(string)
        else:
            continue

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

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

List = []

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

set_List = set(List)
List = list(set_List)
List = sorted(List)
List.remove('')

ans = List[k-1]
print(ans)

Solution (Python):
s=input()
K=int(input())
n=len(s)
a=[s[i] for i in range(n)]+[s[i:j] for i in range(0, n-1) for j in range(i+2, min(n+1, i+K+1))]
a.sort()
i=1
counter=1
while counter<K:
  if a[i]!=a[i-1]:
    counter+=1    
  i+=1
print(a[i-1])

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
N = len(S)
K = INT()

min_s = min(S)
B = [s for s in S]
B.sort()


cursol = 0
min_s = 'ATCODER'
cand = []
while len(cand) < K:
	
	if min_s == B[cursol]:
		cursol += 1
		continue
	else:
		min_s = B[cursol]
	for i,s in enumerate(S):
		if s == min_s:
			for j in range(i+1, i+1+K):
				if not cand.count(S[i:j]): cand.append(S[i:j])
	cursol += 1

cand.sort()


s = min(S)
cnt = 0
for c in cand:
	cnt += 1
	if cnt == K:
		print(c)
		break

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

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

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

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

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

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

Solution (Python):

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

char_place_dict = dict()


for i in range(len(s)):
    if s[i] not in char_place_dict:
        char_place_dict[s[i]] = [i]
    else:
        char_place_dict[s[i]].append(i)
        
all_alphabet = list([chr(i) for i in range(97, 97+26)])

substrings_set = set()
break_flag = 0

s = ''.join(map(str,s))

for char in all_alphabet:
    if char in char_place_dict:
        substrings_set.add(char)
        
        
        for place in char_place_dict[char]:
            for i in range(1,6):
                substrings_set.add(s[place:place+i])
                
                
        if len(substrings_set)>=K:
            break_flag = 1
            break
        
    if break_flag == 1:
            break
            

substrings_list = list(substrings_set)
substrings_list.sort(reverse=False)

print(substrings_list[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())
s = []
ss = []
for i in range(len(S)):
    s.append(S[i:])
s.sort()
for i in range(len(s)-1):
    if s[i] != s[i+1][:len(s[i])]:
        ss.append(s[i])
ss.append(s[-1])
i = 0
while len(ss[i]) < K:
    K -= len(ss[i])
    i += 1
print(ss[i][:K])

Solution (Python):
S = list(input())
N = len(S)
K = int(input())
ans = []
for start in range(N):
    for end in range(K):
        if start + end >= N:
            break
        sentinel = min(N - 1 , start + end)
        ans.append(S[start:sentinel + 1])

i = 0
ans.sort()
answer = []
while len(answer) < K:
    if not ans[i] in answer:
        answer.append(ans[i])
    i += 1
print("".join(answer[K - 1]))

Solution (Python):

s = input()
K = int(input())
T = list(s)
for i in range(2,6):
    for j in range(len(s)-i+1):
        T.append(s[j:j+i])
T = list(set(T))
T.sort()
print(T[K-1])

Solution (Python):
S=str(input())
K=int(input())
S_list=list(S)
J=[]
for i in range(len(S)):
  for j in range(i+1,min(i+6,len(S)+1)):
    J += [''.join(S[i:j])]
J=sorted(list(set(J)))
print(J[K-1])

Solution (Python):
s=input()
K=int(input())
a=list("abcdefghijklmnopqrstuvwxyz")
l=[]
S=set()
n=len(s)

for c in a:
	j=-1
	for i in range(s.count(c)):
		j+=s[j+1:].find(c)+1
		k=j+1
		while k<=n and k-j<=5:
			S.add(s[j:k])
			k+=1
	if len(S)>=5:
		break

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

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

n = len(s)
l = set()

for i in range(n):
    for j in range(k):
        if i+j <=n-1:
            l.add(s[i:i+j+1])

l = list(l)
l.sort()

print(l[k-1])

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

S = set()
for i in range(len(s)):
    for w in range(1, K+1):
        S.add(s[i:i+w])

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

Solution (Python):

S = list(str(input()))
N = len(S)
K = int(input())

cand = []
for i in range(N):
    s = S[i]
    cand.append(s)
    for j in range(K):
        if i+j+1 < N:
            s+=S[i+j+1]
            cand.append(s)
            
cand.sort()
old = ""
shin = []
for c in cand:
    if c != old:
        shin.append(c)
        old = c
        
shin.sort()
print(shin[K-1])

Solution (Python):

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

minimum_canditates = sorted(set(s))
n_counted = 0

canditates = []


def add_canditate(target_chara):
    global n_counted

    canditates.append(target_chara)
    n_counted += 1
    for c in minimum_canditates:
        next_target = target_chara + c
        if n_counted < K and next_target in s:
            add_canditate(next_target)


for c in minimum_canditates:
    add_canditate(c)

print(canditates[K - 1])

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

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

Solution (Python):
def examC():
    S = SI()
    K = I()
    d = set()
    for i in range(len(S)):
        for j in range(5):
            s = S[i:(i+j+1)]
            d.add(s)
    d = list(d)
    d.sort()
    print(d[K-1])

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):
from collections import Counter
s = input()
k = int(input())
se = set()

for i in range(len(s)):
    temp = ''
    last = min(i+5,len(s))
    for j in range(i,last):
        temp+=s[j]
        se.add(temp)
se = list(sorted(se))
print(se[k-1])

Solution (Python):
S = list(input())
k = int(input())
S_sorted = "".join(sorted(list(set(S))))

Ans = []
counter = 0
for counter in range(0, 10000000):
  Ans_temp = []
  moji = S_sorted[counter]
  Index = [i for i, chr in enumerate(S) if moji == chr]
  for j in range(0, k + 1):
    for index in Index:
      if len(S[index : index+j]) != 0:
        Ans_temp.append("".join(S[index : index+j]))

  Ans = Ans + sorted(list(set(Ans_temp)))
  if len(Ans) >= k:
    break
print(Ans[k-1])

Solution (Python):
s = input()
k = int(input())
substrings = []
if len(s) < 8:
    for i in range(1, len(s) + 1):
        substrings.extend([s[_:_ + i] for _ in range(len(s) - i + 1)])
else:
    for i in range(1, 8):
        substrings.extend([s[_:_ + i] for _ in range(len(s) - i + 1)])

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

Solution (Python):


def main():
    s = input()
    K = int(input())
    substrings = []

    for i in range(len(s)):
        for ii in range(i,len(s)):
            if len(s[i:ii+1]) > K:
                break
            if s[i:ii+1] not in substrings:
                substrings.append(s[i:ii+1])
    
    substrings.sort()
    print(substrings[K-1])
        

if __name__ == "__main__":
    main()

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



rank = []
for i in range(len(s)):
    for j in range(i+1, min(i+6,len(s)+1)):
        ss = s[i:j]
        rank.append(ss)

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

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

list_sub = []
for i in range(len(s)):
  temp = [s[i:i+j] for j in range(1, min(len(s)-i+1, k+1))]
  list_sub += temp

list_sub = list(set(list_sub))
list_sub.sort()

print(list_sub[k-1])

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

element =[]
for length in range(1,K+1):
    for i in range(len(string)-length+1):
        tmp = string[i:i+length] 

        if tmp not in element:
            element.append(tmp)
print(sorted(element)[K-1])

Solution (Python):
from heapq import nsmallest
def main():
    S = input()
    K = int(input())
    N = len(S)
    A = []
    for l in range(N):
        for r in range(l+1, min(N+1, l+K+1)):
            A.append(S[l:r])
    print(nsmallest(K, list(set(A)))[-1])

main()

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

for l in range(1, K+1):
    for i in range(len(s)+1-l):
        d |= {s[i:i+l]}
	
print(sorted(list(d))[K-1])

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class SuffixArray(object):
    def __init__(self,s):
        self.__s=s
        self.__n=len(s)
        self.__suffix_array()
        self.__lcp_array()
        self.__sparse_table()

    def __suffix_array(self):
        s=self.__s; n=self.__n
        sa=list(range(n))
        rank=[ord(s[i]) for i in range(n)]
        tmp=[0]*n
        k=1
        cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
        while(k<=n):
            sa.sort(key=cmp_key)
            tmp[sa[0]]=0
            for i in range(1,n):
                tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
            rank=tmp[:]
            k<<=1
        self.__sa=sa
        self.__rank=rank

    def __lcp_array(self):
        s=self.__s; n=self.__n
        sa=self.__sa; rank=self.__rank
        lcp=[0]*n
        h=0
        for i in range(n):
            j=sa[rank[i]-1]
            if(h>0): h-=1
            if(rank[i]==0): continue
            while(j+h<n and i+h<n and s[j+h]==s[i+h]): h+=1
            lcp[rank[i]]=h
        self.__lcp=lcp

    def __sparse_table(self):
        n=self.__n
        logn=max(1,(n-1).bit_length())
        table=[[0]*n for _ in range(logn)]
        table[0]=self.__lcp[:]
        from itertools import product
        for i,k in product(range(1,logn),range(n)):
            if(k+(1<<(i-1))>=n): table[i][k]=table[i-1][k]
            else: table[i][k]=min(table[i-1][k],table[i-1][k+(1<<(i-1))])
        self.__table=table

    @property
    def suffix(self):
        return self.__sa

    def lcp(self,a,b):
        if(a==b): return self.__n-a
        l,r=self.__rank[a],self.__rank[b]
        l,r=min(l,r)+1,max(l,r)+1
        i=max(0,(r-l-1).bit_length()-1)
        table=self.__table
        return min(table[i][l],table[i][r-(1<<i)])

def resolve():
    S=input()
    n=len(S)
    k=int(input())

    sa=SuffixArray(S)
    D=set()
    for i in sa.suffix:
        for j in range(i+1,n+1):
            D.add(S[i:j])
            if(len(D)==k):
                print(sorted(D)[-1])
                return
resolve()