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 = 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)))
if '' in so:
    so.remove('')
    
print(so[k-1])

Submission status: Accepted

Solution code:
s = list(input().rstrip())
k = int(input())
ans_list = []

for i in range(len(s)):
    for j in range(i,len(s)+1):
        a = s[i:j]
        if len(a) > k:
            break
        a = "".join(a)
        ans_list.append(a)
        
ans_list = list(set(ans_list))
ans_list.sort()

print(ans_list[k])

Submission status: Accepted

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

Submission status: Accepted

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

substr_set = set()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

os = sorted(list(set(s).union()))

nth = 0
found = []
for o in os:
  samehead = []
  for i in range(len(s)):
    if s[i] == o:
      for j in range(i+1, len(s)+1):
        if j-i>K: break
        if s[i:j] in samehead: continue
        samehead.append(s[i:j])
  cands = sorted(samehead)
  if nth + len(cands) < K:
    found += samehead
    nth += len(cands)
    continue
  print(cands[K-nth-1])
  break

Submission status: Accepted

Solution code:
# coding: utf-8
s = input()
k = int(input())
sb_str = []
for i in range(len(s)+1):
    for j in range(1+i,len(s)+1):
        if len(s[i:j]) > 5:
            break
        if i < j:
            sb_str.append(s[i:j])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import pdb

def arrins(arr, s):
    for j in range(x):
        if s == arr[j]:
            break
        elif arr[j] == "" or s < arr[j]:
            for k in range(j, x - 1):
                arr[k + 1] = arr[k]
            arr[j] = s
            break

s = raw_input()
x = int(raw_input())

ic = [0 for i in range(30)]
length = len(s)
for j in range(length):
    c = ord(s[j:(j + 1)]) - ord('a')
    ic[c] += length - j

subs = ["" for i in range(5)]
for j in range(30):
    if ic[j] == 0:
         continue

    for k in range(length):
        if ord(s[k:(k + 1)]) == (j + ord('a')) :
            for l in range(1, length - k + 1):
                t = s[k:(k + l)]
                if subs[x - 1] != "" and t > subs[x - 1]:
                    break
                else:
                    arrins(subs, t)

                #pdb.set_trace()
            
    if subs[x - 1] != "":
        break

print subs[x - 1]

Submission status: Accepted

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

arr = []
length = min(5, len(s))
for i in range(len(s)):
    for j in  range(length + 1):
        arr.append(s[i:i+j])
arr = list(set(arr))
arr.remove('')
arr = sorted(arr)
print(arr[K - 1])

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

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

alphabets = 'abcdefghijklmnopqrstuvwxyz'

dic = []

for char in alphabets:
    
    index = 0
    ss = []
    while index != -1:
        index = s.find(char, index)

        if index != -1:
            tmp = s[index:index + 5]
            isSubstring = False
            for sss in ss:
                if sss.find(tmp) == 0:
                    isSubstring = True
                    break
            if isSubstring == False:
                ss.append(tmp)

            index += 1

    if  len(ss) > 0:
        ss.sort()
        for x in ss:
            for i in range(len(x)):
                if x[0:i+1] not in dic:
                    dic.append(x[0:i+1])
                    if len(dic) >= k:
                        break
        if len(dic) >= k:
            break

print(dic[k-1])

Submission status: Accepted

Solution code:
s=input()
n=int(input())
ss=[]
for i in range(len(s)):
  for j in range(5):
    ss.append(s[i:i+j+1])
ss.sort()

kk=1
for i in range(len(ss)):
  if kk==n:
    print(ss[i])
    break
  if ss[i]!=ss[i+1]:
    kk+=1

Submission status: Accepted

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

for i in range(len(s)):
    for j in range(i, min(len(s), i+5)):
        if s[i:j+1] not in substrings: substrings.append(s[i:j+1])

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

Submission status: Accepted

