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: Time Limit Exceeded

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

substring = {}

char_tuple = sorted(tuple(s))

for c in char_tuple:
    if len(substring) >= 5:
        break
    for i in range(len(s)):
        if s[i] == c:
            for j in range(i + 1, len(s) + 1):
                substring[s[i:j]] = True



#
# for i in range(len(s)):
#     for j in range(i+1, len(s)+1):
#         # 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(words)
# print(sorted_words)

# print(substring)

print(sorted_words[k-1])

Submission status: Time Limit Exceeded

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


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

list_pair = list(set(list_pair))

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

Submission status: Time Limit Exceeded

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

l=[]
for i in range(5000):
    for n in range(5000-i):
        slice = s[n:n+i]
        if slice not in l:
            l.append(slice)
l.sort()
print(l[K])

Submission status: Time Limit Exceeded

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

substringList = []
if(len(s) < 10):
    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+6):
                #print(i,j)
                if(s[i:j+1] in substringList):
                    pass
                else:
                    substringList.append(s[i:j+1])
#substringList = list(set(substringList))
print(sorted(substringList)[K-1])

Submission status: Time Limit Exceeded

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

all_words = []
for i in range(len(s) + 1):
    s_min = [s[j: j + i + 1] for j in range(len(s)) if len(s[j: j + i + 1]) == i + 1]
    
    unique = []
    for j in range(len(s_min)):
        if s_min[j] not in unique:
            unique.append(s_min[j])
            
    for j in range(len(unique)):
        all_words.append(unique[j])
    
all_words.sort()
print(all_words[k - 1])

Submission status: Time Limit Exceeded

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

index = []

for i in range(len(s)):
    for j in range(i+1,i+6):
        jyuhuku = 0
        for a in index:
            if(a == s[i:j]):
                jyuhuku = 1
                break
            
        if(jyuhuku == 0):
            index.append(s[i:j])
    

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
l=len(s)
a=[]
for i in range(l):
    for j in range(i,l):
        jbreak = False
        sij = s[i:j+1]
        #print(sij)
        if not(sij in a):
            if a==[]:
                a.append(sij)
            elif len(a) < k:
                a.insert(0,sij)
                for m in range(len(a)-1):
                    if a[m]>a[m+1]:
                        a[m],a[m+1]=a[m+1],a[m]
                    else: break
            else:
                a.insert(0,sij)
                breakflag = False
                for m in range(k):
                    if a[m]>a[m+1]:
                        a[m],a[m+1]=a[m+1],a[m]
                    else: 
                        breakflag=True
                        break
                if not(breakflag):jbreak = True
print(a[k-1])

Submission status: Time Limit Exceeded

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 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: Time Limit Exceeded

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

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

l.sort()
rl = []
for i in range(len(l)-1):
    if l[i] == l[i+1] :
        rl.append(l[i])

for i in rl :
    l.remove(i)

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

Submission status: Time Limit Exceeded

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

l=[]
for i in range(5000):
    for n in range(5000):
        slice = s[n:n+i]
        if slice not in l:
            l.append(slice)
l.sort()
print(l[K])

Submission status: Time Limit Exceeded

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

index = []

for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        jyuhuku = 0
        for a in index:
            if(a == s[i:j]):
                jyuhuku = 1
        if(jyuhuku == 0):
            index.append(s[i:j])
    

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

Submission status: Time Limit Exceeded

Solution code:
def comp(a, b):

    if a.startswith(b):
        return -1
    else:
        for _a, _b in zip(a, b):
            if _a == _b:
                continue
            elif ord(_a) < ord(_b):
                return 1
            else:
                return -1
        return 0

def main():
    
    inp = input()
    k = int(input().strip())

    res_list = ["{"]

    for s in range(len(inp)):
        for e in range(s+1, len(inp)+1):
            tmp = inp[s:e]
            if tmp not in res_list:
                for i in range(min(len(res_list), 6)):
                    if comp(tmp, res_list[i]) == 1:
                        res_list[i:i] = [tmp]
                        break

    print(res_list[k-1])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
k=int(input())
def ss(s,k):
    M=len(s)
    l=[]
    for i in range(M):
        for j in range(i+1,M+1):
            tmp = s[i:j]
            if tmp not in l:
                l.append(tmp)
    l.sort()
    #print(l)
    ret = l[k-1]
    return(ret)

print(ss(s,k))

Submission status: Time Limit Exceeded

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
        for k in parts:
            if s[i:j] == k:
                flg = 1
        if flg == 0:
            parts.append(s[i:j])
        
v = sorted(parts)
print(v[K-1])

Submission status: Time Limit Exceeded

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

#print str, K,  len(str)

dic = []

