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())
alphabet='abcdefghijklmnopqrstuvwxyz'


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]
            #print(l)
            if tmp[0] == 'a':
                if tmp not in l[0]:
                    l[0].append(tmp)
            elif tmp[0] == 'b':
                if tmp not in l[1]:
                    l[1].append(tmp)
            elif tmp[0] == 'c':
                if tmp not in l[2]:
                    l[2].append(tmp)
            elif tmp[0] == 'd':
                if tmp not in l[3]:
                    l[3].append(tmp)
            elif tmp[0] == 'e':
                if tmp not in l[4]:
                    l[4].append(tmp)
            elif tmp[0] == 'f':
                if tmp not in l[5]:
                    l[5].append(tmp)
            elif tmp[0] == 'g':
                if tmp not in l[6]:
                    l[6].append(tmp)
            elif tmp[0] == 'h':
                if tmp not in l[7]:
                    l[7].append(tmp)
            elif tmp[0] == 'i':
                if tmp not in l[8]:
                    l[8].append(tmp)
            elif tmp[0] == 'j':
                if tmp not in l[9]:
                    l[9].append(tmp)
            elif tmp[0] == 'k':
                if tmp not in l[10]:
                    l[10].append(tmp)
            elif tmp[0] == 'l':
                if tmp not in l[11]:
                    l[11].append(tmp)
            elif tmp[0] == 'm':
                if tmp not in l[12]:
                    l[12].append(tmp)
            elif tmp[0] == 'n':
                if tmp not in l[13]:
                    l[13].append(tmp)
            elif tmp[0] == 'o':
                if tmp not in l[14]:
                    l[14].append(tmp)
            elif tmp[0] == 'p':
                if tmp not in l[15]:
                    l[15].append(tmp)
            elif tmp[0] == 'q':
                if tmp not in l[16]:
                    l[16].append(tmp)
            elif tmp[0] == 'r':
                if tmp not in l[17]:
                    l[17].append(tmp)
            elif tmp[0] == 's':
                if tmp not in l[18]:
                    l[18].append(tmp)
            elif tmp[0] == 't':
                if tmp not in l[19]:
                    l[19].append(tmp)
            elif tmp[0] == 'u':
                if tmp not in l[20]:
                    l[20].append(tmp)
            elif tmp[0] == 'v':
                if tmp not in l[21]:
                    l[21].append(tmp)
            elif tmp[0] == 'w':
                if tmp not in l[22]:
                    l[22].append(tmp)
            elif tmp[0] == 'x':
                if tmp not in l[23]:
                    l[23].append(tmp)
            elif tmp[0] == 'y':
                if tmp not in l[24]:
                    l[24].append(tmp)
            elif tmp[0] == 'z':
                if tmp not in l[25]:
                    l[25].append(tmp)
    lis=[]
    for li in l:
        li.sort()
        lis.extend(li)
    l=lis
    #print(l)
    ret = l[k-1]
    return(ret)

print(ss(s,k))

Submission status: Time Limit Exceeded

Solution code:
def isPrefix(str1, str2):
    if str2[:len(str1)] == str1:
        return True
    else:
        return False

def isEarlier(str1, str2):
    for s1, s2 in zip(list(str1), list(str2)):
        if s1 != s2:
            if ord(s1) < ord(s2):
                return True
            else:
                return False

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

    #2. get earliest one
    s_list = set(s)
    earliest = "z"
    for char in s_list:
        if ord(char) < ord(earliest):
            earliest = char
            
    #3. if K=1, end
    #    else, the get K-th one
    if K==1:
        print(earliest)
    else:
        k=1
        subset.remove(earliest)
        while True:
            subset_list = list(subset)
            earliest=subset_list[0]
            for element in subset_list[1:]:
                if (not isPrefix(earliest, element)) and (not isEarlier(earliest, element)):
                    earliest = element
            subset.remove(earliest)
            k += 1
                
            if k==K:
                print(earliest)
                break

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# 部分点は取れるけど満点は微妙そう(O(n^3?))
from sys import stderr
from functools import reduce
from operator import add
f = lambda :[int(i) for i in input().split()]
debug = lambda *x:stderr.write(reduce(add,repr(x))+'\n')