Solution code:
def main():
    #0.input
    s = input()
    K = int(input())
    
    #1. make subset
    subset = set()
    for k in range(1, min(len(s)+1, K+1)):
        start = 0
        while start <= len(s)-k:
            subset.add(s[start:start+k])
            start += 1
    
    subset_list = sorted(list(subset))
    print(subset_list[K-1])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

sset = set()

for i in range(1, 6):
    sset |= set([s[j:j+i] for j in range(0, len(s))])

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

Submission status: Accepted

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

for i in range(5):
    s_list = [s[j:j+i+1] for j in range(len(s)-i)]
    s_set_list = list(set(s_list))
    for m in range(len(s_set_list)):
        ans_list.append(s_set_list[m])

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

Submission status: Accepted

Solution code:
s_list = list(input())
k = int(input())
s_sort = sorted(s_list)
a_list = []
for s in s_sort:
    idx = s_list.index(s)
    for i in range(1, 6):
        a_list.append("".join(s_list[idx:idx+i]))
    s_list[idx] = "@"
a = list(set(a_list))
for i, s in enumerate(a):
    if "@" in s:
        a[i] = s.replace("@", s_sort[0])
a = sorted(a)
print(a[k - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
strs = input()
N = int(input())

Len = len(strs)

allstr = [] 
flag = 0

for i in range(Len):
    tmp = list(range(i+1))
    tmp.reverse()
    for j in tmp:
#        print(strs[Len-i-1:Len-j])
        allstr.append(strs[Len-i-1:Len-j])
        allstr2 = list(set(allstr))
        if len(allstr2) > 5:
            if allstr[5:6] > allstr[4:5] and flag == 1:
#                print(allstr[5:6], allstr[4:5])
                allstr = allstr[0:5]
                break
            allstr2.sort()
            allstr = allstr2[0:5]
            flag = 1
#            print(allstr2)
        

allstr2 = list(set(allstr))        
allstr2.sort()

print(allstr2[N-1])

Submission status: Accepted

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

substring = {}

for i in range(len(s)):
    for j in range(i+1, i+1+k):
        # print('i={}, j={} s[{}:{}]={}'.format(i,j,i,j,s[i:j]))
        substring[s[i:j]] = True


words = [item[0] for item in substring.items()]
sorted_words = sorted(words)

print(sorted_words[k-1])

Submission status: Accepted

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

pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

f = set()
for c in range(97, 123):
    for i in pos[c]:
        for j in range(x):
            f.add(s[i:i+j+1])
    if len(f) >= x:
        break

p = [u for u in f]
p.sort()
print(p[x - 1])

Submission status: Accepted

Solution code:
import sys
import math

results = set()


s = sys.stdin.readline().strip()
K = int(sys.stdin.readline().strip())


chars = set(list(s))

for c in sorted(list(chars)):
    t = s

    ss = set()
    while True:
        i = t.find(c)
    
        if i == -1:
            break

        ss.add(t[i:])

        t = t[i+1:]

    for sa in sorted(list(ss)):
        for j in range(1, len(sa)+1):
            results.add(sa[:j])
            if len(results)==K:
                print(sa[:j])
                quit()

Submission status: Accepted

Solution code:
def f(myC, s, chrs, lst, k):
    if len(lst) == k:
        print(lst[k - 1])
        exit()
    else:
        for c in chrs:
            buf = myC + c
            if buf in s:
                lst += [buf]
                ##print(lst)
                f(buf, s, chrs, lst, k)

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

    chrs = sorted(list(set(s)))
    lst = f('', s, chrs, list(), k)

Submission status: Accepted

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

kouho = [s]# for x in range(K)]

for atama in range(len(s)):
    for offset in range(K):
        tes = s[atama:atama+offset+1]
        if tes in kouho:
            continue
        kouho.append(tes)
        kouho = sorted(kouho)
        if len(kouho) > K:
            kouho.pop()

print(kouho[K-1])

Submission status: Accepted

Solution code:
s=input()
k=int(input())
moji=sorted(list(set(s)))
ans=[moji[0]]
mojinum=0
if k==1:
    print(ans[0])
    import sys
    sys.exit()
while(True):
    for r in range(len(moji)):
        if ans[-1]+moji[r] in s:
            ans.append(ans[-1]+moji[r])
            break
        elif r==len(moji)-1:
            mojinum+=1
            ans.append(moji[mojinum])
    if len(ans)>=k:
        break
print(ans[k-1])

Submission status: Accepted

Solution code:
#import time

str = raw_input()
K = int(raw_input())

#t_start = time.time()

#print str, K,  len(str)

#dic = []
dic = set()

i = 1

#while i <= len(str):
while i <= K:
    idx = 0
    while True:
        head = idx
        tail = i + idx
        if tail > len(str):
            break
        else:
#            dic.append(str[head:tail])
            dic.add(str[head:tail])
            idx = idx + 1

    i = i + 1


#dic_set = list(set(dic))
#dic_set.sort()
#print dic_set

dic_set = list(dic)
dic_set.sort()


print dic_set[K-1]
#print time.time() - t_start

Submission status: Accepted

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


l = list(s)
alphabet = sorted(list(set(l)))

num = 0
for a in alphabet:
    cand = []
    n = s.count(a)
    l = list(s)
    for i in range(n):
        ind = l.index(a)
        for j in range(k):
            cand.append(s[ind+i: ind+j+1+i])
        l.remove(a)
    cand = list(set(cand))
    if len(cand) >= k:
        break
    else:
        num += len(cand)
print(sorted(cand)[k-num-1])

Submission status: Accepted

Solution code:
ss = input()
k = int(input())
save = []
num = ord("a")

while True:
  lst = []
  c = chr(num)
  for i in range(len(ss)):
    if ss[i] == c:
      lst.append(i)
  for ind in lst:
    for j in range(1,k + 1):
      if ind + j <= len(ss):
        save.append(ss[ind:ind + j])
#  print(save)

  if(len(list(set(save)))) >= k:
    flag = True
    break
  num += 1

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

Submission status: Accepted

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

s = input()
K = int(input())
dic = []

for i in range(len(s)):
    for j in range(i+1, i+6):
        if s[i:j] not in dic:
            dic.append(s[i:j])
dic.sort()
print(dic[K-1])

Submission status: Accepted

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

li = sorted(list(set(s)))
hitList = []

def oneMoreChar(moji):
    hitList.append(moji)
    if len(hitList) < K:
        for i in range(len(li)):
            if moji+li[i] in s:
                return oneMoreChar(moji+li[i])
    else:
        pass

for char in li:
    oneMoreChar(char)

print(hitList[K-1])

Submission status: Accepted

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

	subs = set()
	if len(s) <= 50:
		for f in range(len(s)):
			for t in range(f, len(s)+1):
				subs.add(s[f:t])
	else:
		for f in range(len(s)):
			for t in range(f, f+6):
				subs.add(s[f:t])

	l = list(subs)
	l.sort()
	print(l[K])

Submission status: Accepted

Solution code:
def main():
    """
    1<=|s|<=5,000
    1<=K<=5
    """
    s = input()
    K = int(input())

    part(s, K)


def f(s, K):
    """
    K=1, sorted(s)[0]
    K=2, s[min_idx:min_idx+2]
        aabbaac

        min:a, next: aa
        aab<aac
    1-5文字: すべて異なる文字列なら1文字でよい

    minから5種類存在するなら不要
        K個以上存在する
    a: min
    aaaaa: 5th(aa,aaa,aaaaがあれば)

    abced: 完了
    babcd: 途中にaがあるから未完
     abcde: 完了,ただしaaaaaとかあったらNG
    """
    pass


def part(s, K):
    #s = "abcde" * 1000
    n = len(s)
    ss = set()
    for i in range(n):
        # 最初なぜかn文字まで繰り返していたが、辞書順を考えれば不要
        for j in range(i, i+K):
            subs = s[i:j+1]
            # print(subs, i, j, sep="\t")
            ss.add(subs)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

index = []

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

Submission status: Accepted

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

substringList = []
if(len(s) < 50):
    for i in range(len(s)):
            for j in range(i, len(s)):
                #print(i,j)
                if(s[i:j+1] in substringList):
                    pass
                else:
                    substringList.append(s[i:j+1])
else:
    for i in range(len(s)):
            for j in range(i, i+5):
                substringList.append(s[i:j+1])
#substringList = list(set(substringList))
print(sorted(list(set(substringList)))[K-1])

Submission status: Accepted

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

chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
         'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
         's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

current = ""

for i in range(K):
    if current == "":
        current = min(s)
        continue

    startIndexes = [m.start() for m in re.finditer(current, s)]
    candidates = [s[index:index+len(current)+1] for index in startIndexes]
    for candidate in candidates:
        if candidate == current:
            candidates.remove(candidate)
    if not candidates:
        current = min(s.replace(current[0], ""))
    else:
        current = min(candidates)

print(current)

Submission status: Accepted

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

subset_list = list(s)
subset_list += [s[i:i+2] for i in range(len(s)-1)]
subset_list += [s[i:i+3] for i in range(len(s)-2)]
subset_list += [s[i:i+4] for i in range(len(s)-3)]
subset_list += [s[i:i+5] for i in range(len(s)-4)]
subset_list = list(set(subset_list))
subset_list.sort()

print(subset_list[K-1])

Submission status: Accepted

Solution code:
s= str(input().strip())
K= int(input().strip())
parts = []
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        flg = 0
        if j-i > K:
            break
        parts.append(s[i:j])
v = sorted(parts)
vv = [v[0]]
tmp = v[0]
for k in range(1,len(v)):
    if v[k]!=tmp:
        vv.append(v[k])
        tmp = v[k]
    if len(vv)==K:
        break
        
print(vv[K-1])

Submission status: Accepted

Solution code:
s = input()
n = input()
ans = set([])
test = list(s)

for i in range(len(test)):
    s = test[i]
    ans.add(s)
    for j in range(i+1, min(i+5, len(test))):
        s = s + test[j]
        ans.add(s)
    
ans = list(ans)

ans.sort()
print(ans[int(n)-1])

Submission status: Accepted

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

list1=[]
for i in range(len(s)):
    if s[0:i].count(s[i])==0:
        list1.append(s[i])
        i +=1
    else:
        i+=1

i=0
for i in range(len(s)):
    if s[i:i+2] not in list1:
        list1.append(s[i:i+2])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+3] not in list1:
        list1.append(s[i:i+3])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+4] not in list1:
        list1.append(s[i:i+4])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+5] not in list1:
        list1.append(s[i:i+5])
    else:
        i+=1

