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 functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    s = input()
    K = int(input())
    dict = set()
    for i in range(len(s)):
        for j in range(K):
            if i+j+1 <= len(s):
                dict.add(s[i:i+j+1])
    di = list(dict)
    di.sort()
    print(di[K-1])
    
if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
s=input()
k=int(input())
n=len(s)
ans=deque()
for i in range(n):
    for j in range(k):
        ans.append(s[i:i+j+1])
print(sorted(list(set(ans)))[k-1])

Solution (Python):
S = input()
K = int(input())
anslist = []
for i in range(0, len(S)):
	now = ''
	for j in range(i, len(S)):
		now = now + str(S[j])
		flag = True
		if len(anslist) != K and now not in anslist:
			flag = False
			anslist.append(now)
		elif len(anslist) == K and now < anslist[-1] and now not in anslist:
			flag = False
			anslist[-1] = now
		elif now in anslist:
			flag = False
		anslist.sort()
		if flag:
			break
print(anslist[-1])

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

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

for i in range(len(s)):
    for j in range(k):
        if i+j+1 <= len(s):
            dic.add(s[i:i+j+1])
di = list(dic)
di.sort()
print(di[k-1])

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

for i in range(len(s)):
    for j in range(k):
        if i+j+1 <= len(s):
            dic.add(s[i:i+j+1])
di = list(dic)
di.sort()
print(di[k-1])

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

for i in range(len(s)):
    for j in range(k):
        if i+j+1 <= len(s):
            dic.add(s[i:i+j+1])
di = list(dic)
di.sort()
print(di[k-1])

Solution (Python):

def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, k + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

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

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

letter_set = sorted(set(S))

ans_list = []

for letter in letter_set:
    letters = letter
    while letters in S:
        ans_list.append(letters)
        if len(ans_list) == K:
            print(ans_list[K - 1])
            sys.exit()
        for i in range(len(letter_set)):
            if letters + letter_set[i] in S:
                letters = letters + letter_set[i]
                break
        else:
            break
print(ans_list[K - 1])

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

l = "abcdefghijklmnopqrstuvwxyz"
li = []
res = []
for i in l:
    for index,j in enumerate(s):
        if j==i:
            li.append(s[index:])
    else:
        if len(li) > 5:
            break



li.sort()

for i in range(1,6):
    for j in li:
        try:
            
            res.append(j[:i])
            
        except:
            pass
else:
    res = list(set(res))
    res.sort()
        
    print(res[k-1])

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

ls = []

for i in range(min(5,len(s))):
    for j in range(0,len(s)-i):
        ls.append(s[j:j+(i+1)])

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

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


set_ans = set()
for i in range(k):
    for j in range(len(s)):
        set_ans.add(s[j:j+i+1])


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

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


ans_set = set()
for i in range(len(s)):
    c = s[i]
    ans_set.add(c)
    for j in range(i + 1, len(s)):
        c += s[j]
        if len(c) > k:
            break
        ans_set.add(c)


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


print(ans)

Solution (Python):
from collections import defaultdict

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

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

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

sorted_str = sorted(list(str_set))
print(sorted_str[K-1])

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

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

sl=sorted(list(st))

print(sl[K-1])

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

ans=[]
a=ans.append
for i in range(len(s)):
	a(s[i])
for i in range(len(s)-1):
	a(s[i:i+2])
for i in range(len(s)-2):
	a(s[i:i+3])
for i in range(len(s)-3):
	a(s[i:i+4])
for i in range(len(s)-4):
	a(s[i:i+5])
ans=sorted(list(set(ans)))
print(ans[k-1])

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

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

substr = list(set(substr))
substr.sort()

print(substr[K-1])

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

substr = []
for n in range(1, k+1):
    for i in range(len(s)-n+1):
        substr.append(s[i:i+n])

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

Solution (Python):
s=input()
k=int(input())
l=set()
for i in  range(len(s)):
    for j in range(1,k+1):
        l.add(s[i:i+j])
ll=list(l)
ll.sort()

print(ll[k-1])

Solution (Python):

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

lis = []

alps = "abcdefghijklmnopqrstuvwxyz"

for alp in alps:

    for i in range(len(s)):

        
        if s[i] == alp:

            

            for j in range(6):

                j += 1
                
                
                if i + j <= len(s) and (s[i:i+j] not in lis):
                    
                    lis.append(s[i:i+j])

    if len(lis) >= K:
        break


lis.sort()


print (lis[K - 1])

Solution (Python):
import os
import sys

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

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

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

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

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

alpha=[]

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

alpha.sort()

print(alpha[k-1])

