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:
def main(s, K):
    l = list()
    for i in range(len(s)):
        for k in range(1, K + 1):
            sub = s[i:i + k]
            if sub not in l:
                l.append(sub)
    l = sorted(l)
    return l[K-1]

s = input()
K = int(input())
res = main(s, K)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = int(input())
k = len(s)
substrings = set()
for i in range(k):
    for j in range(n):
        substrings.add(s[i:i+1+j])

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

Submission status: Accepted

Solution code:
str = input()
k = int(input())
 
substr = []
for i in range(len(str)):
  substr.extend([str[i:j] for j in range(i+1,i+6)])
 
substr = list(set(substr))
substr.sort()
print(substr[k-1])

Submission status: Accepted

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

s_set = set()
for i in range(len(s)):
    for j in range(i + 1, i + K + 1):
        if j > len(s) + 1:
            break
        s_set.add(s[i:j])
s_list = list(s_set)
s_list.sort()
print(s_list[K - 1])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    text = input()
    number = int(input())
    dic = []

    for text_len in range(1, min(len(text),number) + 1):
        for ss_len in range(0, len(text) - text_len + 1):
            word = text[ss_len:text_len + ss_len]
            if word not in dic:
                dic.append(word)

    dic = sorted(dic)

    print(dic[number - 1])

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    s = input()
    k = int(input())
    extracted = set()
    s_len = len(s)

    # See:
    # https://beta.atcoder.jp/contests/abc097/submissions/2497319
    for i in range(1, min(k, s_len) + 1):
        for j in range(s_len - i + 1):
            extracted.add(s[j:i + j])

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

Submission status: Accepted

Solution code:
import re

str = input()
k = int(input())

strl = list(set([c for c in str]))
strl.sort()

substring = []
for h in strl:
	compiled = re.compile(h)
	st = 0
	m = compiled.search(str, st)
	while m:
		sub = m.start()
		for i in range(sub, min(len(str), sub+5)):
			t = str[sub:i+1]
			if(not (t in substring)):
				substring.append(t)
		st = sub + 1
		m = compiled.search(str, st)
	
	if(len(substring)-len(strl) >= k-1):
		break


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

Submission status: Accepted

Solution code:
import sys
s = input()
K = int(input())
     
# sort_s = sorted(list(s))
temp = set()
# temp = []
for i in range(len(s)):
    for j in range(i+1,i+K+1):
        # if i >j:
        # print("{},{}".format(i,j))
        temp.add(s[i:j])
        # if i+j <= len(s):
            # temp.append(s[i:i+j])
