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


ans = []
for i in range(len(s)):
    x = 0
    for j in range(5):
        if (i+j<len(s)):
            x += (ord(s[i+j])-96)*10**(8-2*j)
            ans.append((x,s[i:i+j+1]))
ans = list(set(ans))
ans.sort()

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

Solution (Python):
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array







sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


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

    S = iss()
    K = ii()

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


if __name__ == '__main__':
    main()

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

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

c = []
for i in range(N):
    for j in range(i+1, N+1):
        if len(c) < K:
            c.append(s[i:j])
            c.sort()
        else:
            if s[i:j] in c:
                continue

            if c[K-1] < s[i:j]:
                break
            else:
                c[K-1] = s[i:j]
                c.sort()

print(c[-1])

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

Solution (Python):
S=input()
K=int(input())
N=len(S)
s=set()
for i in range(N):
    for j in range(i+1,min(i+K+1,N+1)):
        s|={S[i:j]}
A=list(s)
A.sort()
print(A[K-1])

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


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

    ans = []

    for i in range(1,6):
        t = 0
        while t+i <= len(s):
            ans.append(s[t:t+i])
            t += 1
    ans = list(set(ans))
    ans.sort()

    print(ans[k-1])


if __name__=="__main__":
    main()

Solution (Python):
s = input()
n = len(s)
K = int(input())
ans = []
an = set()
for i in range(1,min(5,n)+1):
    for j in range(n-i+1):
        S = s[j:j+i]
        if S not in an:
            ans.append(S)
            an.add(S)
ans.sort()
print(ans[K-1])

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

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

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

Solution (Python):
def cin():  return list(map(int,input().split()))

S = input()
k = cin()[0]
s = set()
length = len(S)
for i in range(length):
    tmp = ""
    for j in range(5):
        if i + j < length:
            tmp += S[i + j]
            s.add(tmp)
        
s = sorted(s)
ans = s[k - 1]
print(ans)

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

alphabets = [chr(i + 97) for i in range(26)]

for char in alphabets:
    l = []
    for i in range(len(s)):
        if s[i] == char:
            l.append(s[i:])

    if l == []:
        continue

    if k == 1:
        print(l[0][0])
        exit()
    
    k -= 1

    strings = set([])
    for i in l:
        for j in range(2, min(k+2, len(i)+1)):
            strings.add(i[:j])
    strings = list(strings)
    strings.sort()
    
    if len(strings) >= k:
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

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

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

def substring(S):
    N = len(S)
    ls = []
    for i in range(1,min(6,N+1)):
        for j in range(0,N-i+1):
            ls.append(S[j:j+i])
    setls = set(ls)
    ls = list(setls)
    ls.sort()
    return ls
print(substring(s)[K-1])

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

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

res = sorted(set(a))
print(res[k-1])

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

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

Solution (Python):
S = input().rstrip()
N = len(S)
K = int(input())
A = []
for i in range(N):
    A.append(S[i:])
A.sort()
B = set()
flg = False
for i in range(len(A)):
    for j in range(1,len(A[i])+1):
        B.add(A[i][:j])
        if len(B)==K:
            flg = True
            break
    if flg: break
B = list(B)
B.sort()
print(B[-1])

Solution (Python):
s=list(input())
k=int(input())
n=len(s)
x=[]
for i in range(n):
    x.append(s[i])
if n>=2:
    for i in range(n-1):
        z=s[i]+s[i+1]
        x.append(z)
if n>=3:
    for i in range(n-2):
        z=s[i]+s[i+1]+s[i+2]
        x.append(z)
if n>=4:
    for i in range(n-3):
        z=s[i]+s[i+1]+s[i+2]+s[i+3]
        x.append(z)
if n>=5:
    for i in range(n-4):
        z=s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]
        x.append(z)
x=set(x)
x=sorted(x)
print(x[k-1])

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

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

seq = set()
l = len(s)
for i in range(l):
    for j in range(1, K + 1):
        seq.add(s[i:i + j])

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

Solution (Python):
s = input()
k = int(input())
seen = set()
i = 1