Solution (Python):
s=input()
K=int(input())
List=[]
Length=len(s)
for i in range(Length):
    List.append(s[i])
    n=1
    while n<=4:
        if i+n>=Length:
            break
        else:
            List.append(s[i:i+n+1])
            n+=1
List_unique=list(set(List))    
List_unique.sort()
print(List_unique[K-1])

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

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  k=I()

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

  l=list(set(l))
  l.sort()

  return l[k-1]

print(main())

Solution (Python):
from collections import Counter

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

chars = sorted(list(Counter(S).keys()))


idx_pre_char = 0
solver = []
while len(solver) < K:
  for i in range(len(S)):
    if S[i] == chars[idx_pre_char]:
      if i <= len(S) - K:
        for j in range(K):
          solver.append(S[i:i+j+1])
      else:
        for j in range(len(S)-i):
          solver.append(S[i:i+j+1])
  solver = list(set(solver))
  idx_pre_char += 1


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

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

l = []

for i in range(K):
    for j in range(len(s)-i):
        l.append(s[j:j+i+1])
l.sort()

ind = 0
cnt = 0
while cnt <K-1:
    if l[ind+1] != l[ind]:
        cnt += 1
    ind += 1
print(l[ind])

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(set(a))
c = []
INF = 97+26
for m in b:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        for j in range(k):
            if i + j >= len(s):
                break
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
                c.sort()
            if len(c) > 5:
                del c[-1]

    if len(c) >= k:
        break

print(c[k-1])

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(set(a))
c = []
INF = 97+26
for m in b:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        for j in range(k):
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
                c.sort()
            if len(c) > 5:
                del c[-1]
            j += 1
            if i + j >= len(s):
                break
    if len(c) >= k:
        break

print(c[k-1])

Solution (Python):

S = input()
K = int(input())
s_len = len(S)
s_set = set()
for i in range(1, s_len+1):
    j = 0
    if i > K:
        break
    else:
        while j+i <= s_len:
            s_set.add(S[j:j+i])
            j += 1
    
s_sort = sorted(list(s_set))
print(s_sort[K-1])

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

for i in range(len(s)):
    a.append(s[i])
    j = 2
    while i + j <= len(s) and j <= 5:
        a.append(s[i:i+j])
        j += 1
print(sorted(set(a))[K-1])

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

kn = len(s) * k
k_list = set(s)

for i in range(2, k+1):
    for j in range(len(s)):
        k_list.add(s[j:j+i])

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

Solution (Python):
s=input()
K=int(input())
As=sorted(set(s))
ans=[]
for A in As:
    ans.append(A)
    if len(ans)>=K:break
    for j in range(2,K+1):
        ind=0
        for i in s:
            if i==A:
                Judge=s[ind:ind+j]
                if len(Judge)==j and (Judge not in ans):
                    ans.append(Judge)
            ind+=1
print(sorted(ans)[K-1])

Solution (Python):

s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(k):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])

Solution (Python):


S = input()
N = int(input())
l = len(S)

sub = {}
for i in range(1,6):
    for j in range(0,l+1-i):
        temp = S[j:j+i]
        if temp not in sub:
            sub [temp]  = True

sub = list(sub.keys())
sub.sort()
print(sub[N-1])

Solution (Python):
s=input()
n=int(input())
l=["z" for i in range(5)]
for i in s:
  if l[4]>i and not i in l:
    l[4]=i
    l=sorted(l)
l2=[]
s+=" "
for i in range(len(s)-1):
  if s[i] in l:
    w=""
    for j in range(5):
      if s[i+j]==" ":
        break
      else:
        w+=s[i+j]
        l2.append(w)
l2=sorted(list(set(l2)))
print(l2[n-1])

Solution (Python):
S = input()

K = int(input())


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

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

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

print(L[k-1])

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

substrings = set()

for i in range(5):
    for j in range(len(s)):
        substring = s[j:j+i+1]
        substrings.add(substring)

answer = sorted(substrings)
print(answer[k-1])

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


sub_string = []
for i in range(len(s)):
    for j in range(0, len(s) + 1 - i):
        if j > K:
            break
        sub_string.append(s[i:i+j])


sub_string = set(sub_string)

sub_string = sorted(sub_string)

sub_string.remove('')
print(sub_string[K - 1])

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

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

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import collections
S=input()
k=I()
ans=[]
for i in range(len(S)):
    for j in range(1,k+1):
        ans.append(S[i:i+j])
ans=list(set(ans))
ans.sort()
print(ans[k-1])

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

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

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

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

Solution (Python):

