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()
N = len(s)
K = int(input())
ords = [ord(_s) for _s in s]
order_set = sorted(list(set(ords)))
d = set()
def add_string(o):
  for i in range(N):
    if ords[i] == o:
      for k in range(1, K+1):
        d.add(s[i:i+k])

add_string(order_set[0])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

add_string(order_set[1])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

add_string(order_set[2])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

Solution (Python):
import sys

import bisect





from operator import attrgetter, itemgetter





readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    k = int(input())
    l = len(s)

    strs = set()

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

    strl = list(strs)
    strl.sort()

    print(strl[k - 1])


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
k=int(input())
cnt = 0
ans = set([])
head  = sorted(list(set(list(s))),reverse=True)
while cnt < k:
    tmp_h = head.pop()
    for n,i in enumerate(s):
        if i==tmp_h:
            for j in range(min(k,len(s)-n)):
                ans.add(s[n:n+j+1])
    cnt = len(ans)
ans = sorted(list(ans))
print(ans[k-1])

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

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
import heapq

def main():
    s = input().strip()
    n = len(s)
    stq = set()
    k = int(input().strip())
    for i in range(n):
        for j in range(i+1, min(i+1+k+1, n+1)):
            stq.add(s[i:j])
    stq = list(stq)
    heapq.heapify(stq)
    for i in range(k):
        ans = heapq.heappop(stq)
        if i == k-1:
            print(ans)

if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
s=input()
k=int(input())
ans=["zzzzzz"]*k
for i in range(len(s)):
  for j in range(i,min(i+8,len(s))):
    A=s[i:j+1]
    if A>ans[k-1]:
      continue
    if A in ans:
      continue
    for ii in range(k):
      if A<ans[ii]:
        break
    for jj in range(k-1,ii,-1):
      ans[jj]=ans[jj-1]
    ans[ii]=A
print(ans[-1])

Solution (Python):
def Kth_Substring(s , k):

    ans = []
    sset = set()

    for i in range(len(s)):
        for w in range(1, k + 1):
            sset.add(s[i:i + w])
    ans = sorted(list(sset))
    return ans[k - 1]

def main():
    s = str(input())
    k = int(input())
    print(Kth_Substring(s , k))

if __name__ == '__main__':
    main()

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

se = set()

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

l = sorted(list(se))
print(l[k-1])

Solution (Python):
s = input()
k = int(input())
strings = set()
for start in range(len(s)):
    for end in range(start+1, start+1+k):
        moji = s[start:end]
        strings.add(moji)

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

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

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

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

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

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

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

Solution (Python):




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

    for i in range(5):
        for j in range(len(S)):
            result.add(S[j:j + i + 1])

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


if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(s, pos):
    global N, K
    ns = {}
    if len(A) > K:
        return
    for i in pos:
        ni = i + 1
        if ni < N:
            x = s + S[ni]
            if x in ns:
                ns[x].append(ni)
            else:
                ns[x] = [ni]
    candidate = []
    for x in list(ns.keys()):
        candidate.append((x, ns[x]))
    candidate.sort()
    for c, idx in candidate:
        A.add(c)
        dfs(c, idx)


S = list(input())
N = len(S)
K = int(input())
alpha = [chr(ord('a') + i) for i in range(26)]

A = set()
for c in alpha:
    if len(A) < K:
        pos = []
        for i, s in enumerate(S):
            if c == s:
                A.add(c)
                pos.append(i)
        dfs(c, pos)

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

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

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

for i, s in enumerate(sorted(ss), start=1):
    if i == k:
        print(s)
        break

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

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

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

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

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

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

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

Solution (Python):
s=input()
k=int(input())
se=set()
for i in range(len(s)):
    for j in range(1,6):
        if(i+j<=len(s)):
           se.add(s[i:i+j])
    
li=sorted(se)

print(li[k-1])

Solution (Python):

s = input()
k = int(input())
ans = set()

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

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

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

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

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

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

res = sorted(list(lst))
print(res[K-1])

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

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

ln = len(s)
ans = set()

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

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

Solution (Python):
s = list(input())
k = int(input())
t = sorted(s)
u = []
v = []
for i in range(min(len(s), 5)):
    u.append(t[i])
for i in range(len(s)):
    if s[i] in u:
        if not [s[i]] in v:
            v.append([s[i]])
        l = [s[i]]
        for j in range(1, 5):
            if i + j == len(s):
                break
            l = l + [s[i + j]]
            if not l in v:
                v.append(l)
for i in range(len(v)):
    v[i] = "".join(v[i])