s = input()
k = int(input())
subs = set()

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

ans = list(subs)
ans.sort()
debug(ans)

print(ans[k-1])

Submission status: Time Limit Exceeded

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

memo = set()

result = []
lst = []
for si in s:
    temp = []
    for li in lst:
        ss = li + si
        if ss not in memo:
            temp.append(li + si)
            memo.add(ss)
    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())
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
        if j-i>k: break
print(a[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])
B = A
if K == 1:
  ans = min(B)
if K == 2:
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  ans = (min(B))
if K == 3:
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  ans = (min(B))
if K == 4:
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  ans = (min(B))
if K == 5:
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  F = B.count(min(B))
  for i in range(F):
    B.remove(min(B))
  ans = (min(B))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
sSet = set()
for i in range(len(s)):
    for j in range(len(s)):
        sSet.add(s[i : j+1])
list = list(sSet)
list.sort()
try:
    list.remove("")
except:
    pass
print(list[K - 1])

Submission status: Time Limit Exceeded

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 = {}
for c in range(97, 123):
    for i in pos[c]:
        for j in range(i, n):
            f[s[i:j+1]] = 1
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + '1'
    while len(u) > len(v): v = v + '1'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Time Limit Exceeded

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

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

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

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

            start += 1
            ended += 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

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

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

for j in range(len(s)):
    ans.append(s[j])
    if j < len(s)-1:
        t = j+2
        while True:
            ans.append(s[j:t])
            if t == len(s):
                break
            t += 1
l = list(set(ans))
l.sort()
print(l[k-1])

Submission status: Time Limit Exceeded

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

def generate_substring(x):
    for i in range(1, len(x)+1):
        for j in range(0, len(x)-i+1):
            # print(j,j+i)
            yield x[j:j+i]

ans = set()
for t in generate_substring(s):
    ans.add(t)
ret = list(sorted(list(ans)))
print(ret[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

chars=[]
L=len(s)

def append_substring(list, str, start):
  for i in range(start,len(str)):
    list.append(str[start:i+1])

# 文字集合をつくる
for i in range(L):
  chars.append(s[i])
chars=sorted(list(set(chars)))

# K 番目の部分文字列を探す
ss=[]
for c in chars:
  for i in range(L):
    if s[i] == c:
      append_substring(ss, s, i)
    ss=list(set(ss))
  if len(ss) >= K:
    break
ss.sort()
# print(ss)
print(ss[K-1])

Submission status: Time Limit Exceeded

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(i, n):
            f.add(s[i:j+1])
            if len(f) >= 1000:
                break
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + '1'
    while len(u) > len(v): v = v + '1'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
k = int(input())
ansnum = 0

while(ansnum < k):
    #print(s)
    for j in range(k):
        listj = []
        for i in range(len(s)-j):
            #print(s[i:i+j+1])
            listj.append(s[i:i+j+1])
        listj.sort()
        # print('listj:',listj)
        # print('j:',j)
        if len(listj) >= 2 and listj[0] == listj[1]:
            # print('choufuku')
            pass
        else:
            # j+1文字で重複なしの場合(j=0,1,2,3,4)
            s = ''.join(s)
            for i in range(len(listj)):
                num = s.index(''.join(listj[i]))
                # print('index:',num)
                # print('ansnum:',ansnum)
                if (len(s) - num) < k - ansnum:
                    ansnum += len(s) - num
                else:
                    ans = s[num:num + k - ansnum]
                    ansnum = k + 1
                    break
        if ansnum > k:
            break

#print('ans:',ans)
print(ans)

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:
from collections import defaultdict

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

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

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

main()

Submission status: Time Limit Exceeded

Solution code:
def get_substrs(s):
    strs = set()
    l = len(s)
    for i in range(l):
        for k in range(i,l):
            strs.add(s[i:k+1])
    return strs

if __name__ == '__main__':
    s = input()
    K = int(input())
    strs = get_substrs(s)
    strs = list(strs)
    strs.sort()
    print(strs[K-1])

Submission status: Time Limit Exceeded

Solution code:
s, k = input(), int(input())
abc = [chr(i) for i in range(ord('a'), ord('a')+26)]

cnt = 0
key_lst = []
for i in abc:
    key_set = set()
    for j in range(len(s)):
        if i == s[j]:
            for l in range(j+1, len(s)+1):
                if s[j:l] not in key_set:
                    key_set.add(s[j:l])

    if cnt + len(key_set) >= k:
        key_lst = list(key_set)
        break
    else:
        cnt += len(key_set)
        k -= len(key_set)

key_lst.sort()

print(key_lst[k-1])

Submission status: Time Limit Exceeded

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(i, n):
            f.add(s[i:j+1])
            if len(f) >= 10000:
                break
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + '1'
    while len(u) > len(v): v = v + '1'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Time Limit Exceeded

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

l = len(s)
substrings = []
for i in range(l):
    tmp = ""
    for j in range(i, l):
        tmp += s[j]
        substrings.append(tmp)
# print(substrings)
ansstrings = list(set(substrings))
ansstrings.sort()
print(ansstrings[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))

for i in range(k-1):
    list_pair.remove(min(list_pair))

print(min(list_pair))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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


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

Solution code:
# time complexity: O(|s|^2 + |subsample|log|subsample|)

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


def brute_force(s, K):
    substring_set = set()

    # brute-force
    for start in range(len(s)):
        for length in range(len(s) - start + 1):
            if length == 0:
                substring = s[start]
            else:
                substring = s[start:start+length]
            substring_set.add(substring)


    substring_list = sorted(list(substring_set))
    print(substring_list[K - 1])

brute_force(s, K)

Submission status: Time Limit Exceeded

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(i, n):
            f.add(s[i:j+1])
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + '1'
    while len(u) > len(v): v = v + '1'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 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), 5)):
                    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:
