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

S = set([])
for i in range(len(s)):
    for j in range(i + 1, i + 1 + K):
        # print(f'{s[i:j]=}')
        S.add(s[i:j])
# print(f'{S=}')
# print(f'{sorted(S)=}')
ans = sorted(S)[K - 1]
print(ans)

Submission status: Accepted

Solution code:
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_)
print(S_[K-1])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

	bruh = {}
	for i  in range(1, k + 1): # length
		for j in range( n - ( i - 1)): # start 
			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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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()
#print(cand)
ans = cand.pop(0)
k -= 1
while k != 0:
    temp = cand.pop(0)
    if temp == ans:continue 
    ans = temp
    k -= 1

print(ans)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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('')

Submission status: Accepted

Solution code:
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
        # print(k, d[0:k], x, d[k:])
        if l < 5:
            d = d[0:l] + [x] + d[l:]
            d = d[0:5]
        # print(f"->{d}")
# l = list(d)
# l.sort()
# print(l)
# if l[0] == '':
    # l = l[1:]

print(d[k-1])

Submission status: Accepted

Solution code:
from collections import defaultdict
import string
s = input()
K = int(input())
location = defaultdict(list)
for i, s_i in enumerate(s):
    location[s_i].append(i)
count = 0
s_list = []
for c in string.ascii_lowercase[:26]:
    if location[c] == []:
        continue
    for idx in location[c]:
        for i in range(K):
            if idx + i + 1 > len(s):
                break
            if s[idx:idx+i+1] in s_list:
                continue
            s_list.append(s[idx:idx+i+1])
    count += 1
    if count == K:
        break
s_list.sort()
print(s_list[K-1])

Submission status: Accepted

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

# check
case = []
append = case.append
for i in range(1, K + 1):
    for idx in range(0, len(s) - (i - 1)):
        if s[idx:idx + i] not in case:
            append(s[idx:idx + i])
case.sort(reverse=True)

print(case[-K])

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
ttl = []
for i in range(N):
    for j in range(N - i):
        ttl.append(S[j:j+i+1])
    if i > K:
        break
ttl = sorted(list(set(ttl)))
print(ttl[K-1])

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
cnt = {i: [] for i in range(N)}
for i in range(N):
    for j in range(N - i):
        s = S[j:j+i+1]
        l = len(s)
        if s not in cnt[l-1]:
            cnt[l-1].append(s)
    if i > K:
        break
ttl = []
for k, v in cnt.items():
    ttl.extend(v)
ttl.sort()
print(ttl[K-1])

Submission status: Accepted

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

sl = [s]
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if j - i > k:
            break
        ss = s[i:j]
        sl.append(ss)
sl = sorted(list(set(sl)))
print(sl[k-1])

Submission status: Accepted

Solution code:
import re

s = input()
n = len(s)
k = int(input())
l = []
for i in range(26):
  m_list = [m.start() for m in re.finditer(chr(ord('a')+i), s)]
  #print(m_list)
  
  for start in m_list:
    c=1
    while start + c <= n and c <= 5:
      if not s[start:start+c] in l:
        l.append(s[start:start+c])
      c += 1
  if len(l) >= k:
    break