v.sort()
print(v[k - 1])

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    s = input().rstrip()
    K = int(input())
    a = sorted(set(s))
    res = set()
    n = len(s)
    for i in a:
        res.add(i)
        if len(res)>=K:
            res = sorted(res)
            print(res[K-1])
            exit()
        for j in range(n):
            if s[j] == i:
                for k in range(1, 5):
                    res.add(s[j:j+k+1])
        if len(res)>=K:
            res = sorted(res)
            print(res[K-1])
            exit()



if __name__ == '__main__':
    main()

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

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

substring = []

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

substring = list(set(substring))
substring.sort()


print(substring[k-1])

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

substring = []

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

substring = list(set(substring))
substring.sort()



print(substring[k-1])

Solution (Python):
import sys
sys.setrecursionlimit(20000000)

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


def calculate(str, k):
    s = sorted(list(set(str)))
    criteron = s[:k]
    objs = {}
    for index, s in enumerate(str):
        if s in criteron:
            if len(str)+1 > index + 1 + k:
                made = index + 1 + k
            else:
                made = len(str)+1
            for i in range(index+1,made):
                objs.__setitem__(str[index:i],True)

    arr = sorted(objs.keys())

    print(arr[k-1])

calculate(s, K)

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

substring = []

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

substring = list(set(substring))
substring.sort()
substring.pop(0)

print(substring[k-1])

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import Counter

s = ns()
n = len(s)
k = ni()

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

c = Counter(l)
uni = list(c)
uni.sort()
print(uni[k - 1])

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

for i in range(min(N,K)):
    for j in range(N-i+1):
        substring.append(s[j:j+i+1])

substring = list(set(substring))
substring.sort()
substring.pop(0)

print(substring[K-1])

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

l = []
for i in range(len(s)):
    for y in range(k):

        if not ''.join(s[i:i+y+1]) in l:
            l.append(''.join(s[i:i+y+1]))

l.sort()
if not l:
    print(s[0])
else:
    print(l[k-1])

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

ss = []
for i in range( 1,K+1 ):
  for j in range( len(S)-i+1 ):
    ss.append(S[j:j+i])
ss.sort()
pre = '@'
for a in ss:
  if pre == a: continue
  pre = a
  K -= 1

  if K==0:
    print(a)
    break

Solution (Python):
s=input()
 
n=int(input())
 
ans = []
 
for i in range(len(s)):
    for j in range(1,7):
        if s[i:i+j] not in ans and j <= len(s):
            ans.append(s[i:i+j])
ans.sort()

print(ans[n-1])

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

L = list("abcdefghijklmnopqrstuvwxyz")

def dictmin(p,q):
    ret = -1
    for i in range(len(p)):
        if i >= len(q):
            ret = q
            break
        elif L.index(p[i]) < L.index(q[i]):
            ret = p
            break
        elif L.index(p[i]) > L.index(q[i]):
            ret = q
            break
    if ret == -1:
        ret = p
    return ret

def renew(X,p):
    for i in range(K):
        if X[i] == p:
            break
        elif dictmin(X[i],p) == p:
            for j in range(K-1,i,-1):
                X[j] = X[j-1]
            X[i] = p
            break
    return X
        
count = 0
can = [["z"]*6 for i in range(K)]

for x in L:
    for i in range(N):
        if s[i] == x:
            count += N-i
            for j in range(i,min(i+5,N)):
                
                can = renew(can,s[i:(j+1)])
                
    if can[K-1] != ["z"]*6:
        break

print("".join(can[K-1]))

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






t=["zzzzz"]*k

for i in range(len(s)):
    for j in range(i,min(len(s),i+k)):
        sij=s[i:j+1]
        for kk in range(k):
            if t[kk]==sij:
                break
        if t[kk]>sij:
            t[kk]=sij
            t.sort()
        
print(t[k-1])

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

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

Solution (Python):














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






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

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

Solution (Python):
s = input()
k = int(input())
a = []
for i in range(len(s)+1):
    for j in range(len(s)+1):
        if j <= k:
            a.append(s[i:i + j])

c = sorted(set(a))

print(c[k])

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

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

Solution (Python):
from heapq import heappush, heappop
s = input()
K = int(input())
N = len(s)
heap = []
cnt = 0
for i in range(N):
	for j in range(i+1, min(i+K+1, N+1)):
		heappush(heap, s[i:j])

l = list(set(heap))
l.sort()
print(l[K-1])

Solution (Python):
from heapq import heappush, heappop
s = input()
K = int(input())
N = len(s)
heap = []
cnt = 0
for i in range(N):
	for j in range(i+1, min(i+K+1, N+1)):
		heappush(heap, s[i:j])

