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):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    k = int(input())
    ss = set()
    alp = "abcdefghijklmnopqrstuvwxyz"
    for ai in alp:
        for i,si in enumerate(s):
            if si != ai:
                continue
            nw = ""
            for sj in s[i::]:
                nw += sj
                if len(nw) > 5:
                    break
                ss.add(nw)
        if len(ss) >= k:
            break
    print(sorted(ss)[k-1])



    return

if __name__ == '__main__':
    main()

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

L=[]
for i in range(K):
    for j in range(N-i):
        if S[j:j+i+1] not in L:
            L.append(S[j:j+i+1])

L.sort()
ans=""
for l in L[K-1]:
    ans+=l
print(ans)

Solution (Python):

s = input() + " "
k = int(input())
ans = []
for i in range(len(s)):
    for j in range(i + 1, min(len(s), i + 5 + 1)):
        t = "".join(s[i:j])
        if t not in ans:
            ans.append(t)
            ans = sorted(ans)[:6]
print(ans[k - 1])

Solution (Python):
if __name__ == "__main__":
    s = input()

    K = int(input())

    subsrings = [s[i : i + K + 1] for i in range(len(s))]
    subsrings.sort()

    first = set()

    for s in subsrings:

        for i in range(1, len(s) + 1):
            if s[:i] not in first:
                first.add(s[:i])
                if len(first) == K:
                    print(s[:i])
                    break

Solution (Python):


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

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

Solution (Python):
import sys
from heapq import heapify, heappop

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    SS = set()
    for i in range(n):
        ss = S[i]
        SS.add(ss)
        for j in range(i + 1, min(n, i + k)):
            ss += S[j]
            SS.add(ss)

    SS = list(SS)
    heapify(SS)
    for _ in range(k):
        res = heappop(SS)
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):

import sys


