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().strip()
N = len(S)
K = int(input()) - 1

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

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

if __name__ == "__main__":
    main()

Solution (Python):






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





mylist = []
length = len(s)
for i in range(length):
    for j in range(i,min(length, i+K)):
        mylist += [s[i:j+1]]
mylist_s = sorted(list(set(mylist)))
print(mylist_s[K-1])

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

len_s =  len(s)
L = []
m = 0
for i in range(1, k+1):
    for j in range(len_s-i+1):
        if s[j:j+i] not in L:
            L.append(s[j:j+i])


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

Solution (Python):
import sys
def input():
  return sys.stdin.readline().rstrip()

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

vec=set()

for i in range(len(S)):
  for j in range(i+1,min(len(S)+1,K+i+1)):
    tmp=S[i:j]
    vec.add(tmp)
vec=list(vec)
vec.sort()

print(vec[K-1])

Solution (Python):
import sys
def input():
  return sys.stdin.readline().rstrip()

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

vec=[]
for i in range(len(S)):
  for j in range(i+1,K+i+1):
    tmp=S[i:j]
    if not tmp in vec:
      vec.append(tmp)
vec.sort()

print(vec[K-1])

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

A = set()
for i in range(N):
    for j in range(1, min(5+1, N-i+1)):
        A.add(s[i:i+j])

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

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

ans_list = []
for i in range(len(s)):
    for j in range(i+1,i+K+1):
        if j < len(s)+1:
            ans_list.append(s[i:j])

ans_set = set(ans_list)
ans_list_min = sorted(list(ans_set))

print(ans_list_min[K-1])

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

cand = set()
for i in range(len(s)):
  for j in range(i+1, i+k+1):
    if j >len(s):
      continue
    cand.add(s[i:j])
listcand = list(cand)
listcand.sort()
print(listcand[k-1])

Solution (Python):
s = input()
K = int(input())
ans_lis = []
s_length = len(s)
lis = [[] for i in range(26)]

for i in range(s_length):
    lis[ord(s[i]) - ord('a')].append(i)


for i in range(26):
    k = 1
    while k <= K:
        for j in lis[i]:
            ans_lis.append(s[j:j + k])
        k += 1
        ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()

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

N = len(s)

d = dict()
for i in range(N):
    for j in range(i, min(N, i+K)):
        sub = s[i:j+1]
        if d.get(sub) == None:
            d[sub] = 1

d2 = sorted(d.items())
print(d2[K-1][0])

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

N = len(s)

d = dict()
for i in range(N):
    for j in range(i, min(N,i+K)):
        sub = s[i:j+1]
        if d.get(sub) == None:
            d[sub] = 1

d2 = sorted(d.items())
print(d2[K-1][0])

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

n = len(S)

ans = set()

for i in range(n):
    for j in range(i, min(i+5, n)):
        ans.add(S[i:j+1])

ans = list(ans)
ans.sort()

print(ans[K-1])

Solution (Python):
S=input()
N=len(S)
K=int(input())
A=[]
for i in range(1,K+1):
    j=0
    while j+i<=N:
        A.append(S[j:j+i])
        j+=1
A=list(set(A))
A.sort()
print(A[K-1])

Solution (Python):
def suuji(a):
  ans=0
  for i in range(len(a)):
    ans+=(ord(a[i])-96)*(27**(5-i))
  return ans
def alpha(a):
  ans=''
  while a>0:
    b = chr((a%27)+96)
    if b!='`':
      ans+=chr((a%27)+96)
    a//=27
  return ans[::-1]
g = []
s=input()
k=int(input())
for i in range(len(s)):
  for j in range(1,min(6,len(s)+1)):
    if i+j>len(s):
      break
    g.append(suuji(s[i:j+i]))
g = sorted(set(g))
print(alpha(g[k-1]))

Solution (Python):

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

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

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


if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



S=input()
N=len(S)
K=intput()
L=[list()]*26
ans=[]
for i in range(N):
    L[ston(S[i])].append(i)
for l in L:
    for i in l:
        for j in range(i+1,min(i+K+1,N+1)):
            s=S[i:j]
            if bisect_left(ans,s)==bisect_right(ans,s):
                insort_left(ans,s)
    if len(ans)>=K:
        print(ans[K-1])
        exit()