while i<=k:
  for j in range(len(s)):
    seen.add(s[j:j+i])
  i += 1

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

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

    P=sorted(S)
    l=[]
    a=[]
    k=0
    while len(l)<=5 and k<N:
        if P[k] not in a:
            a.append(P[k])
            for n in range(N):
                if S[n]==P[k]:
                    for i in range(1,6):
                        if n+i<=N:
                            tmp="".join(S[n:n+i])
                            if tmp not in l:
                                l.append(tmp)
        k+=1
    l.sort()
    print(l[K-1])

if __name__=="__main__":
    main2()

Solution (Python):
from collections import deque

s = input()
k = int(input())

def index_Multi(List,liter):
    
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L

def substr(s, k, j):
    n = ord("a")

    while True:
        l = index_Multi(s, chr(n+j))
        word = []
        if len(l) == 0:
            n += 1
        else:
            for p in l:
                for i in range(k):
                    word.append(s[p:p+i+1])
            sword = set(word)
            if len(sword) >= k:
                tword = list(sword)
                tword.sort()
                
                return tword[k-1]
            else:
                return substr(s, k-len(sword), j+1)
            break

print(substr(s, k, 0))

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

Solution (Python):
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if j-i<=6:
            li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1])

Solution (Python):

s = input()
n = len(s)
k = int(input())
substr = []
for j in range(1, k+1):
    for i in range(n-j+1):
        sub = s[i:i+j]
        if sub not in substr:
            substr.append(sub)
substr.sort()
print(substr[k-1])

Solution (Python):

s = input()
n = len(s)
k = int(input())
substr = []
for j in range(k):
    for i in range(n-j):
        sub = s[i:i+j+1]
        if sub not in substr:
            substr.append(sub)
substr.sort()
print(substr[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):
from collections import Counter
s=list(input())
k=int(input())
n=len(s)
s_c=sorted(Counter(s).items())

ans=[]
for i in s_c:
    for j in range(n):
        if s[j]==i[0]:
            ans.append(s[j])
            if j+1<=n-1:
                ans.append("".join([s[j],s[j+1]]))
                if j+2<=n-1 :
                    ans.append("".join([s[j],s[j+1],s[j+2]]))
                    if j+3<=n-1:
                        ans.append("".join([s[j],s[j+1],s[j+2],s[j+3]]))
                        if j+4<=n-1:
                            ans.append("".join([s[j],s[j+1],s[j+2],s[j+3],s[j+4]]))

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

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

subst = []
for i in range(5):
  for j in range(len(s) - i):
    subst.append(s[j:j+i+1])

subst = list(set(subst))
subst.sort()

print(subst[K - 1])

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

Solution (Python):

from collections import deque


def search(moji):
    num = len(moji)
    setsn = set([])
    for i in range(len(s)-num+1):
        if s[i:i+num] == moji:
            str_ = s[i:i+num+1]
            if len(str_) == num+1:
                setsn.add(str_)
    sorted_setsn = sorted(setsn, reverse=True)

    return sorted_setsn


s = str(input())
k = int(input())
n = len(s)

sets1 = set([])
for i in range(0, len(s)):
    sets1.add(s[i])

sorted_sets1 = sorted(sets1)







dq = deque(sorted_sets1)

while(len(dq)):
    
    moji = dq.popleft()
    k -= 1
    if k == 0:
        print(moji)
        exit()
    sorted_setsn = search(moji)

    
    dq.extendleft(sorted_setsn)

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

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    K = I()
    subs = set()
    for j in range(1, 6):
        for i in range(len(s)):
            st = i
            en = min(st + j, len(s))
            subs.add(s[st:en])
    print(sorted(list(subs))[K-1])
main()

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

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    subs = set()

    for i in range(len(S)):
        for j in range(i + 1, min(len(S) + 1, i + K + 1)):
            subs.add(S[i:j])

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

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    subs = set()

    for i in range(len(S)):
        for j in range(i + 1, min(len(S) + 1, i + K + 1)):
            subs.add(S[i:j])

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

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    subs = set()

    S_sorted = sorted(set(S))
    for c_min in S_sorted:
        indices = [i for i, c in enumerate(S) if c == c_min]
        for i in indices:
            for j in range(i + 1, min(len(S) + 1, i + K + 1)):
                subs.add(S[i:j])

        if len(subs) >= K:
            break

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

    return


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
k=int(input())
n=len(s)
r=[]
for right in range(0,n):
  for left in range(right+1, right+k+1):
    r.append(s[right:left])
print(sorted(set(r))[k-1])

Solution (Python):
s=list(input())
k1=int(input())
l1=set()
for i in range(len(s)):
    l1.add(s[i])
a1=[]
for i in range(len(l1)):
    a1.append(l1.pop())
a1.sort()
for i in range(len(a1)):
    str=a1[i]
    l2=set()
    for j in range(len(s)):
        if s[j]==str:
            l2.add(s[j])
            str2=s[j]
            for k in range(j+1,min(len(s),j+7)):
                str2+=s[k]
                l2.add(str2)
    if len(l2)>=k1:
        l3=sorted(l2)
        ans=l3[k1-1]
        break
    else:
        k1-=len(l2)
print(ans)

Solution (Python):
S = input()
N = len(S)
K = int(input())
StringList = []
for TSt in range(0,N):
    for TEd in range(TSt+1,TSt+K+1):
        StringList.append(S[TSt:TEd])
SetString = sorted(set(StringList))
print(SetString[K-1])

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  

s = LS2()
K = I()
n = len(s)

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

A = list(A)
A.sort()

print(A[K-1])

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

if K==1:
  print(sorted(s)[0])
  exit()
  
topK = sorted(s)[:min(K,len(s))]

indices=[]
for i in range(len(s)):
  if s[i] in topK:indices.append(i)
    
selected=[]
for j in range(len(indices)):
  i = indices[j]
  tmp=[]
  for k in range(min(K,len(s)-i)):
    tmp.append(s[i:i+k+1])
  selected.extend(tmp)
  
selected = sorted(set(selected))

print(selected[K-1])

Solution (Python):
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,min(i+6,len(s)+1)):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])

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