def solve(s: str, K: int):
    pool = set()
    for l in range(K):
        for i in range(0, len(s)-l):
            pool.add(s[i:i+l+1])
    return sorted(pool)[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))  
    print(solve(s, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

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

Solution (Python):
s = input()
k = int(input())
ans = set()
r = len(s)

if r == 1:
    print(s)
else:
    for i in range(r):
        for j in range(k):
            ans.add(s[i:i+j+1])
    print(sorted(list(ans))[k-1])

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = sr()
k = ir()
dic = {}
for l in range(5):
    for i in range(len(s)-l):
        tmp = s[i:i+l+1]
        dic[tmp] = 1
ans = []
for key in dic.keys():
    ans.append(key)
ans.sort()
print(ans[k-1])

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

print(L[k-1])

Solution (Python):
from collections import defaultdict

s = list(input())
K = int(input())
d = defaultdict(int)
L = min(len(s), 5)

for i in range(L):
  for j in range(len(s)-i):
    x = s[j]
    for k in range(i):
      x += s[j+k+1]
    d[x] += 1

D = sorted(d.keys())

print(D[K-1])

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

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

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

Solution (Python):
from collections import Counter

s = str(input())
k = int(input())
d = Counter(s)
L = sorted(d.keys())[:k]
ss = set()
for c in L:
    for i in range(len(s)):
        if s[i] == c:
            ss.add(s[i])
            for j in range(1, k+1):
                if i + j >= len(s):
                    break
                else:
                    ss.add(s[i:i+j+1])
print(sorted(ss)[k-1])

Solution (Python):
s = input()
k = int(input())
buf = dict()
for i in range(len(s)):
    for j in range(1,6):
        if j > len(s):
            break
        buf[s[i:i+j]] = True
keys = buf.keys()
buf = list(buf)
buf.sort()

print(buf[k-1])

Solution (Python):
s=list(input())
k=int(input())
n=len(s)
subset=[]
from bisect import bisect_left

for i in range(n):
    tmp=s[i]
    for j in range(i,min(n,i+5)):
        if j==i: pass
        else: tmp+=s[j]
        if tmp not in subset:
            l=bisect_left(subset, tmp)
            if 0<=l<5:
                subset=subset[:l]+[tmp]+subset[l:5]
                subset=subset[:5]
            else:
                break
print(subset[k-1])

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

print(D[K-1])

Solution (Python):
s = input()
K = int(input())
pool = set()
n = 0
slist = list(s)

for i in range(26):
  c = s.count(chr(97+ i))
  for j in range(c):
    index = slist.index(chr(97+ i))
    slist[index] = ""
    for k in range(len(s)- index):
      pool.add(s[index:index+ k+ 1])
      if(k>= K):
        break
  if(len(pool)>= K):
    newlist = list(pool)
    newlist.sort()
    print(newlist[K- 1])
    break

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

Solution (Python):
from itertools import combinations


def main():
    s, k = input(), int(input())
    l, tmp = len(s), s[:5]
    for i in range(l - 4):
        tmp = min(tmp, s[i:i + 5])
    res = set()
    for i, j in combinations(range(min(6, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations


def main():
    s, k = input(), int(input())
    l, tmp = len(s), s[:k]
    for i in range(l - k + 1):
        tmp = min(tmp, s[i:i + k])
    res = set()
    for i, j in combinations(range(min(k + 1, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations


def main():
    s, k = open(0).read().split()
    k, l = int(k), len(s)
    tmp = s[:k]
    for i in range(l - k + 1):
        tmp = min(tmp, s[i:i + k])
    res = set()
    for i, j in combinations(range(min(k + 1, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

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

n = len(s)
array = []

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

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

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

part = set()
for i in range(n):
    for j in range(k):
        part.add("".join(s[i:i+j+1]))

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

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

lis=[]
for i in range(len(s)):
    lis.append(s[i:i+5])
    lis.sort()

l=[]
for i in lis[:5]:
    for j in range(5):
        l.append(i[:j+1])

l=set(l)
l=list(l)

l.sort()

print(l[k-1])

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

koho=set()
for i in range(n):
    for j in range(i+1, min(i+k+1, n+1)):
        c=s[i:j]
        if c not in koho:
            koho.add(c)
ans=sorted(list(koho))
print(ans[k-1])

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

koho=set()
for i in range(n):
    for j in range(i+1, min(i+k+1, n+1)):
        c=s[i:j]
        if c not in koho:
            koho.add(c)
ans=sorted(list(koho))
print(ans[k-1])

Solution (Python):

s = input()
K = int(input())
result = []
for i in range(1, min(len(s)+1, 6)):
    if(i == 1):
        for j in list(s):
            result.append(j)
    else:
        n = 0
        m = n + i
        while m <= len(s):
            result.append(s[n:m])
            n += 1
            m = n + i

result = set(result)
s = sorted(result)
print(s[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()
a=set()
for i in range(5):
  for j in range(len(s)-i):
    a.add(s[j:j+i+1])

print(sorted(list(a))[int(input())-1])

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

se = set()

def string(now,num):
    if now+num == s or num == k:
        return
    se.add(s[now:now+num+1])
    num += 1
    return string(now,num)

for i in range(S):
    string(i,0)

se = list(se)
se.sort()

print(se[k-1])

Solution (Python):
import sys

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

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

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

Solution (Python):
s = input()
K = int(input())
s_dic = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, c in enumerate(s):
    s_dic[c].append(i)
substrings = set()
for indices in s_dic.values():
    for i in indices:
        for j in range(i + 1, i + K + 1):
            substrings.add(s[i:j])
print(sorted(list(substrings))[K - 1])

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    K = int(input())
    substr = set()
    N = len(s)
    for i in range(N):
        for j in range(1, min(6, N - i + 1)):
            substr |= {s[i:i+j]}
    sl = list(substr)
    sl.sort()
    print(sl[K-1])

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()

s = input()
n = len(s)
k = int(input())
ans = []
used = set()
"""
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[s[i]].append(i)
""" 
for i in range(n):
    start = list(s[i])
    if s[i] not in used:
        ans.append(s[i])
        used.add(s[i])
    for j in range(i + 1, min(i + k, n)):
        start.append(s[j])
        temp = "".join(start)
        if temp not in used:
            ans.append(temp)
            used.add(temp)
ans.sort()
print(ans[k - 1])

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]

for i in range(97, 123):
    moji = chr(i)
    if moji not in dic:
        continue
    kouho = dic[moji]
    strings = set([])
    for idx in kouho:
        e = idx+1
        string = set([])
        while e <= n and len(string) <= k:
            string.add(s[idx:e])
            e += 1
        strings = strings | string
    if len(strings) >= k:
        strings = list(strings)
        strings.sort()
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

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 = str(input())
k = int(input())
s = list(s)

n = len(s)

import copy
l = copy.copy(s)
l = set(l)
l = list(l)
l.sort()


ans = set()
for i in range(len(l)):
    for j in range(n):
        if s[j] == l[i]:
            p = j
            temp = []
            while p < n and p-j+1 <= k:
                temp.append(s[p])
                ans.add(''.join(temp))
                p += 1
    if len(ans) >= k:
        break

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

Solution (Python):
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
        ans = list(set(ans))
    else:
        c = key.pop(0)
        
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(min(5, len(s) - i)):
                queue.append(s[i:i+j+1])

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

Solution (Python):
s = input() + "{{{{{"
K = int(input())
L = []
t = 0
while t <= K:
    for k in range(len(s)-t):
        if "{" not in s[k:k+t+1]:
            L.append(s[k:k+t+1])
    t += 1
L = sorted(list(set(L)))
print(L[K-1])

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
K = int(input())
l = []

for i in range(len(S)):
    for j in range(i, min(len(S), i+5)):
        l.append(S[i:j+1])

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

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

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

print(A[K - 1])

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

l=[]
st=set()
n=len(s)
for i in range(1,min(n,5)+1):
    for j in range(n+1-i):
        tmp=s[j:j+i]
        if tmp not in st:
            l.append(tmp)
            st.add(tmp)
l.sort()
print(l[k-1])

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

Solution (Python):
s = input()
k = int(input())
li = set()
def insert(x):
    if x in li:
        return
    if len(li)<k:
        li.add(x)
    elif x<max(li):
        li.remove(max(li))
        li.add(x)

for i in range(26):
    b = chr(i+ord('a'))
    for i in range(len(s)):
        if s[i]!=b:
            continue
        for j in range(k):
            if i+j<len(s):
                insert(s[i:i+j+1])
    if len(li)==k:
        break
li = list(li)
li.sort()
print(li[k-1])

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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





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

    substring = set()
    for i in range(97, 97 + 26):
        word = chr(i)

        for j in range(len(s)):
            if s[j] == word:
                tmp = s[j:j + k]

                while len(tmp) > 0:
                    substring.add(tmp)
                    tmp = tmp[:-1]

        if len(substring) >= k:
            break

    ans = list(substring)
    ans.sort()

    print(ans[k - 1])


if __name__ == '__main__':
    main()

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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





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

    substring = set()
    for i in range(97, 97 + 26):
        word = chr(i)

        for j in range(len(s)):
            if s[j] == word:
                tmp = s[j:j + k]

                while len(tmp) > 0:
                    substring.add(tmp)
                    tmp = tmp[:-1]

        if len(substring) >= k:
            break

    ans = list(substring)
    ans.sort()

    print(ans[k - 1])


if __name__ == '__main__':
    main()

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

subs = set()
for i in range(N):
  for j in range(K):
    subs.add(s[i:i+1+j])
  
print(sorted(subs)[K-1])

Solution (Python):
from itertools import combinations
s = input()
n = int(input())

le = len(s)
tmp = s[:5]

for i in range(le - 4):
    tmp = min(tmp, s[i:i+5])

seed = tuple(combinations(range(min(6, le+1)), 2))
res = set()
for i, j in seed:
    res.add(tmp[i:j])
ans = sorted(res)
print(ans[n - 1])

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

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

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

Solution (Python):
s = input()
K = int(input())
alp = "abcdefghijklmnopqrstuvwxyz"
candidate_orig = set()

def hoge(c_list, rank, candidate):
    if len(candidate) >= 5:
        return candidate

    cur_targets = {}
    for l in sorted(c_list):
        if l + rank > len(s) - 1:
            continue
        _sub = s[l: l + 1 + rank]
        if _sub not in cur_targets:
            cur_targets[_sub] = [l]
        else:
            cur_targets[_sub].append(l)

    if len(cur_targets) == 0:
        return candidate

    for _d in sorted(cur_targets.items(), key=lambda x: x[0]):
        candidate.add(_d[0])
        candidate = hoge(_d[1], rank + 1, candidate)
        return candidate

    return candidate

for a in alp:
    idx_list = []
    for i, _s in enumerate(s):
        if a == _s:
            idx_list.append(i)
            candidate_orig.add(_s)
    candidate = hoge(idx_list, 1, candidate_orig)
    if len(candidate) >= 5:
        break

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

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

    tank = set()
    for k in range(1, K + 1):
        for i in range(N - k + 1):
            t = S[i:i + k]
            tank.add(t)

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


if __name__ == '__main__':
    main()

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

for i in range(N):
  for j in range(K):
    t= s[i:i+j+1]
    
    tmp.add(t)
    
lis=sorted(tmp)

print(lis[K-1])

Solution (Python):

S = input().strip()
K = int(input())
L = len(S)
substr = set()

for i in range(L):
    for j in range(5):
        s = S[i:min(i+j+1, L)]
        if s:
            substr.add(s)

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

Solution (Python):
s=input()
K=int(input())
abc=list("abcdefghijklmnopqrstuvwxyz")

N=len(s)
L=[]
flag=False
for a in abc:
    for i in range(N):
        if s[i]==a:
            L.append(s[i:])
            
    if flag:
        break
L=sorted(L)

ans=[]
for l in L:
    n=len(l)
    for i in range(n):
        t=l[:i+1]
        if t not in ans:
            ans.append(l[:i+1])
    if len(ans)>=K:
        break

print(ans[K-1])

Solution (Python):
from string import ascii_letters

def solve(word):
    for c in ascii_letters:
        sub = word + c
        if sub in s:
            words.append(sub)
            if len(words) == k:
                print(sub)
                exit()
            solve(sub)

s = input()
k = int(input())
words = []
solve('')

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

    tmp = [[] for _ in range(26)]
    for i in range(N):
        tmp[ord(S[i]) - ord('a')].append(i)

    lst = []
    lst_append = lst.append
    s = set()
    s_add = s.add
    for num in tmp:
        for i in num:
            for j in range(i + 1, min(N, i + K) + 1):
                if S[i:j] in s:
                    continue
                else:
                    s_add(S[i:j])
                    lst_append(S[i:j])
        if len(s) >= K:
            lst.sort()
            print (lst[K - 1])
            
            return

if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heappush, heappop

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

min_s = sorted(list(set(s)))

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

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

print(ans)

Solution (Python):
def solve():
    S = input()
    K = int(input())
    strlist = sorted(list(S))
    lis = set()
    p = 0
    while len(list(lis))<K:
        a = strlist[p]
        if len(S)>=5:
            for i,s in enumerate(S):
                if s==a:
                    for j in range(i+1,min(len(S)+1,i+K+1)):
                        lis.add(S[i:j])
        else:
            for i in range(len(S)):
                for j in range(i+1,len(S)+1):
                    lis.add(S[i:j])
        p += 1
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

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


if __name__ == '__main__':
    main()

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

T = []




for i in range(len(s)): 
  for j in range(i+1,min(len(s)+1,i+K+1)): 
    temp = s[i:j]
    if temp in T:
      continue
    if len(T) < K:
      T.append(temp)
      T.sort()
    else:
      Flag = False
      for t in range(K):
        if temp < T[t]:
          
          T.insert(t,temp)
          Flag = True
          break
      if Flag:
        T.pop()
print(T[K-1])

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

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

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

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

lis = list(set(list(s)))
lis.sort()

ans_lis = []
for i in range(min(5, len(lis))):
    i = lis[i]
    s2 = s
    while 1:
        idx = s2.find(i)
        if idx==-1:
            break
        ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx))]
        s2 = s2[idx+1:]
ans_lis = list(set(ans_lis))
ans_lis.sort()
print(ans_lis[K-1])

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())


finish = set()
S = len(s)

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

finish = list(finish)
finish.sort()

print(finish[k-1])

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

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

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):

        se.add(s[i:j])

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











'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):

        se.add(s[i:j])

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

Solution (Python):



from itertools import zip_longest
from collections import Counter

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

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

subs = list(subs)
subs.sort()

print(subs[K-1])

Solution (Python):
def main():
    s = input()
    k = int(input())
    c = set()

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

if __name__ == '__main__':
    main()

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

N=len(s)
ln=0
siki_sub=''
result={}

for i in range(N):
    for j in range(min(N-i,K+1)):
        if ln<K:
            if s[i:i+j+1] not in result:
                result[s[i:i+j+1]]=1
                siki_sub=max(result)
                ln+=1
        else:
            if siki_sub>s[i:i+j+1] and s[i:i+j+1] not in result:
                del result[siki_sub]
                result[s[i:i+j+1]]=1
                siki_sub=max(result)

print(siki_sub)

Solution (Python):
letter=input()
K=int(input())
import re
ans=[]
X=[chr(i) for i in range(97, 97+26)]
for i in X:
   if i in letter:
      c=[m.end() for m in re.finditer(i, letter)]
      for j in c:
         for i in range(K):
            if j-1+i==len(letter):
               break
            ans.append(letter[j-1:j+i])
   ans=list(set(ans))
   if len(ans)>=5:
      break
ans.sort()
print(ans[K-1])

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

for i in range(n):
    end = min(n, i+K)
    for j in range(i+1, end+1):
        ans.add(s[i:j])

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

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

for i in range(n):
    end = min(n, i+10)
    for j in range(i+1, end+1):
        ans.add(s[i:j])

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

Solution (Python):


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

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

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

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
k = inn()
n = len(s)
cnt = 0
u = set([])
for i in range(26):
    c = chr(ord('a')+i)
    t = s
    while len(t)>0:
        j = t.find(c)
        if j<0:
            break
        for m in range(j+1,min(j+6,n+1)):
            
            u.add(t[j:m])
            cnt += 1
        t = t[j+1:]
    
    if len(u)>=k:
        break

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

Solution (Python):
import sys

input = sys.stdin.readline


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

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

    sub = sorted(sub)
    ans = sub[K - 1]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


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

    N = len(S)
    sub = set()
    for al in AL:
        for i in range(N):
            if S[i] == al:
                for j in range(1, 6):
                    sub.add(S[i:i + j])
        if len(sub) >= K:
            break

    sub = sorted(sub)
    ans = sub[K - 1]

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

subs = set()
for i in range(N):
  for j in range(K):
    subs.add(s[i:i+1+j])
  
print(sorted(subs)[K-1])

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    S = list(input().rstrip())
    K = int(input().strip())
    q = ["zzzzzz"] * K
    for i in range(len(S)):
        s = S[i]
        if s < q[-1] and s not in q:
            q[-1] = s
            q.sort()
        for j in range(1, K):
            if i+j < len(S):
                s += S[i+j]
                if s < q[-1] and s not in q:
                    q[-1] = s
                    q.sort()
    print(q[-1])

if __name__ == '__main__':
    main()

Solution (Python):



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

ans = []

for k in range(1, K+1):
    for i in range(0, N-k+1):

        ans.append(S[i:i+k])

ans = list(set(ans))
ans.sort()

print(ans[K-1])

Solution (Python):
import heapq
s=input()
k=int(input())
n=len(s)
ls=[[si,i] for i,si in enumerate(list(s))]
heapq.heapify(ls)
seen=set()
c=0
while c<k:
  a=heapq.heappop(ls)
  if a[0] not in seen:
    seen.add(a[0])
    c+=1
    
    if c==k:
      print(a[0])
      exit()
  if len(a[0])+a[1]<n:
    a[0]+=s[len(a[0])+a[1]]
    heapq.heappush(ls,a)

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

lis=[]

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

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    S = input()
    k = int(input())
    n = len(S)
    candidate = set()
    for l in range(1, k + 1):
        for i in range(n - l + 1):
            candidate.add(S[i : i + l])
    print(sorted(candidate)[k - 1])
resolve()