#print(l)
print(sorted(l)[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
K = ir()
cand = set()
length = len(S)
for i in range(length):
    for j in range(1, 6):
        cand.add(S[i:i+j])

answer = sorted(list(cand))[K-1]
print(answer)

Submission status: Accepted

Solution code:
def main():
    S = input()
    k = int(input())
    setS = set(list(S))
    count = 0
    ans = []
    for j in range(1, k + 1):
        for i in range(len(S) - j + 1):
            ans.append(S[i:i + j])
    ans = sorted(list(set(ans)))
    print(ans[k - 1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    #sに含まれる文字を一文字ずつ抽出する.
    #ここで抽出した文字を組み合わせて辞書順に文字列を構成していく
    l = sorted(list(set(s)))

    #cnd:=構成した文字列を辞書順に格納するリスト
    cnd = []

    #f(sub):=subから構成可能なK文字以下のSの部分文字列を構成する関数

    #計算量について
    #長さNの文字列から作るsubstringのうち長さが5以下のsubstringの数を計算する
    #長さ5のsubstirngは(N-5+1)個
    #長さ4のsubstringは(N-4+1)個
    #同様に長さ1まで考えて、合計すると約5N個となる

    def f(sub):
        cnd.append(sub)
        if len(sub) <= K: 
            #lから選んでsubに一文字追加する
            for i in l:
                nx = sub+i
                #if nx in s:はO(N)
                if nx in s:
                	f(nx)
    #O(N^2K)
    for i in l:
        f(i)
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    #sに含まれる文字を一文字ずつ抽出する.
    #ここで抽出した文字を組み合わせて辞書順に文字列を構成していく
    l = sorted(list(set(s)))

    #cnd:=構成した文字列を辞書順に格納するリスト
    cnd = []

    #f(sub):=subから構成可能なK文字以下のSの部分文字列を構成する関数

    #計算量について
    #長さNの文字列から作るsubstringのうち長さが5以下のsubstringの数を計算する
    #長さ5のsubstirngは(N-5+1)個
    #長さ4のsubstringは(N-4+1)個
    #同様に長さ1まで考えて、合計すると約5N個となる

    def f(sub):
        cnd.append(sub)
        if len(sub) <= K: 
            #lから選んでsubに一文字追加する
            for i in l:
                nx = sub+i
                #if nx in s:はO(N)
                if nx in s:
                    return f(nx)
    #O(N^2K)
    for i in l:
        f(i)
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    #sに含まれる文字を一文字ずつ抽出する.
    #ここで抽出した文字を組み合わせて辞書順に文字列を構成していく
    #K<=5だから高々26^5個の文字列を構成することになる
    l = sorted(list(set(s)))
    #cnd:=構成した文字列を辞書順に格納するリスト
    cnd = []
    #f(sub):=subから構成可能なK文字以下のSの部分文字列を構成する関数
    def f(sub):
        cnd.append(sub)
        if len(sub) < K: 
            #lから選んでsubに一文字追加する
            for i in l:
                nx = sub+i
                if nx in s:
                    return f(nx)
    for i in l:
        f(i) 
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(1000000)

def main():
    s = readline().rstrip().decode()
    K = int(readline())
    #sに含まれる文字を一文字ずつ抽出する.
    #ここで抽出した文字を組み合わせて辞書順に文字列を構成していく
    #K<=5だから高々26^5個の文字列を構成することになる
    l = sorted(list(set(s)))
    #cnd:=構成した文字列を辞書順に格納するリスト
    cnd = []
    #f(sub):=subから構成可能なK文字以下のSの部分文字列を構成する関数
    def f(sub):
        cnd.append(sub)
        if len(sub) < K: 
            #lから選んでsubに一文字追加する
            for i in l:
                nx = sub+i
                if nx in s:
                    f(nx)
    for i in l:
        f(i) 
    print(cnd[K-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = sorted(set(subs_list))
print(ans[k-1])

Submission status: Accepted

Solution code:
s = list(input())
K = int(input())
t = sorted(list(set(s[:]))) 
p = set()
for i in range(len(s)):
    for j in range(1, K+1):
        if i+j <= len(s):
            p.add("".join(s[i:i+j]))

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
c = []
for i in range(len(s)):
    for j in range(k): c.append(s[i:i+j+1])
c.sort()
pre = ''
for x in c:
    if pre == x: continue
    k -= 1
    if k == 0:
        print(x)
        break
    pre = x

Submission status: Accepted

Solution code:
s = input()
k = int(input())
que = []

def insert(t):
    global que
    for i in range(len(que)):
        if t < que[i]:
            que.insert(i, t)
            if len(que) > 5:
                que = que[:5]
            return
        if que[i] == t:
            return
    if len(que) < 5:
        que.append(t)

for i in range(len(s)):
    for j in range(i+1, min(len(s)+1, i+6)):
        t = s[i:j]
        insert(t)

print(que[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# print('s',s,'k',k)
c = set()
for i in range(n):
    # print(s[i:i+5])
    t = s[i:i+5]
    for j in range(1,5+1):
        # print(t[:j])
        c.add(t[:j])

c = list(c)
c.sort()
# print(*c,sep='\n')
print(c[k-1])

Submission status: Accepted

Solution code:
s = list(input())
K = int(input())
sub_list = []
for i in range(1, min(K+1, len(s)+1)):
    for j in range(len(s) - i + 1):
        sub = "".join(s[j:j+i])
        if sub not in sub_list:
            sub_list.append(sub)
sub_list.sort()
print(sub_list[K-1])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

def main():
	s = input()
	K = INT()

	strings = set()
	for  i in range(1, K+1): #文字列の長さ : K番目で長さがK以上のを考える必要はない。
		for j in range(len(s)-i+1): #スタート地点
			#print(j, i)
			strings.add(s[j:j+i])

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

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

s = input()
K = INT()


substr = []

for l in range(len(s)):
	r = l+1
	while r < len(s)+1:
		#print(l, r, substr)
		if bisect(substr, s[l:r]) == 5:
			break
		elif s[l:r] in substr:
			r += 1
		elif s[l:r] not in substr:
			insort(substr, s[l:r])
			substr = substr[:5]
			if s[l:r] in substr:
				r += 1


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = []

for i in range(min(K, N)):
  for j in range(N-i):
    ans.append(s[j:j+i+1])
  
ans.sort()
count = 0
now = '0'
for i in range(len(ans)):
  if ans[i] != now:
    count += 1
    now = ans[i]
    if count == K:
      print(now)
      exit()

Submission status: Accepted

Solution code:
s = input()
k = int(input())
d = set()
for n in range(1, 6):
    for i in range(len(s)):
        if i+n <= len(s):
            d.add(s[i:i+n])
sd = sorted(d)
print(sd[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
lst = sorted(list(set(s)))
tank = []
for tg in lst:
    for i in range(len(s)):
        if s[i]==tg:
            for j in range(k):
                if i+j<=len(s) and (s[i:i+j+1] not in tank):
                    tank.append(s[i:i+j+1])
    if len(tank) >= k:
        break
tank.sort()
print(tank[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
se = set()
for i in s:
    se.add(i)
if len(s) > 1:
    for i in range(len(s)-1):
        se.add(s[i]+s[i+1])
if len(s) > 2:
    for i in range(len(s)-2):
        se.add(s[i]+s[i+1]+s[i+2])
if len(s) > 3:
    for i in range(len(s)-3):
        se.add(s[i]+s[i+1]+s[i+2]+s[i+3])
if len(s) > 4:
    for i in range(len(s)-4):
        se.add(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
se = sorted(se)
print(se[k-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
A = []
for i in range(len(S)):
    for j in range(1,6):
        a = S[i:i+j]
        A.append(a)   
        #print(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
S = list(sys.stdin.readline().rstrip())
K = int(sys.stdin.readline().rstrip())
res = []
for k in range(K):
    for i in range(len(S)- k):
        res.append("".join(S[i:i+k+1]))
res = list(set(res))
res.sort()
print(res[K - 1])

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

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

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

Submission status: Accepted

Solution code:
s,K = open(0).read().split()
K = int(K)
ss = set()
temp = set([''])
for x in s:
    temp = set([''.join((y,x)) for y in temp if len(y) <= 4])
    ss = ss | temp
    temp.add('')
l = list(ss)
l.sort()
print(l[K-1])

Submission status: Accepted

Solution code:
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if len(string)>k:
            break
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
K = int(input())

Ans = []
for k in range(5):
    for i in range(len(S)-k):
        s = S[i:i+k+1]
        if s not in Ans:
            Ans.append(s)

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

Submission status: Accepted

Solution code:
S = input()
K = int(input())
Ans = []

while len(Ans) < K:
    for i in range(26):
        if chr(97+i) in S and chr(97+i) not in Ans:
            f = chr(97 + i)
            Ans.append(f)
            break

    for i, s in enumerate(S):
        if s == f:
            for j in range(2, 2 + 10):
                if i + j > len(S):
                    break
                if S[i:i+j] not in Ans:
                    Ans.append(S[i:i+j])
    Ans.sort()
print(Ans[K-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()
K = I()
N = len(S)
bag = set()

for i in range(N):
  for j in range(i+1,N+1):
    if S[i:j] not in bag:
      bag.add(S[i:j])
      sortbag = sorted(list(bag))
      if len(sortbag) == 6:
        if S[i:j] not in sortbag[:-1]:
          bag = set(sortbag[:-1])
          break
        bag = set(sortbag[:-1])
print(sorted(bag)[K-1])