Solution (Python):
s = str(input())
K = int(input())
L = []
M = []
con = 0
for i in s:
  L.append(i)
L = list(set(L))
L.sort()
for j in range(len(s)):
    if s[j] == L[0]:
      for k in range(1,6):
        if j + k >=len(s):
          M.append(s[j:])
          break
        else:
          M.append(s[j:j+k])
if len(L) != 1:
  for l in range(len(s)):
    if s[l] == L[1]:
      for m in range(1,6):
        if l + m >= len(s):
          M.append(s[l:])
          break
        else:
          M.append(s[l:l+m]) 
if len(M) < K:
  for n in range(len(s)):
    if s[n] == L[2]:
      for o in range(1,6):
        if n + o >=len(s):
          M.append(s[n:])
          break
        else:
          M.append(s[n:n+o])
M = list(set(M))
M.sort()
print(M[K - 1])

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

for i in range(n):
    for j in range(1,k+1):
        if i+j > n: break
        qq.add(s[i:i+j])

qq=sorted(qq)

print(qq[k-1])

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)









INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        heappush(pos[s], S[i:])
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        while pos[l]:
            sub = heappop(pos[l])
            for i in range(1, len(sub)+1):
                dic.add(sub[:i])

            if len(dic) >= K:
                dic = sorted(list(dic))
                print(dic[K - 1])
                return



if __name__ == "__main__":
    run()

Solution (Python):
S = input()
K = int(input())
S_list = []

for j in range(K):
    for i in range(0,len(S)-j):
        S_list.append(S[i:i+j+1])
S_list = set(S_list)
print(list(sorted(S_list))[K-1])

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

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

Solution (Python):
s = list(input())
K = int(input())
s = list(map(lambda x: ord(x), s))
sub_s = []
for length in range(1, 6):
    for i in range(len(s) - (length - 1)):
        sub_s.append(s[i:i+length])
sub_s.sort()
k = 1
ans = sub_s[0]
for sub in sub_s:
    if ans == sub:
        if k == K:
            break
        continue
    ans = sub
    k += 1
    if k == K:
        break
for c in ans:
    print(chr(c), end="")

Solution (Python):
def main():
    S = input()
    K = int(input())
    ans = []
    def dfs(s):
        if len(s) > K:
            return
        for i in range(97,123):
            tmp = s + chr(i)
            if tmp in S:
                ans.append(tmp)
                dfs(tmp)

    
    dfs('')
    ans.sort()
    print(ans[K-1])



if __name__ == "__main__":
    main()

Solution (Python):
def main():
    S = input()
    K = int(input())
    ans = []
    def dfs(s,cnt):
        res = cnt 
        if len(s) > K:
            return
        for i in range(97,123):
            tmp = s + chr(i)
            if tmp in S:
                res += 1
                ans.append(tmp)
                if res == K:
                    return
                dfs(tmp,res)

    
    dfs('',0)
    ans.sort()
    print(ans[K-1])



if __name__ == "__main__":
    main()

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

for i in range(len(s)):
    for j in range(k):
        lis.append("".join(s[i:i + j + 1]))
lis = sorted(list(set(lis)))

print(lis[k - 1])

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

dic = {}
for i in range(1,6):
    for j in range(len(s)+1-i):
        dic.setdefault(s[j:j+i],0)
        dic[s[j:j+i]] += 1
sort_dic = sorted(dic)
print(sort_dic[k-1])

Solution (Python):
'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,K+1):
    for j in range(len(s)-i+1):
      d.append(s[j:j+i])
  ans=sorted(list(set(d)))
  print(ans[K-1])
  return
main()

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

Solution (Python):



def main():
    s = input()
    n = len(s)
    k = int(input())
    candidates = set()

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

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


if __name__ == '__main__':
    main()

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


a = set()

for i in range(len(S)):
    for j in range(1, 6):
        if i + j > len(S):
            break
        a.add(S[i:i + j])

ans = sorted(list(a))

print(ans[K - 1])

Solution (Python):
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter



input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    s = getS()
    k = getN()

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

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


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

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

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