ans = sorted(temp)
print(ans[K-1])

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    s = input()
    k = int(input())
    extracted = list()
    s_len = len(s)

    for i in range(1, min(k, s_len) + 1):
        start = 0
        ended = i

        for j in range(s_len - i + 1):
            sub_str = s[start:ended]

            if sub_str not in extracted:
                extracted.append(sub_str)

            start += 1
            ended += 1

    sorted_extracted = sorted(extracted)
    print(sorted_extracted[k - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
if len(s)<5:
    s_len = len(s)
else:
    s_len = 5
ans=list()
for length in range(1,s_len + 1):
    for pos in range(0,len(s)-length+1):
        tmp = s[pos:pos+length]
        if tmp not in ans:
            ans.append(tmp)
    ans.sort()
    if len(ans)>5:
        del ans[5:len(ans)+1]


print(ans[K-1])

Submission status: Accepted

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



# S = []
# for i in range(len(s)+1):
#     for j in range(i+1,len(s)+1):
#         if not(s[i:j] in S):
#             S.append(s[i:j])
#         # print(s[i:j])

S = set()

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

T = sorted([x for x in S])

print(T[k-1])

Submission status: Accepted

Solution code:
str=input()
K=int(input())
s=set()
for scope in range(1,K+1):
    for f in range(len(str)-scope+1):
        s.add(str[f:f+scope])
print(sorted([x for x in s])[K-1])

Submission status: Accepted

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

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

print(sorted([i for i in sub])[K - 1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
a=[]
l=len(s)
for i in range(l):
	for j in range(1,K+1):
		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())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from string import ascii_lowercase

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

sub_set = set()
append_cnt = 0

for top_c in ascii_lowercase:
    for idx, c in enumerate(s):
        if c == top_c:
            for i in range(1, 6):
                sub_set.add(s[idx:idx+i])
    if len(sub_set) >= K:
        break

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
D = []

for t in range(len(s)):
    for k in range(1,K+1):
        try:
            D.append(s[t:t+k])
        except:
            ValueError

print(list(sorted(set(D)))[K-1])

Submission status: Accepted

Solution code:
str = input()
K = int(input())
len = len(str)
se = set()
for k in range(1,min(5,len)+1):
  for i in range(len+1-k):
    se.add(str[i:i+k])
lis = list(se)

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

Submission status: Accepted

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

substrings = []
for i in range(len(s)):
    for j in range(len(s)-i+1):
        # print('i={}, i+j={}, s[i:i+j]={}'.format(i, i+j, s[i:i+j]))
        if j <= K and s[i:i+j] != '':
            substrings.append(s[i:i+j])
substrings = sorted(set(substrings))
print(substrings[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

l = len(s)
all = set()
for i in range(l):
    cnt = 0
    for j in range(i, l):
        all.add(s[i:j + 1])
        cnt += 1
        if cnt >= k:
            break

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

Submission status: Accepted

Solution code:
s=list(input())
k=int(input())
t=set({})
for i in range(min(k,len(s))):
    for j in range(len(s)-i):
        t.add("".join(s[j:i+j+1]))
print(sorted(t)[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=raw_input()
k=input()
t=len(s)
a=[]
for i in  range(0,t):
    for j in range(i,min(i+5,t)):
        a.append(s[i:j+1])
a=sorted(set(a))
print a[k-1]

Submission status: Accepted

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

#alphabet = "abcdefghijklmnopqrstuvwxyz"
candidates = []

for i in range(len(s)):
  for j in range(i + 1, len(s) + 1):
    if not s[i:j] in candidates:
      candidates += [s[i:j]]
    if len(s[i:j]) >= k:
      break

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

instr = input()
target = int(input())

# 部分文字列の一覧リストを作成
str_list = []
for i in range(len(instr)):

	# 開始位置はi+1以降(i > jはやる意味ない)
	for j in range(i+1, len(instr)+1):
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		str_list.append(instr[i:j])

# 重複削除
str_list = list(set(str_list))
# 昇順ソート
str_list.sort()

print(str_list[target-1])

Submission status: Accepted

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

instr = input()
target = int(input())

# 部分文字列の一覧リストを作成
str_list = []
for i in range(len(instr)):

	# 開始位置はi+1以降(i > jはやる意味ない)
	for j in range(i+1, len(instr)+1):
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		str_list.append(instr[i:j])

		j += 1
	i += 1

# 重複削除
str_list = list(set(str_list))
# 昇順ソート
str_list.sort()

print(str_list[target-1])

Submission status: Accepted

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

def n_th_singleton(n, moji):
    min = moji[0]
    min_nth_itimoji = []
    if n >= 2:
        nth_soeji = [j for j in range(len(moji)) if hikaku(moji[j], moji, n_th_singleton(n-1, moji))]
        #print(nth_soeji)
        min = moji[nth_soeji[0]]
        for i in nth_soeji:
            if (min >= moji[i]):
                min = moji[i]
                min_nth_itimoji.append(i)
    else:
        for i in range(len(moji)):
            if min >= moji[i]:
                min = moji[i]
                min_nth_itimoji.append(i)
    #print(min_nth_itimoji)
    return min_nth_itimoji

def hikaku(singleton, original_moji, soeji_list):
    for j in soeji_list:
        if singleton <= original_moji[j]:
            return False
    return True

def solution(moji, num):
    sucesseive_length = 0
    n = 1
    while sucesseive_length < num:
        n_list = n_th_singleton(n, moji)
        n_sorted_submoji_list = [moji[i:] for i in n_list]
        n_sorted_submoji_list.sort()
        not_choufuku_list = []
        #print(n_sorted_submoji_list)

        j = 0
        while j < len(n_sorted_submoji_list):
            for k in range(1, len(n_sorted_submoji_list[j])+1):
                if (n_sorted_submoji_list[j][:k] not in not_choufuku_list) and sucesseive_length < num:
                    sucesseive_length += 1
                    not_choufuku_list.append(n_sorted_submoji_list[j][:k])
                    #print(not_choufuku_list)
            if sucesseive_length == num:
                    #print(not_choufuku_list)
                return not_choufuku_list[-1]
            j += 1
        #print(sucesseive_length)
        n += 1


print(solution(mojiretu, K))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
N = len(s)
K = int(input())
ss = set()
for i in range(N):
    for j in range(K):
        if i + j < N:
            ss.add(s[i:i+j+1])
print(sorted(ss)[K-1])

Submission status: Accepted

Solution code:
#K-th Substring

#入力
s = input()
k = int(input())
 
 #計算
sub = set()

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

sub = list(sub) 
sub.sort()

#出力
print(sub[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
st = set()
for i in range(len(s)):
    j = 1
    while j <= k and i+j <= len(s):
        st.add(s[i:i+j])
        j += 1
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))

Submission status: Accepted

Solution code:
s = input()
K = int(input())
list = ["zzz" for i in range(K)]
for i in range(len(s)):
    for j in range(len(s)-i):
        if j > 5:
            continue
        if len(list) < K or s[i : i+j+1] < list[K-1]:
            if not s[i : i+j+1] in list:
                list[K-1] = s[i : i+j+1]
                list.sort()
print(list[K - 1])

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
subs = []
for i in range(min(k,len(s))):
  for j in range(len(s)-i):
    subs.append(''.join(s[j:j+i+1]))
subs = list(set(subs))
subs.sort()
#print(subs)
print(subs[k-1])

Submission status: Accepted

Solution code:
import heapq

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

for i in range(n+1):
    j=1
    while j<=k and i+j<=n:
        ans.add(s[i:i+j])
        j+=1


ansh=[]
for ss in ans:
    heapq.heappush(ansh,ss)
for _ in range(k-1):
    heapq.heappop(ansh)
print(ansh[0])

Submission status: Accepted

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

instr = input()
target = int(input())

# 部分文字列の一覧リストを作成
str_list = []
for i in range(len(instr)):

	for j in range(i, len(instr)+1):
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		if i < j:
			str_list.append(instr[i:j])

		j += 1
	i += 1

# 重複削除
str_list = list(set(str_list))
# 昇順ソート
str_list.sort()

print(str_list[target-1])

Submission status: Accepted

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


sublist = []
for start in range(len(s)):
    end = min(start + k, len(s))
    for end in range(start+1, end + 1):
        sublist.append(s[start:end])

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

Submission status: Accepted

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

dic = [s[i:j] for i in range(len(s)) for j in range(i, i + k + 1)]
print(sorted(set(dic))[k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
sub = set()
for i in range(len(s)):
    for j in range(i+1,i+1+k):
        if(j > len(s)):
            break
        sub.add(s[i:j])
sub = sorted(sub)
print(sub[k-1])

Submission status: Accepted

Solution code:
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(min(len(ss),K)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
K = int(input())


def substring(s, K):
    substrings = []
    length = len(s)
    for i in range(length):
        for j in range(1, K+1):
            if i + j > length:
                break
            substrings.append(s[i:i + j])
    unique_substrings = list(set(substrings))
    unique_substrings.sort()
    return unique_substrings[K - 1]


print(substring(s, K))

Submission status: Accepted

Solution code:
s = input()
K = int(input())
mj = []
for i in range(1,6):
    for j in range(0,len(s)-i+1):
        mj.append(s[j:j+i])
mj_uni = list(set(mj))
mj_stz = sorted(mj_uni)
print(mj_stz[K-1])

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
ans=set()
for i in range(n):
    for j in range(i+1,i+k+1):
        ans.add(s[i:j])
ans=sorted(ans)
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(i+1,i+k+1):
        ans.append(s[i:j])
ans=list(set(ans))
ans.sort()
if "" in ans:
    ans.pop(0)
print(ans[k-1])

Submission status: Accepted

Solution code:
a = input()
k = int(input())
sstr = set()

for i in range(len(a)):
    for j in range(i+1, i+k+1):
        sstr.add(a[i:j])

sstr = sorted(sstr)

print(sstr[k-1])

Submission status: Accepted

Solution code:
def substring():
    a = input()
    K = int(input())
    atra = set()
    
    for i in range(len(a)):
        for j in range(i + K + 1):
            if i >= j:
                continue
            atra.add(a[i:j])
    atra = sorted(atra)
    print(atra[K - 1])
    
if __name__ == '__main__':
    substring()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,K+1):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, i + K + 1):
            if j <= len(S):
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans
 
S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

Submission status: Accepted

Solution code:
s = input()
K = int(input())
L = len(s)
cand = []

if L > 5:
    c = []
    order = sorted(list(s))
    for i in range(L):
        if order[i] in c:
            pass
        else:
            c.append(order[i])
            if len(c) == 5:
                break
else:
    c = list(s)

for i in range(L):
    if s[i] in c:
        for j in range(i+1,min(i+K+1,L+1)):
            cand.append(s[i:j])
cand.sort()

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()

i = 0
while True:
    K -= 1
    if K == 0:
        print(cand[i])
        break
    i += 1
    while(cand[i] == cand[i-1]):
        cand.pop(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
print(sorted({s[i:i+j] for i in range(len(s)) for j in range(6)})[int(input())])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from string import ascii_lowercase


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = []
    for c in ascii_lowercase:
        for text in sorted([s[i:] for i, x in enumerate(s) if x == c]):
            for i in range(len(text)):
                if not text[:i + 1] in result:
                    result.append(text[:i + 1])
                    if len(result) == K:
                        print(result[-1])
                        return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = raw_input()
k = input()
S = set()
for l in range(1,k+1):
    for i in range(len(s)-l+1):
        S.add(s[i:i+l])
print sorted(S)[k-1]

Submission status: Accepted

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

M=len(s)
sss=set()
for i in range(M):
    for j in range(i+1,i+k+1):
        tmp = s[i:j]
        sss.add(tmp)
l = list(sss)
l.sort()
print(l[k-1])

Submission status: Accepted

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


L=[]

for i in range(l):
    L=L+[s[i]]

for i in range(l-1):
    L=L+[s[i]+s[i+1]]

for i in range(l-2):
    L=L+[s[i]+s[i+1]+s[i+2]]

for i in range(l-3):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]]
    
for i in range(l-4):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]]


M=sorted(list(set(L)))

print(M[K-1])

Submission status: Accepted

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


L=[]

for i in range(l):
    L=L+[s[i]]

for i in range(l-1):
    L=L+[s[i]+s[i+1]]

for i in range(l-2):
    L=L+[s[i]+s[i+1]+s[i+2]]

for i in range(l-3):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]]
    
for i in range(l-4):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]]


M=sorted(list(set(L)))

print(M[K-1])

Submission status: Accepted

Solution code:

import math

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

init = sorted(set(list(s)))[:K]
n=0
z=[]
while(n<len(s)):
    if n > 500: break
    x=[]
    for i in range(len(s)-n):
        if s[i] in init:
            x.append(s[i:i+n+1])
    y = sorted(set(x+z))
    z = y[:K]
    n += 1
print(sorted(set(z))[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(5+i+1, len(s)+1)):

    subs.add(s[i:j])
subs = list(subs) 
subs.sort()
print(subs[k-1])

Submission status: Accepted

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

_all = []

for i in range(1, min(k+1, len(s)+1)):
	for j in range(len(s)-i+1):
		sub = s[j:j+i]
		if sub not in _all:
			_all.append(sub)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s=raw_input()
K=input()
l=len(s)

a=set()
for diff in range(1,5+1):
	for i in range(l):
		a.add(s[i:i+diff])

b=list(a)
b.sort()

print b[K-1]

Submission status: Accepted

Solution code:
s=str(input())
K=int(input())
l=len(s)
a=[]
for i in range(0,l):
    for j in range(i,min(l,i+5)):
        a.append(s[i:j+1])
a=sorted(list(set(a)))
print(a[K-1])

Submission status: Accepted

Solution code:
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, i + K + 1):
            if j <= len(S)+1:
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

Submission status: Accepted

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

strs = set()
for i in range(len(s)):
    for j in range(i + K + 1):
        if i >= j:
            continue

        strs.add(s[i:j])

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

Submission status: Accepted

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

    lst = list(S)
    apnd = lst.append
    l = len(S)
    for n in range(2, 6):
        for i in range(l - n + 1):
            apnd(S[i:i+n])

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

main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

s = ns()
k = ni()
ans = []

for i in range(len(s)):
    ans.append(s[i])
    if i < len(s)-1:
        t = i+2
        while True:
            ans.append(s[i:t])
            if t == len(s):
                break
            t += 1
            if t - i > 5:
                break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
      if len(s[k:l+k+1])==z:
        break
print(sorted(set(d))[z-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = set()
    for i in range(l):
        for j in range(i+K+1):
            t = s[i:j]
            if len(t):
                substrings.add(t)
    ans = list(substrings)
    ans.sort()
    return ans[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

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

sub_lst = sorted(list(sub_str))
print(sub_lst[k-1])

Submission status: Accepted

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min(6,k-i+1)):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = input()
    k = int(input())

    subs = set()
    for ln in range(1, k + 1):
        for i in range(len(s)):
            subs.add(s[i:(i + ln)])
    print(sorted(list(subs))[k - 1])

Submission status: Accepted

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min({6,k-i+1})):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Accepted

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

u = [s[i:i+j+1] for i in range(len(s)) for j in range(k+1)]

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

Submission status: Accepted

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


list_pair = []
i = 0
while i <= len(s):
    for j in range(1,min(len(s)-i+1,k+1)):
#        print(j,s[i:i+j])
        list_pair.append(s[i:i+j])
    i = i + 1

list_pair = list(set(list_pair))

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

Submission status: Accepted

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

Submission status: Accepted

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

l = []
for i in range(1, min(len(s)+1,k+1)):
    for j in range(0,len(s)):
        t = s[j:j+i]
        if len(t) != i:break
        if t in l: continue
        l.append(t)
l = sorted(l)
print(l[k-1])

Submission status: Accepted

Solution code:
# coding: utf-8

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

n = len(s)

# sにでてくる英小文字1文字ごとをUTF-8コードのリストで管理する
pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

strset = set()
for c in range(ord('a'), ord('z')+1):
    for i in pos[c]:
        for j in range(K):
            strset.add(s[i:i+j+1])

    # 最初の1文字が最も若い英小文字で始まるすべての部分文字列がK以上なら、それより後ろになる文字列は調べなくて良い
    if len(strset) > K:
        break


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

Submission status: Accepted

Solution code:
#coding: utf-8
s=input()
k=int(input())
l=list(s)
ans=[]
i=0
j=1
while(j<=k):
    while(i+j<=len(l)):
        ans.append(s[i:i+j])
        i+=1
    j+=1
    i=0
ans=sorted(ans)
n=0
while(n+1<=len(ans)-1):
    if(ans[n]==ans[n+1]):
        ans.pop(n)
    else:
        n+=1
print(ans[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
t = sorted(list(s))
num = []
while len(num) < k:
    a = t.pop(0)
    indexes = [i for i, x in enumerate(s) if x == a]
    z = 0
    while z < len(indexes):
        i = indexes[z]
        q = 1
        while q <= 5:
            if s[i:i + q] not in num:
                num.append(s[i:i + q])
            q += 1
        z += 1

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
jisho = []
for i in range(1,min(len(s)+1,6)):
    for j in range(0,len(s)-i+1):
        jisho.append(s[j:j+i])
jisho = list(set(jisho))
jisho.sort()

print(jisho[K-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

e = input()
num =int(input())

a = []

for i in range(len(e)) :
    for j in range(i+1,i+6):
        if e[i:j] not in a:
            a.append(e[i:j])

b = list(set(a))
b.sort()
print(b[num-1])

Submission status: Accepted

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


e=len(s)
l=[]
for i in range(e):
	for j in range(i+1, e+1):
		a = s[i:j]
		if len(a)>k: break
		#print(i,j,a)
		l.append(a)


l=list(set(l))
l.sort()
#print(l)

print(l[k-1])

Submission status: Accepted

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

for i in range(len(s)):
    for plus in range(k+1):
        st = s[i:i + plus]
        kouho.append(st)
so = list(sorted(set(kouho)))
so.remove('')
print(so[k-1])

Submission status: Accepted

Solution code:
#coding:utf-8

s = raw_input()
K = int(raw_input())

s_lists = []

for i in range(K):
    for j in range(len(s) - i):
        sub_s = s[j : j + i + 1]
        #print sub_s
        if not (sub_s in s_lists):
            s_lists.append(s[j : j + i + 1])

s_lists.sort()

#print s_lists

print s_lists[K - 1]