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



Sample input:
aba
4


Sample output:
b

Submission status: Accepted

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

substring = []

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

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

print(substring[k-1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(20000000)

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


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

    arr = sorted(objs.keys())

    print(arr[k-1])

calculate(s, K)

Submission status: Accepted

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

substring = []

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

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

print(substring[k-1])

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Fri Mar  6 03:39:35 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import Counter

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

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

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

Submission status: Accepted

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

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

substring = list(set(substring))
substring.sort()
substring.pop(0)
##print(substring)
print(substring[K-1])

Submission status: Accepted

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

l = []
for i in range(len(s)):
    for y in range(k):
#        print(''.join(s[i:i+y+1]))
        if not ''.join(s[i:i+y+1]) in l:
            l.append(''.join(s[i:i+y+1]))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

L = list("abcdefghijklmnopqrstuvwxyz")

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

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

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

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
#s=list(input())

#t=[]
#for kk in range(k):
#    t.append(s)

t=["zzzzz"]*k

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc097/tasks/arc097_a


# 辞書順に置いては文字の先頭が重要。
# 一文字目が速いやつから注目していく。
# 一文字目が同じだったらさらにその次の文字を注目する。

# atcoderandatcodeer
# a      a  a       # 1種
# at     an at      # 1種 #tは以下のすべてよりも辞書順があと
#        and        # 1種
#        anda       # 1種
#        andat      #

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

# 一番速い文字を検索してからそこからK文字見るのが一番早そう。
# ただし、K文字ない場合は辻褄合わせが必要
# てか計算量的に、こんなことしなくてもK文字目まで全列挙すればよくね？

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

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
a = []
for i in range(len(s)+1):
    for j in range(len(s)+1):
        if j <= k:
            a.append(s[i:i + j])
# print(a)
c = sorted(set(a))
# print(c)
print(c[k])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(already[-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

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

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

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

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

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

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

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

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

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

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

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = []

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
substring = []
# print(s, K)
for i in range(len(s)):
    for j in range(1, min(K+1, len(s)+1)):
        # print(s[i:i+j])
        substring.append(s[i:i+j])

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

# print(substring)
print(substring[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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


A = sorted(set(A))

print(A[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A=[]

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

N = len(s)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappop, heapify

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp = []

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

str_set = set(tmp)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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


#print(X)
print(X[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(substr[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#X = ["a", "ba", "zxx", "abb", "ab"]
#print(sorted(X))

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

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

Submission status: Accepted

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

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

print(dct[k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
ALP = 'abcdefghijklmnopqrstuvwxyz'

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

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

        if tmp_substr in substr:
            continue

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

print(substr[K-1])

Submission status: Accepted

Solution code:
def main():
    s = input()
    K = int(input())
    print(sorted(list({s[i:j]
                       for i
                       in range(len(s))
                       for j
                       in range(i + 1, min(i + K + 1, len(s) + 1))}))[K - 1])
    return


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

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

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

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


main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    K = int(input())
    print(sorted({s[i:j]
                  for i in range(len(s))
                  for j in range(i + 1, min(i + K + 1, len(s) + 1))})[K - 1])
    return


main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
S = set()
s = list(input().rstrip())
K = int(input())
for i in range(len(s)):
    for j in range(i+1, i+K+1):
        if "".join(s[i:j]) not in S:
            S.add("".join(s[i:j]))
S = list(S)
S.sort()
print("".join(S[K-1]))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    dic = []
    dic_set = set()
    for i in range(len(S)):
        j = 0
        tmp = ""
        while i + j < len(S) and j < 5:
            tmp += S[i + j]
            if tmp not in dic_set:
                dic.append(tmp)
                dic_set.add(tmp)
            j += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    dic = []
    for i in range(len(S)):
        j = 0
        tmp = ""
        while i + j < len(S) and j < 5:
            tmp += S[i + j]
            if tmp not in dic:
                dic.append(tmp)
            j += 1

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



    
    
    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    s = input()
    k = int(input())
    l = set()
    ls = len(s)
    clist = sorted(list(set(list(s))))
    ladd = l.add
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        ladd(i)
        for j in range(len(x)):
            idx = x[j]
            xxx = s[idx]
            c = 0
            for t in range(idx+1,ls):
                xxx = xxx +s[t]
                ladd(xxx)
                c += 1
                if c > k:
                    break
        if len(l) >= k:
            l = list(l)
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
K = int(input())
letters = []
for i in range(len(s)):
    for j in range(6):
        if(i + j > len(s)): break
        if(s[i:i + j] != ''): letters.append(s[i:i + j])
l = list(dict.fromkeys(letters))
l.sort()
print(l[K - 1])

Submission status: Accepted

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

Submission status: Accepted

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

al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    while (i + cnt <= N):
        if cnt == 7:
            break
        ans_list.append(S[i:i+cnt])
        cnt += 1

ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        while (i + cnt <= N):
            if cnt == 7:
                break
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))


ans_list.sort()
##print(ans_list)
print(ans_list[K-1])

Submission status: Accepted

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

A = []
for i in range(len(S)):  
    for j in range(1,i + 6):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
        
print(A[K-1])

Submission status: Accepted

Solution code:

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

result = []

for i in range(len_s):
  for j in range(i+1, i+1+5):
    x = s[i:j]
    result.append(x)

result = sorted(result)
len_r = len(result)

if len_r == 1 or K == 1:
  print(result[0])
  exit()

index = 0
for i in range(1, len_r):
  if result[i] != result[i-1]:
    index += 1
  if index == K-1:
    print(result[i])
    exit()

Submission status: Accepted

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

ans = set()
for i in range(len(S)):
  for j in range(1, 6): #　制約が最大K=5の為
    s = S[i:i+j]
    ans.add(s)
    
ans = sorted(ans)    
print(ans[K-1])