# -*- coding: utf-8 -*-

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

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

	for j in range(len(instr)+1):
		
		if i < j:
			str_list.append(instr[i:j])
		j += 1
	i += 1

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

print(str_list[target-1])

Submission status: 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+i,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 = list(input())
k = int(input())
sub = []
sub = s[:]
charGram = []
for j in range(2,len(s)+1):
    charGram += [''.join(s[i:i+j]) for i in range(len(s)-1)]
sub.extend(charGram)
sub = list(set(sub))
print(sorted(sub)[k-1])

Submission status: Time Limit Exceeded

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

ls = []
max_ch = string[0]
for i in range(len(string)):
    for j in range(i + 1, len(string) + 1):
        if len(ls) < k:
            ls.append(string[i:j])
            ls.sort()
            continue
        elif max_ch < string[i]: break
        elif string[i:j] in ls: continue
        for l in range(k):
            if string[i:j] < ls[l]:
                ls[l + 1:] = ls[l:]
                ls[l] = string[i:j]
                ls.pop()
                if string[i] > max_ch:
                    max_ch = string[i]
                break
print(ls[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
aa = set()
for i in range(len(s)):
    for j in range(i,len(s)+1):
        aa.add(s[i:j])
aa.add(s)
aa.remove("")
arr = list(aa)
arr.sort()
#arr.reverse()
#print(arr)
print(arr[k-1])

Submission status: Time Limit Exceeded

Solution code:
import string

s = input()
K = int(input())
candidate = set()
end = 0

for i in string.ascii_lowercase:
    pos = []#iの位置
    for j in range(len(s)):
        if s[j] == i:
            pos.append(j)
            
    if len(pos)!=0:
        candidate.add(i)
        c = 1
        while True:#subsetの長さc+1を変える
            if pos == []:
                break
            for j in range(len(pos)):
                if pos[j] == 10000:
                    continue
                if j+c>len(s)-1:#はみ出したらposから除く(10000に)
                    pos[j] = 10000
                    
            #10000を除く
            n = len(pos)
            for j in range(n):
                if pos[n-j-1] == 10000:
                    del pos[n-j-1]
            
            #posの可能性調べ終えたら次のiへ
            if pos == []:
                break
            
            #candidateに、iから始まる可能なc+1文字のsubsetを追加
            for j in pos:
                candidate.add(s[j:j+c+1])
            
            c += 1
        
        if len(candidate)>=K:
            end = 1
            break
            
    if end == 1:
        break
        
#print(list(sorted(candidate)))
print(list(sorted(candidate))[K-1])

Submission status: Time Limit Exceeded

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

print(x[a-1])

Submission status: Time Limit Exceeded

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)
		if(len(arr)>0):
			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: 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:
      if s[i:j] in A:
        continue
      else:
        A.append(s[i:j])
B = A
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())