i = 1

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

    i = i + 1


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


print dic_set[K-1]

Submission status: Time Limit Exceeded

Solution code:
s=input()
sub=set()
for i in range(len(s)):
    for j in range(i,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: Time Limit Exceeded

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

f1 = ""
f2 = ""
f3 = ""
f4 = ""
f5 = ""
for a1 in range(0, len(s)):
	for a2 in range(a1 + 1, len(s) + 1):
		w = s[a1:a2]
		if w != f1 and w != f2 and w != f3 and w != f4 and w != f5:
			if f5 == "" or w < f5:
				f5 = w
				if f4 == "" or f5 < f4:
					t = f4
					f4 = f5
					f5 = t
					if f3 == "" or f4 < f3:
						t = f3
						f3 = f4
						f4 = t
						if f2 == "" or f3 < f2:
							t = f2
							f2 = f3
							f3 = t
							if f1 == "" or f2 < f1:
								t = f1
								f1 = f2
								f2 = t

if K == 1:
	print(f1)
if K == 2:
	print(f2)
if K == 3:
	print(f3)
if K == 4:
	print(f4)
if K == 5:
	print(f5)

Submission status: Time Limit Exceeded

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,len(s)+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: Time Limit Exceeded

Solution code:
s = input()
k=int(input())
def ss(s,k):
    M=len(s)
    l=[]
    for i in range(M):
        for j in range(i+1,M+1):
            tmp = s[i:j]
            l.append(tmp)
    l.sort()
    l=f7(l)
    #print(l)
    ret = l[k-1]
    return(ret)

def f7(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x)]

print(ss(s,k))

Submission status: Time Limit Exceeded

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
        for k in parts:
            if s[i:j] == k:
                flg = 1
        if flg == 0:
            parts.append(s[i:j])
        