import sys
import string
import itertools


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

    part_set = set()
    for c in string.ascii_lowercase:
        for i in range(len(s)):
            if c == s[i]:
                part_set |= set(itertools.accumulate(s[i:min(i+K,len(s))]))
        if len(part_set) >= K:
            print(sorted(part_set)[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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  k=I()

  l=[]

  for i in range(len(s)):
    l.append(s[i])
    l.append(s[i:i+2])
    l.append(s[i:i+3])
    l.append(s[i:i+4])
    l.append(s[i:i+5])

  l=list(set(l))
  l.sort()

  return l[k-1]

print(main())

Solution (Python):

l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

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

l2=[]

a=''
for x in l:
  if x in s:
    a=x
    for i in range(len(s)):
      if s[i]==a:
        for j in range(6):
          l2.append(''.join(s[i:i+j]))

l2=list(set(l2))
l2.remove('')
l2.sort()
print(l2[K-1])

Solution (Python):
s = raw_input()
chrindex = []
for i in range(0, 26):
	chrindex.append([])
for i in range(0, len(s)):
	chrindex[ord(s[i])-97].append(i)
K = int(raw_input())
sublist = []
for i in range(0, K):
	sublist.append('')
for i in range(0, 26):
	for j in range(0, len(chrindex[i])):
		word = ''
		for k in range(chrindex[i][j], len(s)):
			word = word + s[k]
			if sublist[-1] < word and sublist[-1] != '': break
			if word not in sublist:
				for p in range(0, K):
					if word < sublist[p]:
						for q in range(0, K-p-1):
							sublist[-1-q] = sublist[-2-q]
						sublist[p] = word
						break
					if sublist[p] == '':
						sublist[p] = word
						break
	if '' not in sublist: break
print sublist[-1]

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

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

subs = []
for j in range(K):
    for i in range(len(s)-j):
        new = s[i:i+j+1]
        if not(new in subs):subs += [new]
        
subs.sort()
print(subs[K-1])

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

subs = []
for j in range(K):
    for i in range(len(s)-j):
        new = s[i:i+j+1]
        if not(new in subs):subs += [new]
        
subs.sort()
print(subs[K-1])

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

Solution (Python):
s=input()
k=int(input())
n=len(s)
count=[]
for i in range(k):
    count.append('zzzzz')
for i in range(n):
    for j in range(k):
        for l in range(k):
            if s[i:i+j+1]==count[l]:
                break
            elif s[i:i+j+1]<count[l]:
                for m in range(k-1,l,-1):
                    count[m]=count[m-1]
                count[l]=s[i:i+j+1]
                break
print(count[k-1])

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

Solution (Python):

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

lst = []
for i in range(len(s)):
    for j in range(i+1, min(len(s)+1, i+1+K)):

        lst += [s[i:j]]

lst.sort()

k = 0
flag = 0
ans = str()
check = True
while check:
    if ans != lst[flag]:
        
        k += 1
    ans = lst[flag]
    
    flag += 1
    if k == K:
        ans = ''.join(ans)
        print(ans)
        check = not check

Solution (Python):
S = input()
K = int(input())
store = []
for i in range(len(S)):
  N = i+1
  while N <= i + 5:
    store.append(S[i:N])
    N += 1
store_set = set(store)
store_list = list(store_set)

List = [ x for x in store_list  if len(x) <= K ]
List.sort()
print(List[K-1])

Solution (Python):

import sys


def solve_(S: str, K: int, used):
    
    mn = 'z'
    tmp = set()
    for i, c in enumerate(S):
        if c < mn and not c in used:
            tmp = set()
            for j in range(5):
                tmp.add(S[i:i + j + 1])
            mn = c
        elif c == mn:
            for j in range(5):
                tmp.add(S[i:i + j + 1])
    if len(tmp) < K:
        used.append(mn)
        return solve_(S, K - len(tmp), used)
    else:
        tmp = list(tmp)
        tmp.sort()
        return tmp[K - 1]

def solve(S, K):
    ret = solve_(S, K, [])
    print(ret)
    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())
n = len(s)
a = []
for i in range(k):
    if n - i > 0:
        for j in range(n - i):
            a.append(s[j:j + i + 1])
a = list(set(a))
a.sort()
print(a[k-1])

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

l_s = len(s)
U = set()
for c in [chr(i) for i in range(97, 97+26)]:
    for i in range(l_s):
        if c == s[i]:
            for j in range(k):
                U.add(s[i:i + j + 1])
    if len(U) > 5:
        break
print(sorted(list(U))[k - 1])

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





def main():
    s = input()
    k = intin()

    nlist = [(ord(c), i) for i, c in enumerate(s)]
    nlist.sort()

    prev_oc = None
    slist = []

    for oc, i in nlist:
        kcount = len(slist)
        if prev_oc is not None and oc != prev_oc and kcount >= k:
            break
        for j in range(min(k, len(s) - i)):
            slist.append(s[i:(i+j+1)])
        slist = list(set(slist))
        prev_oc = oc

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

if __name__ == '__main__':
    main()

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

N = len(s)

alphabet = "abcdefghijklmnopqrstuvwxyz"

def search(k, start_dict):
    for chara in alphabet:
        if chara in start_dict:
            k -= 1
            if k == 0:
                return True, chara
            start_list = start_dict[chara]
            new_start_dict = {}
            for start in start_list:
                index = start + 1
                if index == N:
                    continue
                if s[start+1] in new_start_dict:
                    new_start_dict[s[index]].append(index)
                else:
                    new_start_dict[s[index]] = [index]
            has_found, ret = search(k, new_start_dict)
            if has_found:
                return True, chara + ret
            else:
                k = ret
    return False, k

start_dict = {}
for idx, chara in enumerate(s):
    if chara in start_dict:
        start_dict[chara].append(idx)
    else:
        start_dict[chara] = [idx]
_, ans = search(K, start_dict)
print(ans)

Solution (Python):

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

l = {s}
for n in range(1, K+1):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])
l = list(l)