Solution (Python):
def solve(s, k):
    z = set()
    for i in range(1, k+1):
        for j in range(len(s)-i+1):
            z.add(s[j:j+i])
    return sorted(list(z))[k-1]


def main():
    s = input()
    k = int(input())
    result = solve(s, k)
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
from bisect import insort

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

T=[]
N=len(S)
for  i in range(N):
    V=""
    for j in range(i,min(i+K,N)):
        V+=S[j]
        if V not in T:
            insort(T,S[i:j+1])
            T=T[:K]
print(T[-1])

Solution (Python):
from collections import defaultdict
s = input()
k = int(input())
dd = {}
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    dd[s[i]] = 1
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        if j-i+1 <= k:
            dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Solution (Python):
from collections import defaultdict
s = input()
k = int(input())
dd = {}
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    dd[s[i]] = 1
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        if j-i+1 <= k:
            dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    s = input()
    K = read_int()
    min5 = []
    for i in range(len(s)):
        for j in range(i+1, min(len(s), i+K)+1):
            min5.append(s[i:j])
        min5 = sorted(set(min5))
        while len(min5) > K:
            min5.pop()
    return min5[-1]


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

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


kouho=["zzzzzzz"]*k

for i in range(len(s)):
    tmp=""
    if s[i]<kouho[-1]:
        for j in range(min(k,len(s)-i)):
            tmp+=s[i+j]
            kouho.append(tmp)

        kouho=list(set(kouho))
        kouho.sort()
        kouho=kouho[:k]

print(kouho[-1])

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    s =input()
    k = int(input())
    cnt = 0
    mci = 0
    while cnt < k:
        mci = min([ord(i) for i in s if ord(i) > mci])
        a = set()
        for i in range(len(s)):
            if ord(s[i]) != mci:
                continue
            for j in range(1, 6):
                a.add(s[i:i+j])
        if len(a) + cnt < k:
            cnt += len(a)
        else:
            print(sorted(a)[k-cnt-1])
            return


main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    A = set()
    L = len(S)
    for i in range(L):
        for k in range(K):
            if i+k<=L:
                A.add(S[i:i+k+1])
    A = list(A)
    A.sort()
    print(A[K-1])


if __name__ == '__main__':
    main()

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
s = input()
k = ni()
n = len(s)
l = set()
for i in range(k):
    for j in range(0,n-i):
        l.add(s[j:j+i+1])
ls = sorted(list(l))
print(ls[k-1])

Solution (Python):
import sys
import heapq

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

ls = len(s)
q = []
exists = set()
for i in range(26):
    ini = chr(ord("a") + i)
    for j in range(ls):
        if s[j] == ini:
            k = 0
            while k < K and j + k < ls:
                tmp = s[j:j+1+k]
                if tmp not in exists:
                    heapq.heappush(q, s[j:j+1+k])
                    exists.add(tmp)
                k += 1

    if K <= len(q):
        break


for i in range(K-1):
    heapq.heappop(q)
print(q[0])

Solution (Python):
s = input()
K = int(input())
str_list = []
for i in range(len(s)):
    for j in range(K):
        str_list.append(s[i:i + j + 1])
str_list = sorted(list(set(str_list)))

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

Solution (Python):
def main():
    S = input()
    K = int(input())
    n = len(S)
    ALL = set()
    
    cnt = 0
    for i in range(n):
        for j in range(1,K+1):
            if i+j<=n:
                ALL.add(S[i:i+j])

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

main()

Solution (Python):
from collections import deque
s=input()
s_list=list(s)
length=len(s)
K=int(input())
o=[]
x=deque(sorted(set(s)))

while len(o) < K:
    letter=x.popleft()
    X=[i for i , x in enumerate(s_list) if x==letter]
    for i in X:
        for j in range(i+1,length+1):
            if not s[i:j] in o:
                o.append(s[i:j])
            if j-1-i == 5:
                break

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

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

orders = set()

for i in range(n):
    for j in range(1, 6):
        if i + j < n + 1:
            orders.add(S[i:i + j])

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

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

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

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

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

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