v = sorted(parts)
print(v[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
ans=[]
for i in range(1,len(s)+1):
    ans=ans+[s[x:x+i] for x in range(len(s)-i+1)]
    ans=list(set(ans))
print(sorted(ans)[k-1])

Submission status: Time Limit Exceeded

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

substring = {}

for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        # 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(words)
# print(sorted_words)

# print(substring)

print(sorted_words[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
a=[]
for i in range(0,len(s)):
    for j in range(1,len(s)+1):
        a.append(s[i:j])
num = a.count("")
for i in range(num):
    a.remove("")
a=sorted(a)
b=[]
for i in a:
    if i not in b:
        b.append(i)
print(b[k-1])

Submission status: Time Limit Exceeded

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:
            ss.append(s[index:])
            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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

f1 = ""
f2 = ""
f3 = ""
f4 = ""
f5 = ""
for a1 in range(0, len(s)):
	for a2 in range(a1 + 1, len(s) + 1):
		w = s[a1:a2]
		if w != f1 and w != f2 and w != f3 and w != f4 and w != f5:
			if f5 == "" or w < f5:
				f5 = w
			if f4 == "" or f5 < f4:
				t = f4
				f4 = f5
				f5 = t
			if f3 == "" or f4 < f3:
				t = f3
				f3 = f4
				f4 = t
			if f2 == "" or f3 < f2:
				t = f2
				f2 = f3
				f3 = t
			if f1 == "" or f2 < f1:
				t = f1
				f1 = f2
				f2 = t

if K == 1:
	print(f1)
if K == 2:
	print(f2)
if K == 3:
	print(f3)
if K == 4:
	print(f4)
if K == 5:
	print(f5)

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
number = len(s)
word_list = []
for i in range(number):
  for j in range(1,number+1):
    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: Time Limit Exceeded

Solution code:
def main9():
    str = input('');
    numstr = input('');
    num = int(numstr);
    length = len(str);
    list = [];
    for i in range(length):
        for j in range(length-i):
            if not(str[j:j+(i+1)] in list):
                list.append(str[j:j+(i+1)]);
    list.sort();
    print(list[num-1]);

if __name__ == '__main__':
    main9()

Submission status: Time Limit Exceeded

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

s_slice = []
for start in range(len(s)):
    for last in range(start+1,len(s)+1):
        slice = s[start:last]
        if slice != '':
            s_slice.append(slice)
s_slice = list(set(s_slice))
s_slice = sorted(s_slice)
print(s_slice[k-1])

Submission status: Time Limit Exceeded

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

len_s = len(s)
str_list = []
for i in range(len_s):
    for j in range(1, len_s-i+1):
#        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: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
ans=[]
for i in range(1,len(s)+1):
    ans=ans+list(set([s[x:x+i] for x in range(len(s)-i+1)]))
print(sorted(ans)[k-1])

Submission status: Time Limit Exceeded

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

for i in range(len(s)):
    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])
# print(ans_list)


'''
ans_list = []
s_list = [s[i] for i in range(len(s))]
s_set_sorted = sorted(set(s_list))
for i in range(len(s_set_sorted)):
    ans_list.append(s_set_sorted[i])
if k <= len(ans_list):
    ans_list.sort()
    print(ans_list[k-1])
    exit()

s_queue = []
for i in range(len(s)-1):
    s_queue.append(s[i:i+2])
s_queue_set_sorted = sorted(set(s_queue))
for i in range(len(s_queue_set_sorted)):
    ans_list.append(s_queue_set_sorted[i])
if k <= len(ans_list):
    ans_list.sort()
    print(ans_list[k-1])
    exit()

print(s_set_sorted)
'''

Submission status: Time Limit Exceeded

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

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

alphabets = 'abcdefghijklmnopqrstuvwxyz'

n = 0
dic = []

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

        if index != -1:
            ss.append(s[index:])
            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

print(dic[k-1])

Submission status: Time Limit Exceeded

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

Len = len(strs)

allstr = [] 

for i in range(Len):
    for j in range(i+1):
        allstr.append(strs[i-j:i+1])

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

print(allstr2[N-1])

Submission status: Time Limit Exceeded

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

s_list = []
for i in range(0, len(s)):
    for j in range(1, len(s)-i+1):
        if len(s_list) < k:
            s_list.append(s[i:i+j])
            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]

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

print(dict_list[k-1])

Submission status: Time Limit Exceeded

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 end in range(start + 1, len(s) + 1):
            candidates |= {s[start:end]}

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

    #
    # length_to_candidates = defaultdict(list)
    # for length in range(1, len(s) + 1):
    #     for start in range(0, len(s) + 1 - length):
    #         sub = s[start:start + length]
    #         if sub not in length_to_candidates[length]:
    #             length_to_candidates[length].append(sub)
    #         # length_to_candidates |= {s[start:start + length]}
    #
    # all_candidates = []
    # for v in length_to_candidates.values():
    #     all_candidates += list(v)
    #
    # print(all_candidates)
    # print(all_candidates[K - 1])

    # print(length_to_candidates)

Submission status: Time Limit Exceeded

Solution code:
s = input()
X = int(input()) - 1

substrings = {s}

for l in range(1, len(s)):
    for i in range(0, len(s)):
        substrings.add(s[i:i+l])

print(sorted(list(substrings))[X])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

result = []
lst = []
for si in s:
    temp = []
    for li in lst:
        temp.append(li + si)
    temp.append(si)
    result.extend(temp)
    lst = temp

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

Submission status: Time Limit Exceeded

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

x=[]
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        x.append(s[i:j] )
y=list(set(x))
z=sorted(y)

print(z[k-1])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
s = input()
k = int(input())
sb_str = []
for i in range(len(s)+1):
    for j in range(1,len(s)+1):
        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: Time Limit Exceeded

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]
		#print(i,j,a)
		l.append(a)


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

print(l[k-1])

Submission status: Time Limit Exceeded

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

s_slice = []
for start in range(len(s)):
    for last in range(1,len(s)+1):
        slice = s[start:last]
        s_slice.append(slice)
        #print(start,last,slice)
s_slice = [i for i in s_slice if i != '']
s_slice = list(set(s_slice))
s_slice = sorted(s_slice)
print(s_slice[k-1])

Submission status: Time Limit Exceeded

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

substring_list = []
for substring_char_num in range(1, len(s) + 1):
    for substring_head_place in range(len(s) - substring_char_num + 1):
        substring = s[substring_head_place: substring_head_place + substring_char_num]
        if substring not in substring_list:
            substring_list.append(substring)