list1=sorted(list1)
print(list1[int(K)-1])

Submission status: Accepted

Solution code:
from bisect import insort
s = input().strip()
k = int(input())

sublist = []
for i in range(len(s)):
    if len(sublist)>k:
        sublist = sublist[:k]
    for j in range(i+1,len(s)+1):
        if len(sublist)>=k and sublist[k-1]<s[i:j]:
            break
        if s[i:j] not in sublist and (len(sublist)<k or sublist[k-1]>s[i:j]):
            insort(sublist,s[i:j])

print(sublist[k-1])

Submission status: Accepted

Solution code:
# your code goes here

string = input()
N = int(input())

alpha = list(string)
soeji = 0
ans = []
length = len(alpha)
while len(ans) < N:
	fst = sorted(alpha)[soeji]
	indexes = [i for i, x in enumerate(string) if x == fst]
	for i in indexes:
		for j in range(N):
			if i+j+1 < length+1: 
				ans.append(''.join(alpha[i:i+j+1]))
				ans = list(set(ans))
	soeji += 1
print(sorted(ans)[N-1])

Submission status: Accepted

Solution code:

s = input()

K = int(input())

s2 = [i for i in s]
s3 = [i for i in s]
S = s2

S.sort()

S = S[:K]

S = list(set(S))