cnt = 0
alps = 'abcdefghijklmnopqrstuvwxyz'
for alp in alps:
    inds = []
    for i,si in enumerate(s):
        if si == alp:
            inds.append(i)
    if inds:
        s_set = set()
        for ind in inds:
            for i in range(1,6):
                if ind+i <= len(s):
                    s_set.add(s[ind:ind+i])
        sl = list(s_set)
        if cnt + len(sl) >= k:
            sl.sort()
            print(sl[k-cnt-1])
            exit()
        else:
            cnt += len(sl)

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

ans = set()
for i in range(1, K + 1):
    for j in range(N - i + 1):
        ans.add(S[j : j + i])
print(sorted(ans)[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):
s = str(input())
k = int(input())

n = len(s)
S = set()
import heapq

for i in range(n):
    for j in range(i+1, n+1):
        if j-i > k:
            continue
        t = s[i:j]
        S.add(t)
S = list(S)

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

Solution (Python):
def solve():
  S = input()
  K = int(input())
  lis = set()
  for i in range(len(S)):
    for p in range(1,K+1):
      j = i+p
      if j>len(S):
        continue
      lis.add(S[i:j])
  ans = sorted(list(lis))[K-1]
  return ans
print(solve())

Solution (Python):
import collections
s = input()
k = int(input())
dd = collections.defaultdict(int)

for i in range(len(s)):
    tmp = ""
    for j in range(5):
        if(j+i < len(s)):
            tmp += s[j+i]
            dd[tmp]+=1
print(sorted(dd)[k-1])

Solution (Python):
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    s = input()
    n = len(s)
    k = ii()
    a = set()
    for i in range(1, k+1):
        for j in range(n):
            a.add(s[j:j+i])
    print(sorted(a)[k-1])
    
        
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
k = int(input())
lis = ['z'*(5001+i) for i in range(k)]
for i in range(len(s)):
  c = s[i]
  if lis[-1] > c:
    lis.append(c)
    lis = set(lis)
    lis = sorted(lis)[:k]
  else:
    continue
  for j in range(i+1,len(s)):
    if lis[-1] > c:
      c += s[j]
      lis.append(c)
      lis = set(lis)
      lis = sorted(lis)[:k]
    else:
      break
print(lis[-1])

Solution (Python):
s=list(input())
k=int(input())
S=sorted(set(s))
t=0
l=[]
can=[]
while len(can)==0:
    for i in range(len(s)):
        if s[i]==S[t]:
            l.append(i)
    for i in l:
        for j in range(1,k+1):
            if i+j<=len(s) and s[i:i+j] not in can:
                can.append(s[i:i+j])
    if len(can)<k:
        k -= len(can)
        t += 1
        can=[]
        l=[]
can.sort()
ans=can[k-1]
print(''.join(ans))

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



Q=set()


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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()
    K = I()

    l = [[] for _ in range(26)]
    for i in range(len(s)):
        l[ord(s[i])-ord('a')].append(i)

    for i in l:
        tmp = set()
        for j in i:
            for k in range(5):
                if j + k <= len(s) - 1:
                    tmp.add(s[j:j+k+1])
        tmp = list(tmp)
        tmp.sort()
        if len(tmp) >= K:
            print(tmp[K-1])
            break
        else:
            K -= len(tmp)

if __name__ == '__main__':
    resolve()

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

ssort = sorted(set(s))
cnt, ans = 0, set()
while len(ans) < k:
    for i, si in enumerate(s):
        if si == ssort[cnt]:
            ans |= {s[i:i + j + 1] for j in range(k)}
    cnt += 1
print(sorted(ans)[k - 1])

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    S = getS()
    k = getN()


    li = []
    for i in range(len(S)):
        for j in range(1, k + 1):
            if i + j > len(S):
                continue
            li.append(S[i:i+j])

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


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

Solution (Python):
s=input()
k=int(input())
found=[]
now="zzzzzzzzz"

while len(found)<k:
    now="zzzzzzzzzz"
    for i in range(len(s)):
        c=s[i]
        f=1
        while c in found and i+f<len(s):
            c+=s[i+f]
            f+=1
        if not c in found:
            now=min(c,now)
        
    found.append(now)
print(found[-1])

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    t = s[i]
    a.add(t)
    if i < len(s) - 1:
        for j in range(i+1, min(i+k+1,len(s))):
            t += s[j]
            a.add(t)
b = sorted(list(a))
print(b[k-1])

Solution (Python):






s = list(input())
k = int(input())
d = {}
for i in range(len(s)):
    for j in range(i, min(i + k, len(s))):
        t = "".join(s[i:j + 1])
        if t not in d:
            d[t] = True
dk = sorted(d.keys())
print(dk[k - 1])

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

li = []
for i in range(5):
    li.extend([s[j:j+i+1] for j in range(n-i)])
li = list(set(li))
li.sort()
print(li[k-1])

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
k = int(input())
n = len(s)
l = []
for i in range(5):
    l.extend([s[ii:(ii+i+1)] for ii in range(n-i)])
l = list(set(l))
l.sort()
ans = l[k-1]
print(ans)

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

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

sub=sorted(sub)
print(sub[k-1])

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

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

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

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

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,ns):
  global cnt
  if ns in s:
    cnt+=1
  if cnt==k:
    print(ns)
    exit()
  if keta==k:
    return

  for i in abc:
    dfs(keta+1,ns+i)