sln = len(s)
subs = set()

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

Submission status: Time Limit Exceeded

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

ls = []
for i in range(len(string)):
    for j in range(i + 1, len(string) + 1):
        if len(ls) < k:
            ls.append(string[i:j])
            ls.sort()
            continue
        elif string[i:j] in ls:
            continue
        for l in range(k):
            if string[i:j] < ls[l]:
                ls[l + 1:] = ls[l:]
                ls[l] = string[i:j]
                ls.pop()
                break
print(ls[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

substring = {}

char_tuple = sorted(tuple(s))

for c in char_tuple:
    for i in range(len(s)):
        if s[i] == c:
            for j in range(i + 1, max(len(s) + 1, 5)):
                substring[s[i:j]] = True
    if len(substring) >= 5:
        break
#
# 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(sorted_words[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
LIST = []
for i in range(len(s)):
    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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#print str, K,  len(str)

#dic = []
dic = set()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import string
#string.ascii_lowercase
s = input()
K = int(input())
candidate = set()
end = 0

for i in string.ascii_lowercase:
    pos = []#iの位置
    for j in range(len(s)):
        if s[j] == i:
            pos.append(j)#ok
            
    if len(pos)!=0:
        candidate.add(i)
        c = 1
        while True:#subsetの長さc+1を変える
            if pos == []:
                break
            for j in range(len(pos)):
                if pos[j] == 10000:
                    continue
                if j+c>len(s)-1:#はみ出したらposから除く(10000に)
                    pos[j] = 10000
            
            #candidateに、iから始まる可能なc+1文字のsubsetを追加
            for j in pos:
                if j == 10000:
                    break
                candidate.add(s[j:j+c+1])
            
            #posの可能性調べ終えたら次のiへ
            for j in pos:
                if j != 10000:
                    break
            else:
                break
                
            c += 1
        
        if len(candidate)>=K:
            end = 1
            break
            
    if end == 1:
        break
        
#print(list(sorted(candidate)))
print(list(sorted(candidate))[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+k+1):
        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:
string = list(input())
K = int(input())
#print(string)



def Result(string,K):
    lst = []
    for j in range(1,len(string)+1):
        for i in range(len(string)-j+1):
            lst.append("".join(string[i:i+j]))
            #print(lst)
    lst = list(set(lst))
    lst.sort()
    return(lst[K-1])
        
print(Result(string,K))

Submission status: Time Limit Exceeded

Solution code:
import string

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

substring_list = []
for alphabet in string.ascii_lowercase:
    alphabet_places = [i for i, x in enumerate(s) if x == alphabet]
    if len(alphabet_places) == 0:
        continue
    else:
        for substring_head_place in alphabet_places:
            for substrig_len in range(1, len(s) - substring_head_place + 1):
                substring = s[substring_head_place: substring_head_place + substrig_len]
                if substring not in substring_list:
                    substring_list.append(substring)
        if len(substring_list) < K:
            continue
        else:
            sorted_substring_list = sorted(substring_list)
            print(sorted_substring_list[K - 1])
            break

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C

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

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

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

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

            start += 1
            ended += 1

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

Submission status: Time Limit Exceeded

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]
        a = "".join(a)
        ans_list.append(a)
        
ans_list = list(set(ans_list))
ans_list.sort()

print(ans_list[k])

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))
        if len(allstr) > 5:
            allstr2.sort()
            allstr = allstr2[0:6]

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

print(allstr2[N-1])

Submission status: Time Limit Exceeded

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

f1 = ""
f2 = ""
f3 = ""
f4 = ""
f5 = ""
g = ""
for a1 in range(0, len(s)):
	if g == "" or s[a1] <= g:
		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
					g = f5[0]
					if f4 == "" or f5 < f4:
						t = f4
						f4 = f5
						f5 = t
						if f5 == "":
							g = ""
						else:
							g = f5[0]
						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)