l.sort()

print(l[K-1])

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

N = len(s)

li = []
for i in range(N):
    for j in range(5):
        if (i+j >= N):
            break
        li.append(s[i:i+j+1])
    li = sorted(list(set(li)))[:6]
    

print(li[K-1])

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def A():
    return


def B():
    return


def C():
    s = stdin.readline().rstrip()
    K = II() - 1
    ans = []
    for i in range(len(s)):
        for k in range(K+1):
            b = s[i:i + k + 1]
            ans.append(b)
    ans = list(set(ans))
    ans.sort()
    print(ans[K])
    return


def D():
    n, m = LI()
    p = LI_()
    xy = LIR_(m)
    size = [1 for _ in range(n)]
    height = [1 for _ in range(n)]
    par = [i for i in range(n)]
    def find(x):
        if par[x] == x:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    def union(x, y):
        s1 = find(x)
        s2 = find(y)
        if s1 != s2:
            if height[s1] < height[s2]:
                par[s1] = s2
                size[s2] += size[s1]
                size[s1] = 0
            else:
                par[s2] = s1
                size[s1] += size[s2]
                size[s2] = 0
                if height[s1] == height[s2]:
                    height[s1] += 1

    for x,y in xy:
        union(x, y)
    ans = 0
    for i in range(n):
        if find(p[i]) == find(i):
            ans += 1
    
    print(ans)
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    C()

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

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

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

Solution (Python):
def main():
    data = list(input())
    num = int(input())

    set_dic = set()
    for i in range(26):
        point = chr(97 + i)
        for j in range(len(data)):
            if data[j] == point:
                for k in range(min(len(data) - j, num)):
                    set_dic.add(''.join(data[j:j+k + 1]))
        if len(set_dic) >= num:
            break
    set_dic = list(set_dic)
    set_dic.sort()
    print(set_dic[num - 1])



if __name__ == '__main__':
    main()

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

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

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

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

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

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

print(sli[k-1])

Solution (Python):


def read_input():
    s = input()
    k = int(input())
    return s, k



def search_insertion(s, cands, l):
    result = []

    for i in range(len(s)):
        for c in cands:
            if s[i:i+l].startswith(c):
                result.append(s[i:i+l])

    cands.extend(result)
    cands = list(set(cands))
    return cands


def sort_s(cands):
    t = [[c for c in s] for s in cands]
    t.sort()
    return [''.join(s) for s in t]


def submit():
    s, k = read_input()

    cands = list(set([c for c in s]))
    precands = None
    for i in range(2, len(s) + 1):
        cands = search_insertion(s, cands, i)
        cands = sort_s(cands)
        cands = cands[:k]

        if precands == cands:
            break
        precands = cands[:]

    print(cands[-1])

if __name__ == '__main__':
    submit()

Solution (Python):

import sys
import heapq


def solve(s: str, K: int):
    pq = []
    for i, c in enumerate(s):
        heapq.heappush(pq, (c, i))

    ret = set()
    while len(ret) < K:
        cs, i = heapq.heappop(pq)
        ret.add(cs)
        if i < (len(s) - 1):
            heapq.heappush(pq, (cs + s[i+1], i+1))
    ret = sorted(list(ret))
    print(ret[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()
k = int(input())
ans = []
for i in range(1,k+1):
  for j in range(len(s)):
    if j+i > len(s): break

    ans.append(s[j:j+i])


ans = list(sorted(set(ans))) 

if k != 1:
  print((ans[k-1]))
else:
  print(min(list(s)))

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

l = {s}
for n in range(1, K+1):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])

l = list(l)

l.sort()

print(l[K-1])