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

set_substring = set()
for i in range(0,len(s)):
	for j in range(0,len(s)):
		if(i<=j):
			str1 = s[i:j]
			str2 = s[j+1:]
			str3 = s[j:]

			set_substring.add(str1)
			set_substring.add(str2)
			set_substring.add(str3)


set_substring.remove("")

list_substring=list(set_substring)
list_substring.sort()

print(list_substring[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, len(s) - i):
        substring = s[i:i + slen + 1]
        substr_set.add(substring)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline()).replace("\n","")
k = int(list(sys.stdin.readline())[0]) - 1

a = []
for i in range(0, len(s)):
	for j in range(i + 1, len(s) + 1):
		v = s[i:j]
		if not v in a:
			a = a + [v]

a.sort()

print(a[k])

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline()).replace("\n","")
k = int(list(sys.stdin.readline())[0])

a = []
for i in range(0, len(s)):
	for j in range(i, len(s) + 1):
		v = s[i:j]
		if not v in a:
			a = a + [v]

a.sort()
print(a[k])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
subs = []
for i in range(0, len(s)):
    for j in range(i+1, len(s)+1):
        if i == j:
            subs.append(s[i])
        else:
            subs.append(s[i:j])
subs = list(set(subs))
subs.sort()
print(subs[K-1])

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    text = input()
    number = int(input())
    set = set()

    for text_len in range(1, len(text) + 1):
        for ss_len in range(len(text) - text_len + 1):
            set.add(text[ss_len:text_len + ss_len])

    print(sorted(set)[number - 1])

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    text = input()
    number = int(input())
    dic = []

    for ss_len in range(1, len(text) + 1):
        for ss in range(0, len(text) - ss_len + 1):
            c = text[ss:ss_len + ss]
            if c not in dic:
                dic.append(c)

    dic = sorted(dic)

    print(dic[number - 1])

Submission status: Time Limit Exceeded

Solution code:
def dfs(s, dic):
    if len(s) > 0:
        tmp = ''
        for i in s:
            tmp += i
            reg_dic(dic, tmp)
        if len(s) == 1:
            return
        else:
            s = s[1:]
            dfs(s, dic)

def reg_dic(dic, s):
    if s not in dic:
        dic[s] = 1

if __name__ == '__main__':
    s = input()
    K = int(input())
    
    dic = {}

    dfs(s, dic)

    ans = sorted(dic.keys())
    print(ans[K - 1])

Submission status: Time Limit Exceeded

Solution code:
"""
TODO
"""


def substring(s):
    ss = []
    max_ss = len(s) + 1
    for ss_len in range(1, max_ss):
        max_ofs = max_ss - ss_len
        for ofs in range(0, max_ofs):
            c = s[ofs:ss_len + ofs]
            ss.append(c)
    ss = list(set(ss))
    return sorted(ss)


def nth_largest(s, n):
    ss = substring(s)
    return ss[n - 1]


if __name__ == "__main__":
    s = input().rstrip()
    K = int(input().rstrip())
    print(nth_largest(s, K))

Submission status: Time Limit Exceeded

Solution code:
"""
TODO
"""
import sys


def substring(s):
    ss = []
    for ss_len in range(1, len(s) + 1):
        for ofs in range(0, len(s) - ss_len + 1):
            c = s[ofs:ss_len + ofs]
            ss.append(c)
    ss = list(set(ss))
    return sorted(ss)


def nth_largest(s, n):
    ss = substring(s)
    return ss[n - 1]


if __name__ == "__main__":
    s = input().rstrip()
    K = int(input().rstrip())
    print(nth_largest(s, K))

Submission status: Time Limit Exceeded

Solution code:
"""
TODO
"""


def substring(s):
    ss = []
    for ss_len in range(1, len(s) + 1):
        for ofs in range(0, len(s) - ss_len + 1):
            c = s[ofs:ss_len + ofs]
            if c not in ss:
                ss.append(c)
    return sorted(ss)


def nth_largest(s, n):
    ss = substring(s)
    return ss[n - 1]


if __name__ == "__main__":
    s = input().rstrip()
    K = int(input().rstrip())
    print(nth_largest(s, K))

Submission status: Time Limit Exceeded

Solution code:
import sys
s = input()
K = int(input())
     