a_list = sorted(set(s))
for i in a_list:
  if K == 1:
    print(i)
    sys.exit()
  p = []
  for j, x in enumerate(s):
    if x == i:
      p.append(s[j:min(j+K,len(s))])
  p.sort()
  t = K
  for j in range(len(p)):
    if j != len(p) - 1:
      if p[j] == p[j+1][0:len(p[j])]:
        continue
    if len(p[j]) < t:
      t -= len(p[j]) - 1
    else:
      print(p[j][0:t])
      sys.exit()
  K = t - 1

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




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

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

Solution (Python):
import heapq
s = raw_input()
k = int(raw_input())

heap = [(s[i], i) for i in range(len(s))]
heapq.heapify(heap)
seen = set()
while(k and heap):
	t,ii = heapq.heappop(heap)
	if t not in seen:
		seen.add(t)
		k-=1
		if k == 0:
			print t
	if ii + 1 < len(s):
		heapq.heappush(heap, (t + s[ii+1], ii+1))

Solution (Python):
import collections

s = input()
k = int(input())
b = collections.Counter(s)
c = sorted(b.items())
con = []
n = 0
while True:
    con.append(c[n][0])
    if len(con) == k:
        break
    for i in range(len(c)):
        check = c[n][0] + c[i][0]
        if check in s:
            con.append(check)
            if len(con) >= k:
                break
            for i_2 in range(len(c)):
                check_2 = check + c[i_2][0]
                if check_2 in s:
                    con.append(check_2)
                    if len(con) >= k:
                        break
                    for i_3 in range(len(c)):
                        check_3 = check_2 + c[i_3][0]
                        if check_3 in s:
                            con.append(check_3)
                            if len(con) >= k:
                                break
                            for i_4 in range(len(c)):
                                check_4 = check_3 + c[i_4][0]
                                if check_4 in s:
                                    con.append(check_4)
                                    if len(con) >= k:
                                        break
    if len(con) >= k:
        break                              
    n +=1
print(con[k-1])

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

if __name__ == "__main__":
    main()

Solution (Python):
S = input()
k = int(input())
ss = []
for i in range(len(S)):
    for j in range(i+1, min(i+k+1, len(S)+1)):
        ss.append(S[i:j])

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

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

ls = len(s)

res =[]

for i in range(1,k+1):
    for j in range(ls-i+1):
        res.append(s[j:j+i])
        
