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: Runtime Error

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    indexes = [p for p, x in enumerate(s) if x == i]            
    count = 0
    onedict = []
    
    for ii in range(len(indexes)):
        onedict.append(i)
        
    while count <= len(s)  + 1 and len(onedict) <= k + 1:
        count = count + 1
        
        if True:
            quint = indexes
            for sss in range(len(onedict)):
                try:
                    pppp = onedict[sss]
                    pppp = pppp + s[ int(quint[sss])+ count]
                    onedict.append(pppp)
                except:
                    pass
            for jj in onedict:
                zis.append(jj)

                
    if len(zis) > k + 1:
        break
zissort = list(sorted(list(set(zis))))

print(zissort[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    indexes = [p for p, x in enumerate(s) if x == i]            
    count = 0
    onedict = []
    
    for ii in range(len(indexes)):
        onedict.append(i)
        
    while count <= len(s)  + 1 and len(onedict) <= k + 1:
        count = count + 1
        
        if True:
            quint = indexes
            for sss in range(len(onedict)):
                try:
                    pppp = onedict[sss]
                    pppp = pppp + s[ int(quint[sss])+ count]
                    onedict.append(pppp)
                except:
                    pass
            for jj in onedict:
                zis.append(jj)

                
    if len(zis) > k + 1:
        break
zissort = list(sorted(list(set(zis))))
print(zissort)
print(zissort[k-1])

Submission status: Runtime Error

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

alphabet = [chr(i) for i in range(97, 97+26)]
dictionary = list()
for char in alphabet:
    tmp_s = s
    num = tmp_s.find(char)
    while num != -1:

        for i in range(len(tmp_s)-num):
            dictionary.append(tmp_s[num:num+i+1])

        else:
            if num != len(tmp_s)-1:
                tmp_s = tmp_s[num+1:]
            else:
                break

        num = tmp_s.find(char)

    if len(dictionary) > 5:
        break

seen = set()
seen_add = seen.add

dictionary = [ x for x in dictionary if x not in seen and not seen_add(x)]
dictionary.sort()
# print(dictionary)
print(dictionary[k-1])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

alphabet = [chr(i) for i in range(97, 97+26)]
dictionary = list()
for char in alphabet:
    tmp_s = s
    num = tmp_s.find(char)
    while num != -1:

        for i in range(len(tmp_s)-num):
            dictionary.append(tmp_s[num:num+i+1])

        else:
            if num != len(tmp_s):
                tmp_s = tmp_s[num+1:]
            

        num = tmp_s.find(char)

    if len(dictionary) > 5:
        break

seen = set()
seen_add = seen.add

dictionary = [ x for x in dictionary if x not in seen and not seen_add(x)]
dictionary.sort()
# print(dictionary)
print(dictionary[k-1])

Submission status: Runtime Error

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

alphabet = [chr(i) for i in range(97, 97+26)]
dictionary = list()
for char in alphabet:
    tmp_s = s
    num = tmp_s.find(char)
    while num != -1:
        if num == len(tmp_s):
            break
        for i in range(len(tmp_s)-num):
            dictionary.append(tmp_s[num:num+i+1])

        else:
            tmp_s = tmp_s[num+1:]

        num = tmp_s.find(char)

    if len(dictionary) > 5:
        break

seen = set()
seen_add = seen.add

dictionary = [ x for x in dictionary if x not in seen and not seen_add(x)]
dictionary.sort()
# print(dictionary)
print(dictionary[k-1])

Submission status: Runtime Error

Solution code:
str = input()

lt = []
l = len(str)
for s in range(l):
  for t in range(s,l):
    lt.append(str[s:t])
ls = list(set(lt))

print(ls[4])

Submission status: Runtime Error

Solution code:
string = input()
n = int(input())

if len(string) == 1:
    print(string)
else:
    chr = []
    for i in range(len(string)):
        if string[i] not in chr:
            chr.append(string[i])
    if n <= len(chr):
        chr.sort(reverse=True)
        print(chr[n-1])
    else:
        n = n - len(chr)
        for i in range(len(string)-1):
            if string[i]+string[i+1] not in chr:
                chr.append(string[i]+string[i+1])
        chr.sort(reverse=True)
        print(chr[n-1])

Submission status: Runtime Error

Solution code:
# coding : utf-8

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

strlist = sorted(range(len(s)), key=lambda k :list(s)[k], reverse=False)
s_len = len(s)
strset = set(s[strlist[0]])

calcEnd = False
for i in range(len(s)):
    #for j in range(i+1, len(s)+1):
    for j in range(strlist[i+1], len(s)+1):
        #strset.add(s[i:j])
        strset.add(s[strlist[i]:j])

    if s[strlist[i+1]] != s[strlist[i]]:
        if len(strset) >= K:
            calcEnd = True
            break

    if calcEnd:
        break


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

Submission status: Runtime Error

Solution code:
string = str(input())
n=int(input())
substringlist = [string]
for i in range(len(string)-1):
    for j in range(i+1,len(string)+1):
        substringlist.append(string[i:j])

substringli=list(set(substringlist))

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

Submission status: Runtime Error

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

sln = len(s)
subs = set()

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

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
strl = len(s)
s_list = []
i = 0
while chr(65+i) not in s:
    i += 1
s_list = [s[k:k+K] for k in range(strl) if s[k] == chr(65+i)]
s_list = list(set(s_list))
s_l = []
for c in s_list:
    for i in range(K):
        if i >= len(c):
            break
        s_l.append(c[:i+1])
s_l = list(set(s_l))
s_l.sort()
print(s_l[K-1])

Submission status: Runtime Error

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

print(x[a-1])

Submission status: Runtime Error

Solution code:
s=str(input())
n=int(input())
if(len(s)<=5000):	
	flag=0
	z="abcdefghijklmnopqrstuvwxyz"
	k=0
	while(flag==0):
		arr=[]
		arr1=[]
		for i in range(len(s)):
			if(s[i]==z[k]):
				arr.append(i)
		arr1.append(s[arr[0]])
		for i in range(len(arr)):
			for j in range(arr[i]+1,len(s)):
				#print(s[arr[i]:j+1])
				if(s[arr[i]:j+1] not in arr1):
					arr1.append(s[arr[i]:j+1])
		#print(*arr1)
		if(len(arr1)>=n):
			arr1.sort()
			flag=1
			print(arr1[n-1])
		else:
			n-=len(arr1)
		k+=1

Submission status: Runtime Error

Solution code:
str = input()

lt = []
l = len(str)
for s in range(l):
  for t in range(s:l):
    lt.append(slice[t:s])
ls = list(set(lt))

print(ls[3])

Submission status: Runtime Error

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

alphabet = [chr(i) for i in range(97, 97+26)]
dictionary = list()
for char in alphabet:
    tmp_s = s
    num = tmp_s.find(char)
    while num != -1:
        for i in range(len(tmp_s)-num):
            dictionary.append(tmp_s[num:num+i+1])

        else:
            tmp_s = tmp_s[num+1:]

        num = tmp_s.find(char)

    if len(dictionary) > 5:
        break

seen = set()
seen_add = seen.add

dictionary = [ x for x in dictionary if x not in seen and not seen_add(x)]
dictionary.sort()
# print(dictionary)
print(dictionary[k-1])

Submission status: Runtime Error

Solution code:
str=input()
x=int(input())
print(str)
i=0
j=0
b=[]
for i in range(len(str)):
    while i<len(str) and i<j:
        b=str[i:j]
        j=j+1



a=sorted(b)
print(b[x])

Submission status: Runtime Error

Solution code:
str=input()
x=int(input())
print(str)
i=0
j=0
b=[]
for i in range(len(str)):
    while i<len(str) and i<j:
        b=str[i:j]
        j+=1



a=sorted(b)
print(b[x])

Submission status: Runtime Error

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):
                #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: Runtime Error

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+3):
                #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: Runtime Error