sort_s = sorted(list(s))
temp = []
for i in range(len(s)):
    for j in range(1,K+1):
        # if i >j:
        # print("{},{}".format(i,j))
        if i+j <= len(s):
            temp.append(s[i:i+j])
sort_temp=sorted(temp)
ans =[]
for i in sort_temp:
    if i not in ans:
        ans.append(i)
sort_ans = sorted(ans)
print(sort_ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
if len(s)<5:
    s_len = len(s)
else:
    s_len = 5
ans=list()
for length in range(1,s_len + 1):
    for pos in range(0,len(s)-length+1):
        tmp = s[pos:pos+length]
        if tmp not in ans:
            ans.append(tmp)
            ans.sort()

print(ans[K-1])

Submission status: Time Limit Exceeded

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



# S = []
# for i in range(len(s)+1):
#     for j in range(i+1,len(s)+1):
#         if not(s[i:j] in S):
#             S.append(s[i:j])
#         # print(s[i:j])

t = s
S = []

while(1):
    for i in range(t.index(min(t))+1,len(s)+1):
        if not(s[t.index(min(t)):i] in S):
            S.append(s[t.index(min(t)):i])
    if t.count(min(t)) == 1 and len(S)>=k: break
    else: t = t.replace(min(t),"z",1)
    # print(t)
    # print(S)

S.sort()

print(S[k-1])

Submission status: Time Limit Exceeded

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

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

# 処理
res = []
for l in range(1, len(s) + 1):
    subs_l = []
    for i in range(len(s) - l + 1):
        sub = s[i:i+l]
        if not sub in subs_l:
            subs_l.append(sub)

    res += subs_l
    
ans = sorted(res)[k-1]
    
# 出力
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
N = int(input())
l = len(s)
li=[]
for scope in range(1,l+1):
    for first in range(l-scope+1):
        if not s[first:first+scope] in li:
            li.append(s[first:first+scope])

li.sort()
print(li[N-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
subs = []
for begin in range(0,len(s)):
    for end in range(begin,len(s)):
        sub = s[begin:end+1]
        if sub not in subs:
            subs.append(sub)
print(sorted(subs)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import re

str = input()
k = int(input())

strl = list(set([c for c in str]))
strl.sort()

substring = []
for h in strl:
	compiled = re.compile(h)
	st = 0
	m = compiled.search(str, st)
	while m:
		sub = m.start()
		for i in range(sub, len(str)):
			t = str[sub:i+1]
			if(not (t in substring)):
				substring.append(t)
		st = sub + 1
		m = compiled.search(str, st)
	
	if(len(substring)-len(strl) >= k-1):
		break


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

Submission status: Time Limit Exceeded

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

substrings = []
for i in range(len(s)+1):
    for j in range(len(s)-i+1):
        # print('i={}, i+j={}, s[i:i+j]={}'.format(i, i+j, s[i:i+j]))
        if s[i:i+j] != '':
            substrings.append(s[i:i+j])
substrings = sorted(set(substrings))
print(substrings[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
st = set()
num = int(input())
for i in range(len(s)+1):
    for j in range(len(s)+1-i):
        st.add(s[i:i+j])
st.remove("")
print(sorted(st)[num-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

S = []
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        if not(s[i:j] in S):
            S.append(s[i:j])
        # print(s[i:j])

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

Submission status: Time Limit Exceeded

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

alphabet = "abcdefghijklmnopqrstuvwxyz"
candidates = []

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

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

Submission status: Time Limit Exceeded

Solution code:
#K-th Substring

#入力
s = input()
k = int(input())
 
 #計算
subs = set()
for i in range(len(s)):
  for j in range(i+1, len(s)+1):
    subs.add(s[i:j])

subs = list(subs) 
subs.sort()

#出力
print(subs[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
st = set()
for j in range(len(s)+1):
    for i in range(j):
        st.add(s[i:j])
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))

Submission status: Time Limit Exceeded

Solution code:
import heapq

s=input()
k=int(input())
n=len(s)
ans=set()

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

ans.remove('')

ansh=[]
for ss in ans:
    heapq.heappush(ansh,ss)
for _ in range(k-1):
    heapq.heappop(ansh)
print(ansh[0])

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):
		
		# 開始位置iの方が大きいものはやる必要がないのでjを増やす
		if i >= j:
			j = i + 1
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		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 -*-

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

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

	for j in range(len(instr)+1):
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break
		
		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:
s = input()
k = int(input())
dic = []

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

print(sorted(dic)[k])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
list = ["zzz" for i in range(K)]
for i in range(len(s)):
    for j in range(len(s)-i):
        if len(list) < K or s[i : i+j+1] < list[K-1]:
            # sSet.add(s[i : i+j+1]
            if all([k != s[i : i+j+1] for k in list]):
                list[K-1] = s[i : i+j+1]
                list.sort()
print(list[K - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
array = ""
a = set()

for i in range(len(s)):
    a.add(s[i])
    for word in s[i:]:
        array += word
        a.add(array)
    array = ""
print(sorted(a)[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
array = ""
a = set()

for i in range(len(s)):
    for word in s[i:]:
        array += word
        a.add(array)
        a.add(word)
    array = ""
print(sorted(a)[k-1])

Submission status: Time Limit Exceeded

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

s_set = set({})
string =""

for i in range(len(s)):
    for j in range(len(s)):
        if i+j<len(s):
            for k in range(j+1):
                string+=s[i+k]
            s_set.add(string)
            string=""

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

Submission status: Time Limit Exceeded

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

list = []

for i in range(len(s)):
    if s[i] not in list:
        list.append(s[i])
    for j in range(2,len(s)+1):
        if (s[i:j] not in list) and s[i:j] !='' and len(s[i:j]) <= 5 :
            list.append(s[i:j])

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

Submission status: Time Limit Exceeded

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

list = []

for i in range(len(s)):
    if s[i] not in list:
        list.append(s[i])
    for j in range(2,len(s)+1):
        if (s[i:j] not in list) and s[i:j] !='':
            list.append(s[i:j])

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

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)-i):
        sSet.add(s[i : i+j+1])
list = list(sSet)
list.sort()
print(list[K - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s,n=input(),int(input())
ss=[s[i:i+j+1] for i in range(len(s)) for j in range(5)]
ss.sort()
print(sorted(set(ss), key=ss.index)[n-1])

Submission status: Time Limit Exceeded

Solution code:
s,n=input(),int(input())
ss=[s[i:i+j+1] for i in range(len(s)) for j in range(5)]
print(sorted(set(ss), key=sorted(ss).index)[n-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
N = len(S)
tmp = []
lis = []
lis_uniq = []

for i in range(N):
    tmp = []
    for j in range(N-i):
        tmp.append(str(S[j:i+j+1]))

    tmp = list(set(tmp))
    tmp = sorted(tmp)
    lis_uniq = lis_uniq + tmp
    m = len(lis_uniq)
    #if(m > K+1):break

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

init = sorted(set(list(s)))[:K]
n=0
z=[]
while(n<len(s)):
    x=[]
    for i in range(len(s)-n):
        if s[i] in init:
            x.append(s[i:i+n+1])
    y = sorted(set(x+z))
    z = y[:K]
    n += 1
print(sorted(set(z))[K-1])

Submission status: Time Limit Exceeded

Solution code:
import math

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

n=0
z=[]
while(n<len(s)):
    x=[]
    for i in range(len(s)-n):
        x.append(s[i:i+n+1])
    y = sorted(set(x+z))
    z = y[:K]
    n += 1
print(sorted(set(z))[K-1])

Submission status: Time Limit Exceeded

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

subs = set()

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

n=0
z=[]
while(n<len(s)):
    x=[]
    for i in range(len(s)-n):
        x.append(s[i:i+n+1])
    y = sorted(set(x))
    z += y[:K]
    n += 1

print(sorted(set(z))[K-1])

Submission status: Time Limit Exceeded

Solution code:
import math

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

n=0
z=[]
while(n<len(s)):
    x=[]
    for i in range(len(s)-n):
        x.append(s[i:i+n+1])
    y = sorted(list(set(x)))
    z += y[:5]
    n += 1
#print(z)
print(sorted(list(set(z)))[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
K=int(input())
l=len(s)
a=[]
for i in range(0,l):
    for j in range(i,l):
        a.append(s[i:j+1])
a=sorted(list(set(a)))
print(a[K-1])

Submission status: Time Limit Exceeded

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


def sort_here(ll):  # バブルソート
    for m in range(len(ll)):
        for n in range(len(ll)-1-m):
            A, B = compare(ll[n], ll[n+1])
            ll[n] = A
            ll[n + 1] = B
    return ll


def compare_(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    a = len(A)
    b = len(B)

    if a > b:
        if A[:b] == B:
            return B, A
    elif b > a:
        if B[:a] == A:
            return A, B

    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B

def compare(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B

    if len(A) < len(B):
        return A, B
    elif len(B) < len(A):
        return B, A
    else:
        raise Exception


# まずは長さが5以下で存在しうるsubstringを準備
i_list = []
for i in range(1, K+1):
    # i文字数のsutringをまずは作る
    for j in range(len(s) - i + 1):
        cand = s[j:j+i]
        if cand not in i_list:
            i_list.append(s[j:j+i])

#print(i_list)

# 並び替え
i_list = sort_here(i_list)
#print(i_list)


# 出力
print(i_list[K-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = []

    for i in range(l):
        for j in range(l+1):
            t = s[i:j]
            if len(t) and t not in substrings:
                substrings.append(t)
                substrings.sort()
                if len(substrings) > 5 and substrings[-1] == t:
                    substrings.pop()
                    break
    return substrings[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

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


def sort_here(ll):  # バブルソート
    for m in range(len(ll)):
        for n in range(len(ll)-1-m):
            A, B = compare(ll[n], ll[n+1])
            ll[n] = A
            ll[n + 1] = B
    return ll


def compare_(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    a = len(A)
    b = len(B)

    if a > b:
        if A[:b] == B:
            return B, A
    elif b > a:
        if B[:a] == A:
            return A, B

    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B

def compare(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B

    if len(A) < len(B):
        return A, B
    elif len(B) < len(A):
        return B, A
    else:
        raise Exception


# まずは長さが5以下で存在しうるsubstringを準備
i_list = []
for i in range(1, 6):
    # i文字数のsutringをまずは作る
    for j in range(len(s) - i + 1):
        cand = s[j:j+i]
        if cand not in i_list:
            i_list.append(s[j:j+i])

#print(i_list)

# 並び替え
i_list = sort_here(i_list)
#print(i_list)


# 出力
print(i_list[K-1])

Submission status: Time Limit Exceeded

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


def sort_here(ll):  # バブルソート
    for m in range(len(ll)):
        for n in range(len(ll)-1-m):
            A, B = compare(ll[n], ll[n+1])
            ll[n] = A
            ll[n + 1] = B
    return ll


def compare_(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    a = len(A)
    b = len(B)

    if a > b:
        if A[:b] == B:
            return B, A
    elif b > a:
        if B[:a] == A:
            return A, B

    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B

def compare(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B

    if len(A) < len(B):
        return A, B
    elif len(B) < len(A):
        return B, A
    else:
        raise Exception


# まずはありうるsubstringを準備
i_list = []
for i in range(1, len(s) + 1):
    # i文字数のsutringをまずは作る
    for j in range(len(s) - i + 1):
        cand = s[j:j+i]
        if cand not in i_list:
            i_list.append(s[j:j+i])

#print(i_list)

# 並び替え
i_list = sort_here(i_list)
#print(i_list)


# 出力
print(i_list[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def sort_here(ll):  # バブルソート
    for m in range(len(ll)):
        for n in range(len(ll)-1-m):
            A, B = compare(ll[n], ll[n+1])
            ll[n] = A
            ll[n + 1] = B
    return ll


def compare(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    a = len(A)
    b = len(B)

    if a > b:
        if A[:b] == B:
            return B, A
    elif b > a:
        if B[:a] == A:
            return A, B

    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B


# まずはありうるsubstringを準備
i_list = []
for i in range(1, len(s) + 1):
    # i文字数のsutringをまずは作る
    for j in range(len(s) - i + 1):
        cand = s[j:j+i]
        if cand not in i_list:
            i_list.append(s[j:j+i])

#print(i_list)

# 並び替え
i_list = sort_here(i_list)
#print(i_list)


# 出力
print(i_list[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
K = int(raw_input())
subs = set()
for i in range(len(s)):
  for j in range(i, len(s)):
    subs.add(s[i:j+1])
subs = list(subs)
subs.sort()
print subs[K-1]

Submission status: Time Limit Exceeded

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

def sort_here(ll):
    for _ in range(len(ll)):
        for n in range(len(ll)-1):
            A, B = compare(ll[n], ll[n+1])
            ll[n] = A
            ll[n + 1] = B

    return ll


def compare(A, B):
    # このゲームにおける比較
    # 小、大の順で返す
    a = len(A)
    b = len(B)

    if a > b:
        if A[:b] == B:
            return B, A
    elif b > a:
        if B[:a] == A:
            return A, B

    for i in range(len(min(A, B))):
        if A[i] > B[i]:
            return B, A
        elif A[i] < B[i]:
            return A, B


# まずはありうるsubstringを準備
i_list = []
for i in range(1, len(s) + 1):
    # i文字数のsutringをまずは作る
    for j in range(len(s) - i + 1):
        cand = s[j:j+i]
        if cand not in i_list:
            i_list.append(s[j:j+i])

#print(i_list)

# 並び替え
i_list = sort_here(i_list)
#print(i_list)


# 出力
print(i_list[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
str=[]
p=1
for i in range(k):
    for j in range(len(s)):
        if j+i+1<=len(s):
            str.append(s[j:j+i+1])
            str=list(set(str))
str.sort()
print(str[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))



if len(s)<=50:
    list_pair.sort()
    print(list_pair[k-1])
else:
    abc = "abcdefghijklmnopqrstuvwxyz"
    tmp = []

    i = 0
    j = 0
    while len(tmp) < k + 1:
        for list_j in list_pair:

            if abc[i]==list_j[0]:
                tmp.append(list_j)

        i = i+1

    tmp.sort()

    print(tmp[k-1])

Submission status: Time Limit Exceeded

Solution code:
Strings = list(input())
k = int(input())
NEW = []
for i in range(len(Strings)):
    for j in range(i+1, len(Strings)+1):
        add_st = ''.join(Strings[i:j])
        NEW.append(add_st)


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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = set()

    pre_check = set()
    for ch in s:
        pre_check.add(ch)
    pre_check = list(pre_check)
    pre_check.sort()
    pre_check = pre_check[:5]

    for i in range(l):
        if not s[i] in pre_check:
            continue
        for j in range(l+1):
            t = s[i:j]
            if len(t):
                substrings.add(t)
    ans = list(substrings)
    ans.sort()
    return ans[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
str=[]
p=1
for i in range(len(s)):
    for j in range(len(s)):
        if j+i+1<=len(s):
            str.append(s[j:j+i+1])
    str=list(set(str))
str.sort()
print(str[k-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = set()
    for i in range(l):
        for j in range(l+1):
            t = s[i:j]
            if len(t):
                substrings.add(t)
    ans = list(substrings)
    ans.sort()
    return ans[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
flag = 0
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
  if len(set(d))==z:
    break
print(sorted(set(d))[z-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

os = sorted(list(set(s).union()))

nth = 0
found = []
for o in os:
  samehead = []
  for i in range(len(s)):
    if s[i] == o:
      for j in range(i+1, len(s)+1):
        if s[i:j] in samehead: continue
        samehead.append(s[i:j])
  cands = sorted(samehead)
  if nth + len(cands) < K:
    found += samehead
    nth += len(cands)
    continue
  print(cands[K-nth-1])
  break

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 = [s[i:i+j+1] for i in range(len(s)-j)]
        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)
            lens = len(s)
            for i in range(len(listj)):
                num = s.index(''.join(listj[i]))
                a = lens - num
                # print('index:',num)
                # print('ansnum:',ansnum)
                if a < k - ansnum:
                    ansnum += a
                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())
l = list(s)
for i in range(len(s)-1):
    for j in range(1, len(s)+1):
        if i < j:
            l.append(s[i:j])
l = list(set(l))
l.sort()
print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
ss = []
for i in s:
  ss.append(i)
k = int(input())
a = []
for i,j in enumerate(ss):
  for l in range(i+1,len(s)+1):
    a.append(s[i:l])
a = list(set(a))
a.sort()
print(a[k-1])