Problem:
 Score : 300 points    Problem Statement You are given a string s .
Among the different substrings of s , print the K -th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s .
For example, if s  =  ababc , a , bab and ababc are substrings of s , while ac , z and an empty string are not.
Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j} .      Constraints  1  ≤  |s|  ≤  5000  s consists of lowercase English letters.  1  ≤  K  ≤  5  s has at least K different substrings.       Partial Score  200 points will be awarded as a partial score for passing the test set satisfying |s|  ≤  50 .         Input Input is given from Standard Input in the following format:  s  K       Output Print the K -th lexicographically smallest substring of K .        Sample Input 1 aba
4      Sample Output 1 b  s has five substrings: a , b , ab , ba and aba .
Among them, we should print the fourth smallest one, b .
Note that we do not count a twice.       Sample Input 2 atcoderandatcodeer
5      Sample Output 2 andat       Sample Input 3 z
1      Sample Output 3 z

Solution (Python):


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

Solution (Python):

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

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

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

        if(not(s[i:i+j] in str_list)):
            str_list.append(s[i:i+j])
        

s_str_list = sorted(str_list)

print(s_str_list[K-1])

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

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

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

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

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

Solution (Python):


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

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

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

print(l[k-1])

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

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

Solution (Python):
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[K-1])

Solution (Python):
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[k-1])

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

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

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

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

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

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

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

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

Solution (Python):
def get_subs(l, c, n):
    
    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))
    
    return res


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

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



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[K-1])

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

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

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

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

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

Solution (Python):
s = input()
K = int(input())
Kinds = set(s)
sort_s = sorted(list(Kinds))
cand = set([]) | set(sort_s)
for h in sort_s:
    first_i = [i for i, c in enumerate(s) if c == h]
    for i in first_i:
        for j in range(1, 5):
            if i+j+1 <= len(s):
                cand.add(s[i:i+j+1])

sort_res = sorted(list(cand))

print(sort_res[K-1])

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

n = len(s)
a = []
for i in range(n+1):
    for j in range(6):
        if len(s[i:i+j]) >=1:
            if not s[i:i+j] in a:
                a.append(s[i:i+j])
a.sort()
print(a[k-1])

Solution (Python):
s = raw_input()
k = int(raw_input())
l = len(s)
ls = []
for a in range(l):
    for b in range(a+1,min(a+k+1,l+1)):
        if ls.count(s[a:b]) == 0:
            ls.append(s[a:b])
ls.sort()
print ls[k-1]

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

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

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

Solution (Python):




s = input()
k = int(input())
var = 0
sub = set()
size = 0
for var in range(97,123):
    if len(sub)>k:
        break
    for i in range(len(s)):
        size=0
        if s[i]==chr(var):
            for j in range(i,len(s)):
                if size>=k:
                    break
                sub.add(s[i:(j+1)])
                size+=1 
l = list(sub)
l.sort()
print(l[k-1])

Solution (Python):

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

array = []
max_length = 6
if(len(s) < 5):
    max_length = len(s) + 1
for l in range(1, max_length):
    for i in range(len(s)):
        if i + l > len(s):
            continue
        array.append(s[i:i+l])
        
array = list(set(array))
array.sort()
print(array[k-1])

Solution (Python):
s = list(input())
k = int(input())
l = []
for i in range(1, k+1):
  for j in range(0, len(s)-i+1):
    l.append("".join(s[j:j+i]))

l = sorted(set(l))

print(l[k-1])

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