sorted_substring_list = sorted(substring_list)
print(sorted_substring_list[K - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
k = int(input())
sub = []
sub += s[:]

for j in range(2,len(s)+1):
    charGram = [''.join(s[i:i+j]) for i in range(len(s)-1)]
    sub += charGram
sub = list(set(sub))
print(sorted(sub)[k-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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))+1) in s:
                    ans.append(chr(ord(min(s))+1))
                    break
                elif i >= 100:
                    print('error')
                    break
                else:
                    i += 1

        else:
            ans.append(sub[0])

Submission status: Time Limit Exceeded

Solution code:
# coding : utf-8

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

strset = set(s)
s_len = len(s)

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

strsetsort = sorted(strset, reverse=False)
ans = strsetsort[K-1]
print(ans)

Submission status: Time Limit Exceeded

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

strs = set()

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

        strs.add(s[i:j])

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

Submission status: Time Limit Exceeded

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

lst = set()
s_len = len(s)
for length in range(1, s_len + 1):
    for i in range(s_len):
        myS = s[i:(i + length)]
        if myS != '':
            lst.add(myS)
lst_sorted = sorted(list(lst))
##print(lst_sorted)
print(lst_sorted[k - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
S = []
for i in range(1, len(s) + 1):
    k = 0
    while True:
        count = 0
        if len(s) - k - i < 0:
            break
        a = []
        for j in range(0, i):
            a.append(s[j + k])
        k += 1
        for j in S:
            if j == a:
                count += 1
                break
        if count == 0: S.append(a)

#keylist = []
#for i in range(len(S)):
  #  for j in range(len(S)):
 #       if S[i] == S[j] and i != j and i > j:
#            keylist.append(i)

#for i in keylist:
#    del S[i]
S.sort()
print(''.join(S[K - 1]))

Submission status: Time Limit Exceeded

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))+1) in s:
                    ans.append(chr(ord(min(s))+1))
                    break
                else:
                    i += 1
        else:
            ans.append(sub[0])

Submission status: Time Limit Exceeded

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

_all = []

for i in range(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: Time Limit Exceeded

Solution code:


ss = []
s = input()
k = int(input())
for window_size in range(len(s)):
    window_size += 1
    for step in range(len(s)-window_size+1):
        ss.append(s[step:step+window_size])

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

Submission status: Time Limit Exceeded

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

zisyo = []
for i in range(len(s)):
    count = 0
    st = s[i]
    zisyo.append(st)
    while count <= len(s):
        count = count + 1
        try:
            st = st + s[i + count]
            zisyo.append(st)
        except:
            pass
    
zisyosort = list(sorted(list(set(zisyo))))
print(zisyosort[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 i + q <= len(s):
            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: Time Limit Exceeded

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

substr_map = {}

for i in range(len(s) + 1):
    for j in range(i + 1, len(s) + 1):
        substr_map[s[i:j]] = 1

print(list(sorted(substr_map.items(), key = lambda x: x[0]))[K - 1][0])

Submission status: Time Limit Exceeded

Solution code:
import re

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

subs = set()

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

subs = list(subs)


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

Submission status: Time Limit Exceeded

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

size = len(s)
l = []
for i in range(size):
    for j in range(i+1,size+1):
        if not s[i:j] in l:
            l.append(s[i:j])
l.sort()
print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
def alf(a):
    A = "abcdefghijklmnopqrstuvwxyz"
    return A.index(a)

def main():
    s = input()
    K = int(input())
    List = []
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            if (s[i:j] in List) == False:
                List.append(s[i:j])
    List.sort()
    return List[K-1]

if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

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

substring = []
for length in range(1,len(s)+1):
    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: Time Limit Exceeded

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

_all = []

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


_set = set(_all)
print(sorted(_set)[k-1])

Submission status: Time Limit Exceeded

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

    ans = set()
    for i in range(len(s)):
        # print(s[i:])
        for j in range(len(s) - i + 1):
            # print(s[i:i + j + 1])
            ans.add(s[i:i + j + 1])
    lans = sorted(list(ans))
    # for s in lans: print(s)
    print(lans[K - 1])

Submission status: Time Limit Exceeded

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

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

sub = []
for i in range(1,int(len(s))+1):
    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: Time Limit Exceeded

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

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

print b[K-1]

Submission status: Time Limit Exceeded

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

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

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

print(dict_list[k-1])

Submission status: Time Limit Exceeded

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

sublist = []

for start in range(len(s)):
    for end in range(start+1, len(s) + 1):
        sublist.append(s[start:end])
list_uq = list(set(sublist))
list_sorted = sorted(list_uq)
print(list_sorted[k-1])

Submission status: Time Limit Exceeded

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

alphabet = "abcdefghijklmnopqrstuvwxyz"
candidates = []

for i in range(len(alphabet)):
  key = alphabet[i]
  count = s.count(key)
  if count > 0:
    index = 0
    for j in range(count):
      index = s.find(key, index)
      for i in range(index, len(s) + 1):
        if not s[index:i] in candidates and len(s[index:i]) > 0:
          candidates += [s[index:i]]
      index += 1
  if len(candidates) >= k:
    break

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

Submission status: Time Limit Exceeded

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

dic = []

for i in range(len(s)):
  for j in range(len(s) - i):
    dic.append(s[i:i+1+j])

dic_sort = sorted(list(set(dic)))
print(dic_sort[k-1])

Submission status: Time Limit Exceeded

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

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

substring = []
for begin in range(len(s)):
    for end in range(begin + 1, len(s) + 2):
        string = s[begin:end]
        if string not in substring:
            substring.append(string)
print(sorted(substring)[K-1])