already = []
while True:
	w = heappop(heap)
	if w not in already:
		already.append(w)
	if len(already)>=K:
		break

print(already[-1])

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007



def main():
	s = input()
	s = s[:-1]
	k = inputInt()

	stringss = []
	for i in range(len(s)):
		for j in range(i+1,i+6):
			tmp = s[i:j]
			if tmp in stringss:
				pass
			else:
				stringss.append(tmp)

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







def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Solution (Python):
s = input()
K = int(input())
l = []
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    for j in range(i, len(s)):
        d = s[i:j+1]
        l.append(d)
        if len(d) >= K:
            break
l = list(set(l))
l.sort()
print(l[K-1])

Solution (Python):
def main():
  s=input()
  k=int(input())
  l=len(s)
  
  substr=set()
  for alpha in 'abcdefghijklmnopqrstuvwxyz':
    for i in range(l):
      if s[i]==alpha:
        sub=s[i]
        substr.add(sub)
        j=i+1
        cnt=0
        while j<l and cnt<6:
          sub+=s[j]
          substr.add(sub)
          j+=1
          cnt+=1
    if len(substr)>k:
      break
      
  substr=list(substr)
  substr.sort()
  print(substr[k-1])
if __name__=='__main__':
  main()

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

ans = []

for index, i in enumerate(s):
  ans.append(i)

  count = 1
  now = i
  for indexs, k in enumerate(s):
    if indexs <= index:
      continue
      
    if count >= 5:
      break

    now += k
    ans.append(now)
    count += 1

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

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

Solution (Python):
import re

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

if __name__ == '__main__':
    main()

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

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

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

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

substring = list(set(substring))
substring.sort()


print(substring[K-1])

Solution (Python):
s=input()
K=int(input())
x=[]
for i in range(5):
  x.extend(list({s[j:j+i+1] for j in range(len(s)-i)}))
x=sorted(x)
print(x[K-1])

Solution (Python):
S = input()
n = len(S)
k = int(input())
cnt = 0
itl = sorted(list(set(S)))
ans = set([])
for w in itl:
    for i, s in enumerate(S):
        if s != w:
            continue
        else:
            for j in range(i+1, i+k+1):
                ans.add(S[i:j])
    cnt += len(ans)
    if cnt >= k:
        break
    else:
        ans.clear()

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

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

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


A = sorted(set(A))

print(A[k-1])

Solution (Python):
S=input()
K=int(input())
L=[""]
for s in range(len(S)):
    for e in range(s,len(S)):
        
        if S[s:e+1] in L:
            continue
        if len(L)>K:
            if S[s:e+1]>L[K]:
                break
        if S[s:e+1] not in L:
            if len(L)<=K:
                L.append(S[s:e+1])
                L.sort()
            else:
                L.append(S[s:e+1])
                L.sort()
                L=L[:K+1]
                
print(L[-1])

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

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

A=[]

for i in range(N):
    for j in range(K):
        r=i+j+1
        if r>N:
            break
        A.append(s[i:r])
        
AA=list(set(A))
AA.sort()
print(AA[K-1])

Solution (Python):
def main():
    string = input()
    range_ = int(input())
    substrings = []
    for i in range(len(string)):
        for j in range(1, range_ + 1):
            substrings.append(string[i:i + j])
    substrings = list(set(substrings))
    substrings.sort()
    print(substrings[range_ - 1])


if __name__ == '__main__':
    main()

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

N = len(s)

ans = []
for i in range(1,K+1):
    for j in range(N-i+1):
        ans.append(s[j:j+i])

