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())
n=len(s)
d=set()
#d={s[i:j+1] for j in range(i,n) for i in range(n)}
#d={s[i:j+1] for i in range(n) for j in range(i,n)}
for i in range(n):
    for j in range(i,max(n,i+5)):
        d.add(s[i:j+1])
ans=sorted(list(d))
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
d=set()
#d={s[i:j+1] for j in range(i,n) for i in range(n)}
d={s[i:j+1] for i in range(n) for j in range(i,n)}
#for i in range(n):
#    for j in range(i,n):
#        d.add(s[i:j+1])
ans=sorted(list(d))
print(ans[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

dic={}
for i in range(len(s)):
    dic[s[i:]]=1
arr=sorted(dic)
dic={}
for x in arr:
    for i in range(0,len(x)):
        tmp = x[:i+1]
        if dic.get(tmp,0)==0:
            K-=1
            dic[tmp]=1
        else:
            continue
        if K==0:
            print(x[:i+1])
            break

Submission status: Time Limit Exceeded

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

dic={}
for i in range(len(s)):
    dic[s[i:]]=1
arr=sorted(dic)
dic={}
for x in arr:
    for i in range(0,len(x)):
        tmp = x[:i+1]
        if dic.get(tmp,0)==0:
            K-=1
            dic[tmp]=1
        else:
            continue
        if K==0:
            print(x[:i+1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
a=[]
n=len(s)

for i in range(n):
  for j in range(1,n+1):
    a.append(s[i:i+j])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def compare(a, b):
    ll = [a, b]
    ll = sorted(ll)
    return ll[0] == a


db = []
for length in range(1, l + 1):
    for start in range(l + 1 - length):
        candidate = s[start:start+length]
        if len(db) >= 5:
            if compare(candidate, db[-1]):
                if candidate not in db:
                    db.append(candidate)
                    db = sorted(db)
                    db = db[:5]
        else:
            if candidate not in db:
                db.append(candidate)
                db = sorted(db)

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

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

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

S=[]
ls=len(s)
for i in range(ls):
    S.append([s[i:ls],0,ls-i])

S.sort()

S[0][1]=S[0][2]
for i in range(ls-1):
    t=0
    lS0=len(S[i][0])
    lSp1=len(S[i+1][0])
    while t<lS0 and t<lSp1 and S[i][0][t]==S[i+1][0][t]:
        t+=1
    S[i+1][1]=S[i+1][2]-t

#print(S)




k-=1
i=0
while k>=S[i][1] :
    k-=S[i][1]
    i+=1

ans=S[i][0][0:(S[i][2]-S[i][1]+k+1)]

#print(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

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

S=[]
for i in range(len(s)):
    S.append([s[i:len(s)],0,len(s)-i])

S.sort()

S[0][1]=S[0][2]
for i in range(len(S)-1):
    t=0
    while t<len(S[i][0]) and t<len(S[i+1][0]) and S[i][0][t]==S[i+1][0][t]:
        t+=1
    S[i+1][1]=S[i+1][2]-t

#print(S)




k-=1
i=0
while k>=S[i][1] :
    k-=S[i][1]
    i+=1

ans=S[i][0][0:(S[i][2]-S[i][1]+k+1)]

#print(i)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sub = []

for i in range(len(s)):
    for j in range(i,len(s)):
        if s[i:j+1] not in sub:
            sub.append(s[i:j+1])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])

Submission status: Time Limit Exceeded

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

sub = []

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

sub.sort()

print(sub[k-1])

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()
K = int(input())

def main():

    k = K

    start_point = ord('a')
    end_point = ord('z')
    curr_point = start_point
    while curr_point <= end_point:
        curr_char = chr(curr_point)
        curr_point += 1

        s = S
        matches_set = set()
        pattern = re.escape(curr_char) + r".*"
        while s:
            m = re.search(pattern, s)
            if m is None:
                break
            substr = m.group()
            matches_set.add(substr)
            s = substr[1:]

        matches_temp = list(matches_set)[:]
        for m in matches_temp:
            for i in range(len(m)):
                if i == 0:
                    continue
                matches_set.add(m[:i])

        matches = sorted(list(matches_set))
        matched_length = len(matches)
        if matched_length >= k:
            ans = matches[k - 1]
            break
        else:
            k -= matched_length

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()
K = int(input())

def main():

    matches = []

    start_point = ord('a')
    end_point = ord('z')
    curr_point = start_point
    while curr_point <= end_point:
        curr_char = chr(curr_point)
        curr_point += 1

        s = S
        matches_set = set()
        pattern = re.escape(curr_char) + r".*"
        while s:
            m = re.search(pattern, s)
            if m is None:
                break
            substr = m.group()
            matches_set.add(substr)
            s = substr[1:]

        matches_temp = list(matches_set)[:]
        for m in matches_temp:
            for i in range(len(m)):
                if i == 0:
                    continue
                matches_set.add(m[:i])

        matches += sorted(list(matches_set))
        if len(matches) >= K:
            break

    ans = matches[K - 1]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

count = 0

for alp in alphabet:
    ss = []
    # print(alp)
    if alp in s:
        pos = [i for i, x in enumerate(s) if x == alp]
        # print(pos)
        for i in pos:
            for j in range(1,len(s)-i+1):
                ss.append(s[i:i+j])
        ss = list(set(ss))
        ss.sort()
        # print(ss)
        if K - count <= len(ss):
            print(ss[K - count -1])
            break
        else:
            count += len(ss)

Submission status: Time Limit Exceeded

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

sl=[]
l=len(s)
x=0
for i in range(l):
    if i>k:
        x=i-k
    for j in range(x,i+1):
        sl.append(s[j:i+1])
              
li=[]
for i in sl:
    if i not in li:
        li.append(i)
        
li.sort()

print(li[k-1])

Submission status: Time Limit Exceeded

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

sl=[]
l=len(s)
for i in range(l):
    for j in range(i+1):
        sl.append(s[j:i+1])
              
li=[]
for i in sl:
    if i not in li:
        li.append(i)
        
li.sort()

print(li[k-1])

Submission status: Time Limit Exceeded

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

sl=[]
l=len(s)
for i in range(l):
    for j in range(i+1):
        sl.append(s[j:i+1])
        
sl.sort()      
li=[]
for i in sl:
    if i not in li:
        li.append(i)

print(li[k-1])

Submission status: Time Limit Exceeded

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

N = len(S)
A = []

for i in range(N):
    for j in range(1, N+1-i):
        A.append(S[i:i+j])

A = list(set(A))
A.sort()

print(A[k-1])

Submission status: Time Limit Exceeded

Solution code:
# 部分点解
s = input()
k = int(input())
n = len(s)
subs = []
for i in range(n):
    for j in range(n-i):
        subs.append(s[i:i+j+1])
print(sorted(set(subs))[k-1])

Submission status: Time Limit Exceeded

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

l = len(s)

ss = []
num = 0

for i in range(1,l+1):
    for j in range(l-i+1):
        slice = s[j:j+i]
#        print slice in ss
        if (slice in ss) is True:
#            print slice
            continue
        else:
            ss.append(slice)
            ss.sort()
            if len(ss) > K :
                ss.pop()
#        print ss

print ss[K-1]

Submission status: Time Limit Exceeded

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

l = len(s)

ss = []
num = 0

for i in range(1,l+1):
    for j in range(l-i+1):
        slice = s[j:j+i]
#        print slice in ss
        if (slice in ss) is True:
#            print slice
            continue
        else:
            ss.append(slice)
            ss.sort()
            if len(ss) > 5 :
                ss.pop()
#        print ss

print ss[K-1]

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
k = int(input())
a = set()
for i in range(len(s)):
  for j in range(i, len(s)):
    a.add("".join(s[i:j + 1]))
a = sorted(a)
print(a[k - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = int(input())
r = set()

# i: 文字数
for i in range(1,len(s)+1):
    # j: 始点
    for j in range(len(s)-i+1):
        sub = s[j:j+i]
        r.add(sub)

print(sorted(r)[t-1])

Submission status: Time Limit Exceeded

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

print(sorted(set([x for x in [s[i: i+n] for n in range(1, len(s) + 1) for i in range(0, len(s)-n+1)]]))[K-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def main():
    s = input()
    K = int(input())
    c = Counter(s)

    se = set()
    for k, v in sorted(c.items()):
        for i in range(len(s)):
            if s[i] == k:
                for j in range(i + 1, len(s) + 1):
                    se.add(s[i:j])
        if len(se) > K:
            break

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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

string_cands = []
for i in range(len(s)):
    for ii in range(i, len(s)+1):
        if i < ii:
            if ii != len(s):
                string_cands.append(s[i:ii])
            else:
                string_cands.append(s[i:])
            #print(i, ii, s[i:ii])
print(sorted(set(string_cands))[K-1])

Submission status: Time Limit Exceeded

Solution code:
def n_gram(s, n):
	return [s[i:i+n] for i in range(len(s)-n+1)]

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

n_gram_set = set()
for i in range(1, len(s)+1):
	n_gram_set = n_gram_set | set(n_gram(s, i))

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

Submission status: Time Limit Exceeded

Solution code:
import sys 
import math

#X = int(input())
#a = list(map(int, input().split(" ")))
#a = [0 for i in range(X+1)]

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

for i in range(len(s)):
    sub_str_len = len(sub_str)
    for j in range(i+1, len(s)+1):
        str = s[i:j]
        #print(str)
        if sub_str_len > 5:
            if sub_str[4] <= str:
                break
        if not(str in sub_str):
            sub_str.append(str)
    sub_str.sort()
   
sub_str.sort()
print(sub_str[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys 
import math

#X = int(input())
#a = list(map(int, input().split(" ")))
#a = [0 for i in range(X+1)]

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

for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        str = s[i:j]
        #print(str)
        if not(str in sub_str):
            sub_str.append(str)
sub_str.sort()
print(sub_str[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
N = int(input())
len_s = len(s)

sub_set = set()

for frm in range(len_s):
    for to in range(frm+1, len_s+1):
        sub_set.add(s[frm:to])
        

sub_list = list(sub_set)
sub_list.sort()

print(sub_list[N-1])

Submission status: Time Limit Exceeded

Solution code:
S=input();print(sorted(set([S[i:i+I]for I in range(len(S)+1)for i in range(len(S)-I+1)]))[int(input())])

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

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

    A = []
    for i in range(len(S)):
        for j in range(i+1, len(S)+1):
            A.append(S[i:j])

    print(sorted(list(set(A)))[K-1])

main()

Submission status: Time Limit Exceeded

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

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

    dict_list = []


    abc_list = 'abcdefghijklmnopqrstuvwxyz'
    
    for abc in abc_list:
        dict_temp = []
        j = 1
        while True:
            for i in range(len(s)):
                if  i + j <= len(s) and s[i] == abc and len(s[i:i+j]) <= K:
                    dict_temp.append(s[i:i+j])
            j += 1
            if j > len(s):
                break
        dict_temp = list(set(dict_temp))
        dict_list += dict_temp
        dict_list.sort()
        if len(dict_list) >= K:
            print(dict_list[K-1])
            break
        
    #print(dict_list)
            

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

    dict_list = []

    abc_list = 'abcdefghijklmnopqrstuvwxyz'

    for abc in abc_list:
        j = 1
        dict_temp = []
        while True:
            for i in range(len(s)):
                if  i + j <= len(s) and s[i] == abc:
                    dict_temp.append(s[i:i+j])
            j += 1
            if j > len(s):
                break
        dict_temp = list(set(dict_temp))
        dict_temp.sort()
        dict_list += dict_temp
        if len(dict_list) >= K:
            print(dict_list[K-1])
            break
    #print(dict_list)
            

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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


def substr(s):
    l = list(s)
    subl = []
    for i in range(len(l)):
        acc = ""
        for h in range(len(l)-i):
            acc = acc + l[i+h]
            subl.append("".join(list(acc)))
    return list(set(subl))

ans = sorted(substr(s))
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:

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


def substr(s):
    l = list(s)
    subl = []
    for i in range(len(l)):
        temp = l[i:]
        for h in range(len(temp)):
            subl.append("".join(temp[:h+1]))
    return list(set(subl))

ans = sorted(substr(s))
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
sub_list=[]
for i in range(len(s)):
    for j in range(i,len(s)+1):
        sub_list.append(s[i:j])
sub_list_uq = sorted(list(set(sub_list)))
print(sub_list_uq[K])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jul  6 22:20:31 2018
ABC097A
@author: maezawa
"""

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

perm = []

n = len(s)
for i in range(1, n+1):
    for j in range(n-i+1):
        perm.append(s[j:j+i])
    
ans_array = sorted(set(perm))
#print(ans_array)
print(ans_array[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
str_len = len(s)
substrings = []  

def get_substrings(substr_len):
    if substr_len == 0:
        return
    else:
        for i in range(0, str_len + 1 - substr_len):
            sub_s = s[i:i+substr_len]
            if not(sub_s in substrings):
                substrings.append(sub_s)
        get_substrings(substr_len - 1)

get_substrings(str_len)
substrings.sort()

print(substrings[K - 1])

Submission status: Time Limit Exceeded

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

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

s_set = {x for x in s_set if x}

s_list = sorted(list(s_set))

print(s_list[k - 1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
substrings=[]
for i in range(len(s)+1):
    X=s[:i]
    for j in range(i+1):
        Y=X[j:]
        if Y not in substrings:
            substrings.append(Y)
        else:
            pass
substrings.remove(substrings[0])
substrings.sort()
print(substrings[K-1])

Submission status: Time Limit Exceeded

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

l = len(s)
lst = [[s[i], i] for i in range(l)]
lst.sort()
substr = []
i = 0
init_c = lst[i][0]

while len(substr) < K:
    while True:
        j = lst[i][1]
        for k in range(j, l):
            substr.append(s[j:k+1])
        i += 1
        init_c_ = init_c
        if i == l: break
        init_c = lst[i][0]
        if init_c != init_c_: break
    substr = list(set(substr))

substr.sort()
print(substr[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = len(s)
substr = []
for i, j in itertools.combinations_with_replacement(list(range(0, l)), 2):
    substr.append(s[i:j+1])

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

Submission status: Time Limit Exceeded

Solution code:
# n < 50 のとき
# substring の全列挙

s = input()
n = len(s)
K = int(input())

substr = []
for i in range(n):
    for j in range(i, n):
        substr.append(s[i:j+1])

substr = sorted(list(set(substr)))
print(substr[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import *
s = input()
k = int(input())

def get_all_substrings(input_string):
  length = len(input_string)
  return [input_string[i:j+1] for i in range(length) for j in range(i,length)]
# print(sorted(set(get_all_substrings(s))))
print(sorted(set(get_all_substrings(s)))[k-1])

Submission status: Time Limit Exceeded

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

    subs = []
    for i in range(len(s)):
        for j in range(len(s)):
            try:
                subs.append(s[i:i+j+1])
            except:
                break
    subs = set(subs)
    print(sorted(list(subs))[K-1])

Submission status: Time Limit Exceeded

Solution code:

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

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

    print(ss[k-1])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
sbst = set()
for i in range(1, len(s)+1):
    for j in range(len(s)-i+1):
        sbst.add(s[j:j+i])
sbstl = sorted(list(sbst))
print(sbstl[k-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
s=input()
K=int(input())

a = defaultdict(list)

for i, c in enumerate(s):
    a[c].append(i)


result = set()
for k, v in a.items():
    for i in v:
        for j in range(i+1, len(s)+1):
            result.add(s[i:j])

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

Submission status: Time Limit Exceeded

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

list = []
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    tmp = s[i:j]
    if not tmp in list:
      list.append(tmp)
    list.sort()
    if len(list)>K:
      list = list[:K]

print(list[K-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for i in range(26):
    for j in d[chr(ord('a')+i)]:
        for k in range(len(s[j:])):
            sub.add(s[j:j+k+1])
#            print(s[j:j+k+1])
#    print(len(sub), k)    
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break

Submission status: Time Limit Exceeded

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

def solve(s, K):
	substrings = []
	substrings_dict = {}

	s_len = len(s)
	for j in range(1, s_len+1):
		for i in range(0, s_len):
			substring = s[i:i+j]
			if substring in substrings_dict:
				continue
			substrings_dict[substring] = True
			substrings.append(substring)
	substrings.sort()
	return substrings[K-1]

if __name__ == "__main__":
	s = input()
	K = int(input())
	print(solve(s, K))

Submission status: Time Limit Exceeded

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

substrings = set()

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

substrings_list = sorted(list(substrings))
print(substrings_list[K-1])

Submission status: Time Limit Exceeded

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

l =[]

for i in range(len(s)):
    tmp = ''
    for j in range(i, len(s)):
        if j > i + 4: break
        tmp += s[j]
        l.append(tmp)
l.sort()

l2 = []
for x in l:
    if x not in l2:
        l2.append(x)

ans = l2[K - 1]

print(ans)

Submission status: Time Limit Exceeded

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

l =[]
l2 = []

for i in range(len(s)):
    tmp = ''
    for j in range(i, len(s)):
        if j > i + 4: break
        tmp += s[j]
        l.append(tmp)
l.sort()

for i in l:
    is_double = 0
    for j in l2:
        if j == i:
            is_double = 1
            break
    if is_double == 0:
        l2.append(i)

ans = l2[K - 1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
sub = set(S)
for step in range(2, len(S) + 1):
    for i in range(0, len(S) - step + 1):
        sub.add(S[i:i+step])
print(sorted(sub)[K - 1])

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
K = int(input())
sub = set(S)
for step in range(2, len(S) + 1):
    for i in range(0, len(S) - step + 1):
        st = ''
        for s in S[i:i + step]:
            st += s
        sub.add(st)
substring = list(sub)
substring.sort()
print(substring[K - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
sub = {s}
for d in range(1,len(s)):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
sub = list(sub)
n = len(sub)
for i in range(K):
    for j in range(n-i):
        a, b = sub[-i-1], sub[j]
        if a > b: sub[-i-1], sub[j] = b, a
print(sub[-K])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
sub = {s}
for d in range(1,len(s)):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
print(sorted(sub)[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
 
ans=[]
ans.append(s)
 
 
for i in range(len(s)-1):
 for j in range(i+2):
  cut_s=s[j:j+len(s)-i-1]
  if cut_s not in ans:
   ans.append(cut_s)
   ans.sort()
  if len(ans)>K:
    ans.pop()
 
answer=ans[K-1]
print(answer)

Submission status: Time Limit Exceeded

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

slist = list(s)
n = len(s)
substlist = []


for i in range(97,123):
  if len(list(set(substlist))) > 5:
    break
  arglist = []
  for c in range(len(slist)):
    if slist[c] == chr(i):
      arglist.append(c)
      substlist.append(chr(i))
    for k in arglist:
      for j in range(1,5):
        if k + j <= n:
          substlist.append(s[k:k+j+1])
        
while substlist.count("")>0:
  substlist.remove("")

hoge = list(set(substlist))
hoge.sort()
print(hoge[po-1])

Submission status: Time Limit Exceeded

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

cand_list = []
for i in range(len(s)):
    for j in range(0, len(s)+1):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break

print(sorted(list(set(cand_list)))[k-1])

Submission status: Time Limit Exceeded

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

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

print(sorted(list(set(cand_list)))[k-1])

Submission status: Time Limit Exceeded

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

def decompose(s):
    l = []
    N = len(s)
    i = 0
    while i < N:
        j = i
        while j <= N:
            l.append(s[i:j])
            j += 1
        i += 1
    l = list(set(l))
    l.sort()
    return l
print(decompose(s)[k])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def abc097_c():
    s = input()
    k = int(input())
    n = len(s)
    substr = [[] for _ in s]
    substr[-1] = [s[-1]]

    for i in range(n - 2, -1, -1):
        substr[i] = [s[i] + val for val in substr[i + 1]] + [s[i]]

    substr = list(set([val for vals in substr for val in vals]))
    substr.sort()

    return substr[k - 1]


print(abc097_c())

Submission status: Time Limit Exceeded

Solution code:
def abc097_c():
    s = input()
    k = int(input())
    substr = []
    for i in range(len(s) + 1):
        for j in range(i + 1, len(s) + 1):
            if s[i:j] not in substr:
                substr.append(s[i:j])
    substr = sorted(set(substr))

    return substr[k - 1]

print(abc097_c())

Submission status: Time Limit Exceeded

Solution code:
def abc097_c():
    s = input()
    k = int(input())
    substr = []
    for i in range(len(s) + 1):
        for j in range(i + 1, len(s) + 1):
            substr.append(s[i:j])
    substr = sorted(set(substr))

    return substr[k - 1]


print(abc097_c())

Submission status: Time Limit Exceeded

Solution code:
import string


lowercase = string.ascii_lowercase

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

substrings = ['']

for i in range(K):
    for c in lowercase:
        for string in substrings:
            if string+c in s and string+c not in substrings:
                substrings.append(string+c)

print(sorted(substrings)[K])

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
sub=[]
for i in range(len(s)):
    for j in range(len(s)):
        if sub.count(s[i:j+1])==0 and s[i:j+1]!="":
            sub.append(s[i:j+1])
sub.sort()
print(sub[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    if not s[i] in d:
        d.append(s[i])
    ele = []
    ele.append(s[i])
    for j in range(i+1,len(s)):
        ele.append(s[j])
        substr = ''.join(ele)
        if not substr in d and len(substr)<=K:
            d.append(substr)
d.sort()
print(d[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    if not s[i] in d:
        d.append(s[i])
    ele = []
    ele.append(s[i])
    for j in range(i+1,len(s)):
        ele.append(s[j])
        if not ''.join(ele) in d:
            d.append(''.join(ele))
d.sort()
print(d[K-1])

Submission status: Time Limit Exceeded

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

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

list_substring=list(set_substring)
list_substring.sort()

print(list_substring[K-1])