Solution code:
s=input()
k=int(input())
ans=[]
n=len(s)
for i in range(n):
    for j in range(n):
        ans.append(s[i:j+1])
ans=list(set(ans))
ans.sort()
if "" in ans:
    ans.pop(0)
if n==1:
    print(s)
else:
    print(ans[k])

Submission status: Runtime Error

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

index = []

for i in range(len(s)):
    for j in range(i+1,i+k):
        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: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
LIST = []
for i in range(len(s)-1):
    j=i+1
    while j<=len(s):
        if len(LIST)>=K:
            if LIST[K-1] > s[i:j]:
                if s[i:j] not in LIST:
                    LIST[K-1] = s[i:j]
                    LIST.sort()
        else:
            if s[i:j] not in LIST:
                LIST.append(s[i:j])
                LIST.sort()
        j+=1

print(LIST[K-1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
strl = len(s)
s_list = []
i = 0
ind = -1
while chr(65+i) not in s:
    i += 1
s_list = [s[k:k+K] for k in range(strl) if s[k] == chr(65+i)]
s_list = list(set(s_list))
s_l = []
for c in s_list:
    for i in range(K):
        if i >= len(c):
            break
        s_l.append(c[:i+1])
s_l = list(set(s_l))
s_l.sort()
print(s_l[K-1])

Submission status: Runtime Error

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    ones = i
    indexes = [p for p, x in enumerate(s) if x == i]
            
    for kk in indexes:
        st = s[kk]
        count = 0
        while count <= len(s) - kk + 1:
            count = count + 1
            try:
                st = st + s[kk + count]
                zis.append(st)
            except:
                pass
                
    if len(zis) > k:
        break
zissort = list(sorted(list(set(zis))))
print(zissort[k])

Submission status: Runtime Error

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

substringList = []
if(len(s) < 5):
    for i in range(len(s)):
        if(i+5 > 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)):
        if(i+5 > len(s)):
            for j in range(i, i+5):
                #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: Runtime Error

Solution code:
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, 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: Runtime Error

Solution code:

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


# alphabet順に探査する
# 探査順序配列
search_seq = sorted(list(set(s)))

count = 0
previous = 0

for key in search_seq:
    previous = count
    indexes = [i for i, x in enumerate(s) if x == key]
    sublist = []
    for index in indexes:
        for end in range(index+1, len(s) + 1):
            sublist.append(s[index:end])
    count += len(s)
    if k-1 < count:
        list_uq = list(set(sublist))
        list_sorted = sorted(list_uq)
        print(list_sorted[k-previous-1])
        exit()

Submission status: Runtime Error

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

str_list = list(s)
str_list2 = list(s)
str_list2 = list(set(str_list2))
str_list2.sort()
a = str_list2[0]
n = str_list.count(a)

if K==1:
    print(a)
else:
    K -= 1
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
    if len(indexes) >0:
        sub_list = [s[i:i+2] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
    if len(indexes) >0:
        sub_list += [s[i:i+3] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
    if len(indexes) >0:
        sub_list += [s[i:i+4] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
    if len(indexes) >0:
        sub_list += [s[i:i+5] for i in indexes]
    sub_list = list(set(sub_list))
    sub_list.sort()
    if len(sub_list) >= K:
        print(sub_list[K-1])
    else:
        K -= len(sub_list)
        a = str_list[1]
        if K==1:
            print(a)
        else:
            K -= 1
            sub_list = []
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
            if len(indexes) >0:
                sub_list = [s[i:i+2] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
            if len(indexes) >0:
                sub_list += [s[i:i+3] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
            if len(indexes) >0:
                sub_list += [s[i:i+4] for i in indexes]
            sub_list = list(set(sub_list))
            sub_list.sort()
            if len(sub_list) >= K:
                print(sub_list[K-1])
            else:
                K -= len(sub_list)
                a = str_list[2]
                if K==1:
                    print(a)
                else:
                    K -=1
                    sub_list = []
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
                    if len(indexes) >0:
                        sub_list = [s[i:i+2] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
                    if len(indexes) >0:
                        sub_list += [s[i:i+3] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
                    if len(indexes) >0:
                        sub_list += [s[i:i+4] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
                    sub_list = list(set(sub_list))
                    sub_list.sort()
                    print(sub_list[K-1])

Submission status: Runtime Error

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)
print(ans[int(n)-1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
LIST = []
for i in range(len(s)-1):
    j=i+1
    while j<=len(s):
        if s[i:j] not in LIST:
            if len(LIST)>=K:
                if LIST[K-1] > s[i:j]:
                    LIST[K-1] = s[i:j]
                    LIST.sort()
            else:
                LIST.append(s[i:j])
                LIST.sort()
        j+=1

print(LIST[K-1])

Submission status: Runtime Error

Solution code:
def f(myC, chrs, s, lst):
    for c in chrs:
        if(myC + c) in s:
            lst += [myC + c]
            f(myC + c, chrs, s, lst)
            
if __name__ == '__main__':
    s = input()
    k = int(input())

    chrs = sorted(list(set(s)))
    lst = []
    f('', chrs, s, lst)
    ##print(lst)
    print(lst[k - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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


# alphabet順に探査する
# 探査順序配列
search_seq = sorted(list(set(s)))

count = 0
previous = 0

for key in search_seq:
    previous = count
    indexes = [i for i, x in enumerate(s) if x == key]
    sublist = []
    for index in indexes:
        for end in range(index+1, len(s) + 1):
            sublist.append(s[index:end])
    count += len(s)
    if k < count:
        list_uq = list(set(sublist))
        list_sorted = sorted(list_uq)
        print(list_sorted[k-previous-1])
        exit()

Submission status: Runtime Error

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 s in index:
            if(s == s[i:j]):
                jyuhuku = 1
        if(jyuhuku == 0):
            index.append(s[i:j])
    

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
 
str_list = list(s)
str_list2 = list(s)
str_list2 = list(set(str_list2))
str_list2.sort()
a = str_list2[0]
n = str_list.count(a)
 
if K==1:
    print(a)
else:
    K -= 1
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
    if len(indexes) >0:
        sub_list = [s[i:i+2] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
    if len(indexes) >0:
        sub_list += [s[i:i+3] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
    if len(indexes) >0:
        sub_list += [s[i:i+4] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
    if len(indexes) >0:
        sub_list += [s[i:i+5] for i in indexes]
    sub_list = list(set(sub_list))
    sub_list.sort()
    if len(sub_list) >= K:
        print(sub_list[K-1])
    else:
        K -= len(sub_list)
        a = str_list[1]
        if K==1:
            print(a)
        else:
            K -= 1
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
            if len(indexes) >0:
                sub_list = [s[i:i+2] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
            if len(indexes) >0:
                sub_list += [s[i:i+3] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
            if len(indexes) >0:
                sub_list += [s[i:i+4] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
            sub_list = list(set(sub_list))
            sub_list.sort()
            if len(sub_list) >= K:
                print(sub_list[K-1])
            else:
                K -= len(sub_list)
                a = str_list[2]
                if K==1:
                    print(a)
                else:
                    K -=1
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
                    if len(indexes) >0:
                        sub_list = [s[i:i+2] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
                    if len(indexes) >0:
                        sub_list += [s[i:i+3] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
                    if len(indexes) >0:
                        sub_list += [s[i:i+4] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
                    sub_list = list(set(sub_list))
                    sub_list.sort()
                    print(sub_list[K-1])

Submission status: Runtime Error

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

str_list = list(s)
str_list2 = list(s)
str_list2 = list(set(str_list2))
str_list2.sort()
print(str_list)
a = str_list2[0]
n = str_list.count(a)

if K==1:
    print(a)
else:
    K -= 1
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
    if len(indexes) >0:
        sub_list = [s[i:i+2] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
    if len(indexes) >0:
        sub_list += [s[i:i+3] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
    if len(indexes) >0:
        sub_list += [s[i:i+4] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
    if len(indexes) >0:
        sub_list += [s[i:i+5] for i in indexes]
    sub_list = list(set(sub_list))
    sub_list.sort()
    if len(sub_list) >= K:
        print(sub_list[K-1])
    else:
        K -= len(sub_list)
        a = str_list[1]
        if K==1:
            print(a)
        else:
            K -= 1
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
            if len(indexes) >0:
                sub_list = [s[i:i+2] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
            if len(indexes) >0:
                sub_list += [s[i:i+3] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
            if len(indexes) >0:
                sub_list += [s[i:i+4] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
            sub_list = list(set(sub_list))
            sub_list.sort()
            if len(sub_list) >= K:
                print(sub_list[K-1])
            else:
                K -= len(sub_list)
                a = str_list[2]
                if K==1:
                    print(a)
                else:
                    K -=1
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
                    if len(indexes) >0:
                        sub_list = [s[i:i+2] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
                    if len(indexes) >0:
                        sub_list += [s[i:i+3] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
                    if len(indexes) >0:
                        sub_list += [s[i:i+4] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
                    sub_list = list(set(sub_list))
                    sub_list.sort()
                    print(sub_list[K-1])

Submission status: Runtime Error

Solution code:
from sys import stdin
from string import ascii_lowercase

stdin = open('sample.txt')


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: Runtime Error

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])
a=sorted(a)
b=[]
for i in a:
    if i not in b:
        b.append(i)
b.remove("")
print(b[k-1])

Submission status: Runtime Error

Solution code:
str=list(input())
x=int(input())
print(str)
i=0
j=0
for i in range(len(str)):
    for j in range(len(str)):
        for k in range(i,j):
            a=list(str[k])
b=sorted(a)
print(b[x+1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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.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: Runtime Error

Solution code:
s=input()
K=int(input())
S=set()
l=len(s)
for i in range(l):
    k=0
    while i+k<l:
        if len(S)>K:
            break
        S.add(s[k:k+i])
        k+=1
ans=sorted(S)
print(ans[K-1])

Submission status: Runtime Error

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()
    #print(l)
    ret = l[k-1]
    return(ret)

print(ss(s,k))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
def powerset(s):
    length = len(s)
    return [s[i: j] for i in range(len(s)) for j in range(len(s))] + [s]


def is_a_repetition_of_one_character(s):
    if len(s) <= 1:
        return False
    else:
        if s == len(s) * s[0]:
            return True
        else:
            return False

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

iterator = powerset(s)
substrings = [''.join(i) for i in iterator if not is_a_repetition_of_one_character(''.join(i))]
substrings = list(set(substrings))
substrings.sort()
substrings.remove('')
print(substrings[K-1])

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
LIST = []
for i in range(len(s)-1):
    j=i+1
    while j<=len(s):
        if s[i:j] not in LIST:
            LIST.append(s[i:j])
            LIST.sort()
            LIST[0:K]
        j+=1

print(LIST[K-1])

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

def main():
  d=[]
  h='z'
  for i in range(len(s)):
    if len(s)>1000:
      if s[i]>h:
        continue
      else:
        h=s[i]
    for j in range(i,len(s)+1):
      d.append(s[i:j])

  d=list(set(d))
  d.sort()

  print d[K]

main()

Submission status: Runtime Error

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)
    onelist = list(sorted(list(set(zisyo))))
    
    if onelist.index(st) > 6:
        continue
    while count <= n:
        count = count + 1
        try:
            st = st + s[i + count]
            zisyo.append(st)
        except:
            pass
    
zisyosort = list(sorted(list(set(zisyo))))
print(zisyosort)