cnt=0
for i in abc:
  if i not in s:
    continue
  dfs(1,i)

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

Solution (Python):
S = input().strip()
N = len(S)
K = int(input())
A = []
for k in range(1,min(6,N+1)):
    for i in range(N-k+1):
        x = S[i:i+k]
        if x not in A:
            A.append(x)
A = sorted(A)
print(A[K-1])

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

s = list(input())
K = int(input())
leng = len(s)
from heapq import heappush, heappop
Q = []
for i in range(leng):
    heappush(Q, (s[i], i))

se = set()
cnt = 0
while 1:
    a, idx = heappop(Q)
    if a not in se:
        se.add(a)
        cnt += 1
    if cnt==K:
        break
    if idx!=leng-1:
        heappush(Q, (a+s[idx+1], idx+1))

print(a)

Solution (Python):
S = str(input())
K = int(input())
N = len(S)
L = set([])

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

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

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

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

Solution (Python):
s=input()
K=int(input())
d=['zzzzz']
for i in range(len(s)):
    for j in range(i+1,i+6):
        for k in range(len(d)):
            if s[i:j] not in d and s[i:j]<d[k]:
                d.insert(k,s[i:j])
                if len(d)>5:
                    d.pop()
                break
print(d[K-1])

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

Solution (Python):
s=input()
k=int(input())
m=[ord("z")+1]*3
for i in range(len(s)):
    if ord(s[i])<m[0]:
      m=[ord(s[i]),m[0],m[1]]
    elif m[0]<ord(s[i])<m[1]:
      m=[m[0],ord(s[i]),m[1]]
    elif m[1]<ord(s[i])<m[2]:
      m=[m[0],m[1],ord(s[i])]

a=[]
for l2 in m:
  l=chr(l2)
  s2=s
  while l in s2:
    for i in range(5):
      a.append(s2[s2.find(l):min(s2.find(l)+i+1,len(s2))])
    s2=s2[s2.find(l)+1:]
print(sorted(set(a))[k-1])

Solution (Python):
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

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

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

Solution (Python):
import re
s = input()
k = int(input())
scl = sorted(list(set(s)))
ans = scl[:k]
for i in range(k-1):
  dans = []
  for j in ans[i:]:
    dans += re.findall(j+".",s)
    dans = sorted(list(set(dans)))[:k]
    if len(dans) == k:
      break
  ans = sorted(list(set(ans+dans)))[:k]
  

print(ans[-1])

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

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

Solution (Python):
import heapq

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

h = []
l = set()

for i in range(len(s)):
  m = min(len(s),i+K)
  for j in range(i,m):
    heapq.heappush(h, s[i:j+1])
    
while h:
  p = heapq.heappop(h)
  l.add(p)
  if len(l) == K:
    print(p)
    exit()

Solution (Python):
a = input()
n = int(input())
t = 1
ar = []
while True:
    for i in range(len(a) - t + 1):
        if a[i:i+t] not in ar:
            ar.append(a[i:i+t])
    t += 1
    if t > len(a) or t > n:
        break
ar.sort()
print(ar[n-1])