ress = sorted(list(set(res)))
print(ress[k-1])

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

Solution (Python):
S = input()
K = int(input())
S_len = len(S)
ans = set()
for i in range(0, K+1):
    for j in range(0, S_len):
        if j + i <= S_len:
            t = S[j:j + i]
            if t != '':
                ans.add(t)
ans = list(ans)
ans.sort()
print(ans[K-1])

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

d = sorted(list(S))
x = set(d)
for c in d:
    left = S.index(c)
    while left < len(S):
        if S[left] != c:
            left += 1
            continue
        j = 2
        while j <= K:
            x.add(S[left:left+j])
            j += 1
        left += 1
    if len(x) >= K:
        break
x = sorted(list(x))
print(x[K - 1])

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = list(input())
    k = int(input())
    subs = set()
    lens = len(s)
    for i1 in range(k + 1):
        for i2 in range(lens - i1):
            subs.add("".join(s[i2:i2+i1+1]))
    subs_l = list(subs)
    subs_l.sort()
    print(subs_l[k-1])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    s = list(input())
    k = int(input())
    k -= 1

    d1 = defaultdict(list)
    for i, c in enumerate(s):
        d1[c].append(i)
    d2 = sorted(d1.items())

    lens = len(s)
    for d2e in d2:
        subs = set()
        subs.add(d2e[0])
        for d2ee in d2e[1]:
            end = min(lens + 1, d2ee + k + 2)
            for i1 in range(d2ee+1, end):
                subs.add("".join(s[d2ee:i1]))
        if len(subs) > k:
            subsl = list(subs)
            subsl.sort()
            print(subsl[k])
            sys.exit()
        else:
            k -= len(subs)

if __name__ == '__main__':
    main()

Solution (Python):


s = input()
k = int(input())

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


kouho = {}

for i in early:
    for j in range(len(s)):
        if s[j]==i:
            for l in range(k):
                kouho[s[j:j+l+1]]=0
    if len(kouho)>k:
        break

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

Solution (Python):
from string import ascii_lowercase
alp=ascii_lowercase
s=input()
k=int(input())
lst=set()
p=-1
while len(lst)<=k-1:
    p+=1
    for i in range(len(s)):
        if s[i]==alp[p]:
            for j in range(k):
                if i+j<len(s):
                    lst.add(s[i:i+j+1])
lst=sorted(lst)
print(lst[k-1])

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

s = input().rstrip()
K = int(input())
ls = len(s)
cs = collections.deque()
for i in range(ls):
    for j in range(i+1,i+1+K):
        cs.append(s[i:j])
os = sorted(cs)
count = 0
lis = []
for i in os:
    if i not in lis:
        lis.append(i)
        count +=1
    else:
        continue
    if count == K:
        print(i)
        exit()

Solution (Python):
s=input()
k=int(input())
l=len(s)
def find_substring_from_a(a):
    a_s=[]
    for i in range(l):
        if s[i]==a:
            for j in range(1,min(6,l-i+1 )):
                a_s.append(s[i:i+j])
    return sorted(set(a_s) )
moji_list = sorted(set(s))
length = 0
for a in moji_list:
    a_s=find_substring_from_a(a)
    lenas = len(a_s)
    if length+lenas >=k:
        break
    else:
        length+=lenas
print(a_s[k-length-1])

Solution (Python):


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

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

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

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

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


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

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

S_=[]
for s in range(len(S)):
    s_temp=S[s]
    S_.append(s_temp)
    for e in range(s+1,len(S)):
        if e-s>K+10:
          break
        s_temp+=S[e]
        S_.append(s_temp)
        
S_=list(set(S_))
S_.sort()

print(S_[K-1])

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

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

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

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

tmp = set(l)
l = sorted(list(tmp))

print(l[k-1])

Solution (Python):
def calc( s , k , n):

	bruh = {}
	for i  in range(1, k + 1): 
		for j in range( n - ( i - 1)): 
			bruh[s[j: j + i:]] = 0
	another = bruh.keys()
	another = sorted(another)
	print( another[k - 1])

s = input()

k = int(input())

n = len(s)
 