S.sort()

X = []
for w in S:
    for i in range(len(s3)):
        if s3[i]==w:
            k = min(len(s3)-i, K)
            for ki in range(k):
                word = s[i:i+ki+1]
                X.append(word)
                
X = list(set(X))
X.sort()

print(X[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
lst = []
if len(s) > 5:
    for i in range(1, 6):
        for j in range(len(s) - i + 1):
            lst.append(s[j:j + i])
else:
    for i in range(1, len(s) + 1):
        for j in range(len(s) - i + 1):
            lst.append(s[j:j + i])
ulst = list(set(lst))
ulst.sort()
print(ulst[k - 1])

Submission status: Accepted

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

len_s = len(s)
str_list = []
for i in range(len_s):
    j_lim = min(len_s-i+1, 6)
    for j in range(1, j_lim):
#        print(s[i:i+j])
        if(not(s[i:i+j] in str_list)):
            str_list.append(s[i:i+j])
        
#print(str_list)
s_str_list = sorted(str_list)
#print(s_str_list)
print(s_str_list[K-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
kouho = []
for i in range(len(S)):
    for j in range(1,K+1):
        kouho.append(S[i:i+j])
ans = sorted(set(kouho))
if "" in ans:
    ans = ans.remove("")
print (ans[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
alp = list(set(s))
alp.sort()
moji = []

for a in alp:
    for i, si in enumerate(s):
        if si == a:
            moji.append(s[i:i+1])
            moji.append(s[i:i+2])
            moji.append(s[i:i+3])
            moji.append(s[i:i+4])
            moji.append(s[i:i+5])
            moji = set(moji)
            moji = list(moji)

    if len(moji) > k-1:
        break
    
moji.sort()
print(moji[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
number = len(s)
word_list = []
for i in range(number):
  for j in range(1,6):
    if i+j > number:
      break
    word_list.append(s[i:i+j])

unique_list = list(set(word_list))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
lis =[]
for i in range(len(s)-4):
    lis.append(s[i:i+5])
    
for i in range(len(s)-3):
    lis.append(s[i:i+4])
    
for i in range(len(s)-2):
    lis.append(s[i:i+3])
    
for i in range(len(s)-1):
    lis.append(s[i:i+2])
    
for i in range(len(s)):
    lis.append(s[i:i+1])
    
nlist = list(set(lis))
nlist.sort()
print(nlist[K-1])

Submission status: Accepted

Solution code:
#coding: utf-8

s = input()
x = int(input())

single = []
for i in range(len(s)):
    single.append(s[i])

count = 0
result = []
ssingle = sorted(list(set(single)))
for i in range(len(ssingle)):
    for j in range(len(s)):
        if s[j] == ssingle[i]:
            for k in range(1,x+1):
                if k > len(s):
                    break
                if s[j:j+k] not in result:
                    result.append(s[j:j+k])
                result = sorted(result)
                if len(result) > len(s):
                    break
        if len(result) > len(s):
            break
    if len(result) > len(s):
        break
print(result[x-1])

Submission status: Accepted

Solution code:
from sys import stdin
from string import ascii_lowercase


def myfind(s, c):
    result = []
    for i, x in enumerate(s):
        if x == c:
            result.append(i)
    return result


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = []
    for x in ascii_lowercase:
        idxs = myfind(s, x)
        if not idxs:
            continue
        result.append(x)
        if len(result) >= K:
            break
        temp = sorted(list(set([s[x:] for x in idxs])))
        for y in temp:
            for z in range(len(y)):
                foo = y[: z + 1]
                if not foo in result:
                    result.append(foo)
                    if len(result) >= K:
                        break
            if len(result) >= K:
                break
        if len(result) >= K:
            break

    print(result[-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = list(input())
k = int(input())
l = []
for i in range(len(a)):
    # print(i)
    for j in range(1,k+1):
        # print(j)
        if(len(a) >= i+j):
            t = ''.join(a[i:i+j])
            l.append(t)
            # print(l)
l = list(set(l))
l.sort()
# print(l)
print(l[k-1])

Submission status: Accepted

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

s_list = []
for i in range(0, len(s)):
    for j in range(1, 1+k):
        if len(s_list) < k:
            s_list.append(s[i:i+j])
            s_list = list(set(s_list))
            s_list.sort()
        elif s_list[k-1] > s[i:i+j]:
            s_list.append(s[i:i+j])
            s_list = list(set(s_list))
            s_list.sort()
            s_list = s_list[:k]
    else:
        continue

dict_list = list(set(s_list))
dict_list.sort()

print(dict_list[k-1])

Submission status: Accepted

Solution code:
def suffix_array(s):
    def k(a):
        return s[a:]
    
    x = list(range(len(s)))
    x.sort(key=k)
    return x

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

    a = suffix_array(s)
    v = set()

    for i in a:
        for j in range(i + 1, len(s) + 1):
            v.add(s[i:j])
            if len(v) == k:
                print(s[i:j])
                return

main()

Submission status: Accepted

Solution code:
import sys
import math
if __name__ == "__main__":
   s = str(input())
   K = int(input())
   uniq = sorted(list(set(list(s))))
   buf = []
   for i in range(len(uniq)):
      buf.append(uniq[i])
      for j in range(len(s)):
         if s[j] == uniq[i]:
            fin = K
            if (len(s) - j) - K < 0:
               fin = (len(s) - j)
            for k in range(1, fin):
               buf.append(s[j:j+k+1])
   ans = sorted(list(set(buf)))
#   print(ans)
   print(ans[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
subs = []
for i in range(len(s)):
    for j in range(5):
        if s[i:i+j+1] not in subs:
            subs.append(s[i:i+j+1])
subs = sorted(subs)
# print(subs)
print(subs[k-1])

Submission status: Accepted

Solution code:
import re

s = input()
k = int(input())
ans = [min(s)]
i = 1
while True:
    if len(ans) == k:
        print(ans[-1])
        break
    else:
        base = ans[-1]
        sub = sorted(re.findall(base + '.', s))
        if len(sub) == 0:
            while True:
                if chr(ord(min(s))+i) in s:
                    ans.append(chr(ord(min(s))+i))
                    break
                else:
                    i += 1

        else:
            ans.append(sub[0])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = input()
    K = int(input())
    # s = 'aba'
    # s = 'atcoderandatcodeer'
    # K = 5

    candidates = set()
    for start in range(0, len(s)):
        for length in range(1, K + 1):
            candidates |= {s[start:start + length]}

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
sorted_s = sorted(list(set(s)))
l = len(s)

for c in sorted_s:
    str_list = set()

    for i, cc in enumerate(s):
        if cc == c:
            str_list |= set([s[i: i + j] for j in range(1, 6)])
            str_list = set(str_list)

    if K <= len(str_list):
        break
    K -= len(str_list)

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

Submission status: Accepted

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

smin = list(set(list(s)))
smin = sorted(smin)[0:5]


def search(st):
    ans = []
    cnt = 0
    for a in st:
        if len(set(ans)) >= 5:
            return ans
        for i in range(len(s)):
            if s[i] is a:
                for j in range(1,6):
                    ans.append(s[i:min(i+j,len(s))])

    
    return ans
    
b = list(set(search(smin)))
b = sorted(b)
if b[0] == '':
    del b[0]

print(b[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
n = len(s)
if n == 1:
    print(s)
elif n == 2:
    l2 = sorted(list(set([s[i:i+2] for i in range(n-1)])))
    print(l2[0])
elif n == 3:
    l1 = list(set(s))
    l2 = list(set([s[i:i+2] for i in range(n-1)]))
    l3 = list(set([s[i:i+3] for i in range(n-2)]))
    out = sorted(l1 + l2 + l3)
    print(out[k-1])
elif n == 4:
    l1 = list(set(s))
    l2 = list(set([s[i:i+2] for i in range(n-1)]))
    l3 = list(set([s[i:i+3] for i in range(n-2)]))
    l4 = list(set([s[i:i+4] for i in range(n-3)]))
    out = sorted(l1 + l2 + l3 + l4)
    print(out[k-1])
else:
    l1 = list(set(s))
    l2 = list(set([s[i:i+2] for i in range(n-1)]))
    l3 = list(set([s[i:i+3] for i in range(n-2)]))
    l4 = list(set([s[i:i+4] for i in range(n-3)]))
    l5 = list(set([s[i:i+5] for i in range(n-4)]))
    out = sorted(l1 + l2 + l3 + l4 + l5)
    print(out[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
ssorted = sorted(set(list(s)))
j = 0
dic = []
while len(dic) < K:
  w = ssorted[j]
  index = -1
  idxs =[]
  while True:
    index = s.find(w, index + 1)
    if index == -1:
      break
    else:
      idxs.append(index)
  dic += sorted(set([w] + 
                   [s[i:i+2] for i in idxs] +
                   [s[i:i+3] for i in idxs] +
                   [s[i:i+4] for i in idxs] +
                   [s[i:i+5] for i in idxs]))
  j += 1
print(dic[K-1])

Submission status: Accepted

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

lst = []
for n in range(97, 123):
    for i in range(0, len(arr)):
        if arr[i] == chr(n):
            ge = ""
            for j in range(0, 5):
                if i + j < len(arr):
                    ge = ge + (arr[i + j])
                    if ge not in lst:
                        lst.append(ge)
                else:
                    break
    if len(lst) > 5:
        break
lst.sort()
print(lst[k - 1])

Submission status: Accepted

Solution code:
def get_subs(l, c, n):
    # print('c = ' + str(c))
    canl = []
    for index, val in enumerate(l):
        if val == c:
            candidate = ''
            for i in range(n):
                if index + i < len(l):
                    candidate += l[index + i]
            canl.append(candidate)
    res = list(set(canl))
    # print(res)
    return res


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

cand = sorted(list(set(list(s))))
cand.reverse()
# print(cand)


subl = []
while len(subl) < K:
    c = cand.pop()
    n = 1
    while n <= K:
        canl = get_subs(list(s), c, n)
        subl.extend(canl)
        subl = list(set(subl))
        n += 1

subl = sorted(subl)
# print(subl)
print(subl[K-1])

Submission status: Accepted

Solution code:
s = list(input())
K = int(input())
list_s = []
for j in range(1,K+1):
    for i in range(len(s)-j+1):
        list_s.append(''.join(s[i:i+j]))
set_s = set(list_s)
sorted_s = sorted(set_s)
print(sorted_s[K-1])

Submission status: Accepted

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

for i in range(1, 6):
  l |= set([s[n:n+i] for n in range(0, len(s))])

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

Submission status: Accepted

Solution code:
import queue
qu = queue.PriorityQueue()
visited = set()
s = input()
K = int(input())
for i,v in enumerate(list(s)):
    qu.put((v,i,1))
counter = []
while not qu.empty() and len(counter) < K:
    string,index,length = qu.get()
    if string not in visited:
        counter.append(string)
    visited.add(string)
    if index + length < len(s):
        qu.put((s[index:index+length+1], index, length + 1))
print(counter[-1])

Submission status: Accepted

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

substring = []
for length in range(1,6):
    for start in range(0,len(s)+1-length):
        substring.append(s[start:start+length])

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

Submission status: Accepted

Solution code:
S = input()
K = int(input())
uniqueS = []
for s in S:
    if s not in uniqueS:
        uniqueS.append(s)
lenS = len(S)
ansS = []
uniqueS.sort()
for us in uniqueS:
    for i in range(lenS):
        for j in range(1,min(lenS-i+1,6)):
            if S[i] == us:
                if S[i:i+j] not in ansS:
                    ansS.append(S[i:i+j])
    if len(ansS) >= 5:
        break
ansS.sort()
print(ansS[K-1])