ans = list(set(ans))
ans.sort()
print(ans[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:
            ans.append(s[i:i+j]) 
ans=sorted(list(set(ans)))
print(ans[k-1])

Solution (Python):
from heapq import heappop, heapify

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

sub = set()
for i in range(N):
  for j in range(5):
    if i+j+1 <= N:
      sub.add(s[i:i+j+1])

sub = list(sub)
heapify(sub)
for i in range(K-1):
  _ = heappop(sub)
print(heappop(sub))

Solution (Python):
s=list(map(str,input()))
A=int(input())
V=[]
S=[]
ct=0
for i in range(1,A+1):
  for j in range((len(s)-(i-1))):
    V.append("".join(s[j:j+i]))
S=sorted(set(V))

print(S[A-1])

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

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

l = list(t)
l.sort()
print(l[n - 1])

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

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

tmp = []

s_len = len(S)
for i in range(s_len):
    for j in range(i,i+min(K,s_len-i)):
        
        
        tmp.append(S[i:j+1])

str_set = set(tmp)

for i,s in enumerate(sorted(str_set)):
    if i == K-1:
        print(s)
        break

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

l = []
for i in range(len(s)):
    for j in range(1, 6):
        if i + j > len(s): break
        l.append(s[i : i + j])
l.sort()
cnt = 0
idx = 0
for i in range(len(l)):
    sub = 0
    while idx + sub < len(l) and l[idx] == l[idx + sub]: sub += 1
    cnt += 1
    if cnt == k:
        print(l[idx])
        break
    idx += sub

Solution (Python):
from itertools import product
s = input()
k = int(input())
anss = []
for bit in product(list(range(len(s)+1)), repeat=2):
    if k >= bit[1] - bit[0] > 0:
        if bit[0] < bit[1] and s[bit[0]:bit[1]] not in anss:
            anss.append(s[bit[0]:bit[1]])

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

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

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

x = dict()
y = []
for i in range(5000):
    y.append([])


"""
for i in range(n):
    t = ""
    for j in range(i,n):
        t += s[j]
        if len(t) in x:
            if t not in y[len(t)]:
                y[len(t)].append(t)
        else:
            x[len(t)] = t
            y[len(t)].append(t)
X = []
for i in range(5000):
    if len(y[i]) == 0:
        continue
    y[i].sort()
    for j in range(len(y[i])):
        X.append(y[i][j])
"""
for i in range(n):
    t = ""
    for j in range(i,i+1+K):
        if j > (n-1):
            break
        t += s[j]
        x[t] = t
X = []
for i in x:
    X.append(i)
X.sort()



print(X[K-1])

Solution (Python):
s = input()
K = int(input())
 
sub = []
for l in range(1,6):
  for st in range(0,len(s)+1-l):
    sub.append(s[st:st+l])

sub_set = list(set(sub))
sub_set.sort()
print(sub_set[K-1])

Solution (Python):
s = input()
K = int(input())
idx = [[] for _ in range(26)]

for i in range(len(s)):
    idx[ord(s[i])-ord("a")].append(i)

substr = set()
for i in range(26):
    for j in idx[i]:
        for k in range(j+1,j+6):
            substr.add(s[j:k])
    if len(substr) >= K:
        substr = sorted(list(substr))
        break

print(substr[K-1])

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

Solution (Python):
s = list(input())
l = int(input())
s1 = sorted(s)
ans = set()

for i in range(len(s)):
    sta = s1[i]
    for j in range(len(s)):
        if s[j] == sta:
            ans.add(s[j])
            check = s[j]
            for k in range(j+1,min(len(s),j+5)):
                check = check+s[k]
                ans.add(check)
    if len(ans) >= l:
        ans1 = sorted(ans)
        print(ans1[l-1])
        exit()
ans1 = sorted(ans)
print(ans1[l-1])

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

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

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

Solution (Python):



s = str(input())
K = int(input())
ans = []
N = len(s)

for i in range(N):
  y = min(N + 1, i + K + 1)
  for j in range(i + 1,y):
    x = s[i:j]
    if x not in ans:
      ans.append(x)

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

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

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

print(dct[k])

Solution (Python):
S=input()
s=len(S)
K=int(input())
A=[]
for i in range(s):
  A.append(S[i])
for i in range(s-1):
  A.append(S[i:i+2])
for i in range(s-2):
  A.append(S[i:i+3])
for i in range(s-3):
  A.append(S[i:i+4])
for i in range(s-4):
  A.append(S[i:i+5])
B=sorted(set(A))
print(B[K-1])

Solution (Python):
import bisect
ALP = 'abcdefghijklmnopqrstuvwxyz'

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

N = len(S)
substr = []
for i in range(N):
    for j in range(i, min(i + 5, N)):
        tmp_substr = S[i:j+1]

        if tmp_substr in substr:
            continue

        if len(substr) <= 4:
            substr.append(tmp_substr)
            substr.sort()
        else:
            substr.append(tmp_substr)
            substr.sort()
            del substr[-1]

print(substr[K-1])

Solution (Python):
def main():
    s = input()
    K = int(input())
    print(sorted(list({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):
def main():
    s = input()
    K = int(input())
    lst = sorted(list(set(s)))
    ans = []

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

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


main()

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

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

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


main()

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:
                    return dfs(c + li)
        return

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


main()

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)
        return

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


main()

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[K - 1])
    return


main()

Solution (Python):
def main():
    s = input()
    K = int(input())
    lst = sorted(set(s))
    ans = ""
    cnt = 0

    def dfs(sub):
        nonlocal cnt, ans
        if cnt < K:
            ans = sub
            cnt += 1
            for li in lst:
                if sub + li in s:
                    dfs(sub + li)

    for li in lst:
        dfs(li)
    print(ans)
    return


main()