calc( s , k , n)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = in_s()
    K = in_n()
    N = len(S)

    subs = set()
    for i in range(N):
        for j in range(1, K + 1):
            if i + j <= N:
                subs |= {S[i:i + j]}

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


if __name__ == '__main__':
    main()

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

N = len(S)

memo = []
for i in range(N):
    for d in range(1, min(K, N - i) + 1):
        memo.append(S[i:i + d])

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

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

Solution (Python):
import sys
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    """
    文字列のソートをする際には計算量に要注意！
    数字の大小比較と違って文字列の比較の場合は１文字１文字左から順番に見ないといけない。
    そのため一回の比較でO(比較文字列の長さ)分の計算量がかかる。
    特に長さMの文字列N個をソートするのにかかる時間は
            ❌O(NlogN)
            ⭕️O(MNlogN)

    そこで文字列のソート時には文字数をなるべく小さくするのがポイント。
    今回K<=5なので、「答えはK<=5文字以下になる」のがミソ。
    """

    s = input()
    L = len(s)
    K = int(input())
    string = set([])
    for i in range(L):
        for j in range(i + 1, min(i + K, L) + 1):
            string.add(s[i:j])

    string = list(string)
    heapify(string)
    for _ in range(K):
        ans = heappop(string)
    print(ans)


if __name__ == "__main__":
    main()

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

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

SUBSTRINGS = sorted(SUBSTRINGS)

print(SUBSTRINGS[k - 1])

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

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

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

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

cand = []
for i in range(len(s)):
    temp = ''
    for j in range(k):
        if i + j >= len(s):continue
        temp += s[i + j]
        cand.append(temp)

cand.sort()

ans = cand.pop(0)
k -= 1
while k != 0:
    temp = cand.pop(0)
    if temp == ans:continue 
    ans = temp
    k -= 1

print(ans)

Solution (Python):
import sys
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

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


if __name__ == '__main__':
    main()

Solution (Python):
S = input()
K = int(input())
val = ''
A = set()
for i,s in enumerate(S):
    val = ''
    for j in range(i,min(i+5,len(S))):
        val += (S[j])
        A.add(val)
A_sort = sorted(list(A))
print(A_sort[K-1])

Solution (Python):


import math



from collections import deque
from collections import Counter




s=input()
k=int(input())
n=len(s)
a=[chr(i) for i in range(ord('a'),ord('z')+1)]
ans=set()
for i in a:
    if i not in s:
        continue
    if len(ans)>=5:
        break
    for c in range(n):
      if s[c]==i:
          l=c
          r=c
          while True:
            if  r>n or r-l>6:
                break
            ans.add(s[l:r+1])
            r+=1
ans=list(ans)
ans.sort()
print(ans[k-1])

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

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

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

Solution (Python):
s = input()
k = int(input())
l = "abcdefghijklmnopqrstuvwxyz"
d = {}

for i in range(26):
    cnt = s.count(l[i])
    pre = 0
    if cnt > 0:
        for j in range(cnt):
            pos = s.find(l[i], pre)
            pre = pos + 1
            for m in range(min(len(s) - pos, k)):
                if s[pos:pos + m + 1] not in d:
                    d[s[pos:pos + m + 1]] = 1
    if len(d) >= k:
        dl = []
        for i in d.keys():
            dl.append(i)
        dl.sort()
        print(dl[k - 1])
        exit()

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

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

substrings = sorted(substrings)

print(substrings[K - 1])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)

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

chars = sorted(set(S))
checked = set()


def dfs(s):
    for c in chars:
        if len(checked) >= K:
            return
        next_s = s + c
        if next_s not in checked and next_s in S:
            checked.add(next_s)
            if len(checked) == K:
                print(next_s)
                return
            elif len(next_s) <= len(S):
                dfs(next_s)


dfs('')

Solution (Python):
s = input()

d = ["z"*5010]*5

k = int(input())
for i in range(len(s)):
    for j in range(i, i+k):
        x = s[i:j+1]
        if x in d or x == '':
            continue
        l = 0
        while l < 5 and x > d[l]:
            l += 1
        
        if l < 5:
            d = d[0:l] + [x] + d[l:]
            d = d[0:5]
        




    

print(d[k-1])

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