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 = str(input())
l = []
n = len(s)
for i in range(n):
    for j in range(i,n):
        l.append(s[i:j+1])
l = list(set(l))
l.sort()
#print(l)
print(l[int(input())-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
ans=[]
for i in range(len(s)):
  for j in range(len(s)):
    ans.append(s[j:])
  s=list(s)
  s.pop()
  s=''.join(s)
ans=list(set(ans))
ans.sort()
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
substrings = {s[i:j]:0 for i in range(len(s)) for j in range(i+1, len(s)+1) if len(s[i:j]) <= K}
print(sorted(substrings)[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

length = len(s)
sub = []
for item in "abcdefghijklmnopqrstuvwxyz":
  if item in s:
    for i, c in enumerate(s):
      if c == item:
        for j in range(0,length - i + 1):
          if j==0:
            if s[i] not in sub:
              sub.append(s[i])
          else: 
            if s[i:i+j] not in sub:
              sub.append(s[i:i+j])
    if len(sub) >= k:
      break
print(sorted(sub)[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

_set=set()

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

#print(sorted(list(_set)))
print(sorted(list(_set))[K-1])

Submission status: Time Limit Exceeded

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

substringList = []
for i in range(1,length+1) :
    for j in range(length-i+1) :
        substringList.append(s[j:j+i])


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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
K = int(input())
stack = []
for i in range(len(s)):
    for j in range(i+1, min(i+1+K, len(s))+1):
        sub = s[i:j]
        if sub not in stack:
            stack.append(sub)
stack.sort()
print(stack[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def solve(string):
    s, k = string.split()
    g = []
    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            g.append(s[i:j])
    g = sorted(set(g))
    return g[int(k)-1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Time Limit Exceeded

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

d = dict()
SET = set()
for i in range(len(s)):
    if not d.__contains__(s[i]):
        d[s[i]] = []
    d[s[i]].append(i)


alphabet = 'abcdefjhijklmnopqrstuvwxyz'

for c in alphabet:
    if not d.__contains__(c):
        continue
    l = d[c].copy()
    SET.add(c)
    if(len(SET) >= K):
        break
    tmp = []
    for idx in l:
        if idx+1>=len(s):
            continue
        tmp.append((idx,s[idx+1]))
    tmp.sort(key = lambda x:x[1])
    for idx,nxt in tmp:
        for step in range(2,len(s)+1):
            if idx+step>len(s):
                break
            if s[idx:idx+step] not in SET:
                SET.add(s[idx:idx+step])
    if len(SET) >= K:
         break

res = list(SET)
res.sort()
print(res[K-1])

Submission status: Time Limit Exceeded

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

idx_dict = defaultdict(list)

for i, c in enumerate(s):
    idx_dict[c].append(i)
results = set()
abc = "abcdefghijklmnopqrstuvwxyz"

for al in abc:
    idxs = idx_dict[al]
    count = len(idxs)
    if count == 0:
        continue

    lens = [1 for i in range(count)]
    while len(results) < K:
        useIdx = -1
        useStr = "あああ"
        for i in range(count):
            i1 = idxs[i]
            i2 = idxs[i] + lens[i]
            if i2 <= len(s):
                ss = s[i1:i2]
                if useStr > ss:
                    useStr = ss
                    useIdx = i
        if useIdx < 0:
            break
        lens[useIdx] += 1
        results.add(useStr)
sorted = list(results)
sorted.sort()
print(sorted[K - 1])

Submission status: Time Limit Exceeded

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

results = set()
abc = "abcdefghijklmnopqrstuvwxyz"

for al in abc:
    idxs = []
    last = 0
    while True:
        f = s.find(al, last)
        if f < 0:
            break
        idxs.append(f)
        last = f + 1
    count = len(idxs)
    if count == 0:
        continue

    lens = [1 for i in range(count)]
    while len(results) < K:
        useIdx = -1
        useStr = "あああ"
        for i in range(count):
            i1 = idxs[i]
            i2 = idxs[i] + lens[i]
            if i2 <= len(s):
                ss = s[i1:i2]
                if useStr > ss:
                    useStr = ss
                    useIdx = i
        if useIdx < 0:
            break
        lens[useIdx] += 1
        results.add(useStr)
sorted = list(results)
sorted.sort()
print(sorted[K - 1])

Submission status: Time Limit Exceeded

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

for i in range(len(s)+1):
	for j in range(i,len(s)+1):
		if len(s[i:j]) <= 5:
			substring.append(s[i:j])

		
sub = list(set(substring))
sub.remove('')
sub.sort()

print(sub[k-1])

Submission status: Time Limit Exceeded

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

for i in range(len(s)+1):
	for j in range(i,len(s)+1):
		substring.append(s[i:j])
		
sub = list(set(substring))
sub.remove('')
sub.sort()

print(sub[k-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
# python のsortは辞書順
substrings = []
for i in range(1, len(S)+1):  # 文字数
    for n in range(len(S) - i + 1):
        sub = S[n:n + i]
        if sub not in substrings:
            substrings.append(sub)
# print(substrings)
substrings.sort()
print(substrings[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

alpha_list = [chr(i) for i in range(97, 97+26)] #["a","b",...."c"]
dic = []
for i in range(len(s)):
    dic = sorted(dic)
    if k < bisect.bisect_left(dic,s[i]):
        continue
    for j in range(i+1, len(s)+1):
        s0 = s[i:j]
        if s0 not in dic:
            dic.append(s0)

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
ab = 'abcdefghijklmnopqrstuvwxyz'
N = len(s)
substrings = set()
for i in ab:
    for l in range(N):
        if s[l] != i:
            continue
        for r in range(l,N):
            substrings.add(s[l:r+1])
    if len(substrings) >= K:
        break

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

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s=input()
    K=int(input())
    words = set()
    ls = len(s)
    for i in range(ls):
        for j in range(i+1,ls+1):
            words.add(s[i:j])
    words = sorted(list(words))
    return words[K-1]

print(solve())

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
a=[]
for i in range(len(s)):
    for j in range(i+1, max(i+k, len(s)+1)):
        a.append(s[i:j])
b=list(set(a))
b.sort()
print(b[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(n-i): 
           A.append(s[i:j+i+1])

B = set(A)
C = []
for i in B:
    C.append(i)
C.sort()
print(C[K-1])

Submission status: Time Limit Exceeded

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

sub = set()

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

sub = sorted(sub)

print(sub[k])

Submission status: Time Limit Exceeded

Solution code:
A = list(input())
N = int(input())
L = []
for i in range(len(A)):
    tmp = A[i:]
    while tmp:
        L.append(''.join(tmp))
        tmp.pop()
L = list(set(L))
L.sort()
print(L[N-1])

Submission status: Time Limit Exceeded

Solution code:
A = input()
N = int(input())
L = []
for i in range(len(A)):
    for j in range(i+1, len(A)+1):
        L.append(A[i:j])
L = list(set(L))
L.sort()
print(L[N-1])

Submission status: Time Limit Exceeded

Solution code:
str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    if len(result) == int_k and str_s[f] > result[-1][0]:
        continue
    for t in range(f + 1, len(str_s) + 1):
        pattern.add(str_s[f:t])
        result = sorted(set(result + sorted(list(pattern))[:int_k]))[:int_k]

print(result[-1])

Submission status: Time Limit Exceeded

Solution code:
str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    if len(result) == int_k and str_s[f] > result[-1][0]:
        continue
    for t in range(f + 1, len(str_s) + 1):
        pattern.add(str_s[f:t])
        result = sorted(set(result + list(pattern)))[:int_k]

print(result[-1])

Submission status: Time Limit Exceeded

Solution code:
str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    for t in range(f + 1, len(str_s) + 1):
        pattern.add(str_s[f:t])
        result = sorted(set(result + list(pattern)))[:int_k]

print(result[-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    K = int(input())
    ranks = ["~"] * K
    for l in range(len(s)):
        for r in range(l+1, len(s)+1):
            target = s[l:r]
            if target in ranks:
                continue
            if target < ranks[K-1]:
                ranks[K-1] = target
            for i in range(K-1, 0, -1):
                if ranks[i] < ranks[i-1]:
                    tmp = ranks[i]
                    ranks[i] = ranks[i-1]
                    ranks[i-1] = tmp
    print(ranks[K-1])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#encoding utf-8

import copy
import numpy as np
import random


s = list(str(input()))
k = int(input())

substrings = []
for length in range(1,len(s)+1):
    for i in range(len(s)-length+1):
        word = "".join(s[i:i+length])
        # print(word)

        if word in substrings:
            pass
        else:
            substrings.append(str(word))

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

Submission status: Time Limit Exceeded

Solution code:
str_s = input()
int_k = int(input())

pattern = set()

for f in range(len(str_s) + 1):
    for t in range(f + 1, len(str_s) + 1):
        pattern.add(str_s[f:t])

print(sorted(list(pattern))[int_k - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s =input()
k = int(input())
#入力

length = len(s)
s_set  =[]
for i in range(length):
    for j in range(min(0,i+1-k),i+1):
        s_set.append(s[j:i+1])
s_set = set(s_set)
s_set = list(s_set)
s_set.sort()
#print(s_set)
if k == 1:
    k -= 1
print(s_set[k])

Submission status: Time Limit Exceeded

Solution code:
s =input()
k = int(input())
#入力

length = len(s)
s_set  =[]
for i in range(length):
    for j in range(i+1):
        s_set.append(s[j:i+1])
s_set = set(s_set)
s_set = list(s_set)
s_set.sort()
#print(s_set)

print(s_set[k-1])

Submission status: Time Limit Exceeded

Solution code:
s =input()
k = int(input())
#入力

length = len(s)
s_set  =[]
for i in range(length):
    for j in range(i+1):
        s_set.append(s[j:i+1])
s_set.sort()
#print(s_set)
i,j = 0,0
while i < k:
    if i > 0:
        if s_set[j] != s_set[j-1]:
            i += 1
    if i == 0:
        i += 1
    j += 1

print(s_set[j-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

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

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        for l in range(1, len(S)-j+1):
            cand.append(S[j:j+l])
    cand = list(set(cand))
    if len(cand) >= K:
        break
    i += 1
cand = sorted(cand)
print(cand[K-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

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

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        for l in range(1, len(S)-j+1):
            cand.append(S[j:j+l])
    cand = list(set(cand))
    i += 1
cand = sorted(cand)
print(cand[K-1])

Submission status: Time Limit Exceeded

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
s = input()
K = int(input())

dic = set()

for i in range(len(s)+1):
  for j in range(len(s)):
    if len(s[j:j+i])>0:
      dic.add(s[j:j+i])

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    K = int(input())
    alp = 'abcdefghijklmnopqrstuvwxyz'
    sk = []
    for a in alp:
        for i in range(len(s)):
            c = s[i]
            if a != c:
                continue
            for j in range(1, K + 1):
                ss = s[i:i + j]
                if ss not in sk:
                    sk.append(ss)
    print(sorted(sk)[K - 1])


main()

Submission status: Time Limit Exceeded

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

l=len(s)
chars=set()
sub1=['']*l


for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])

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

Submission status: Time Limit Exceeded

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

d = {}
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        s = S[i:j]
        if s in d.keys():
            pass
        else:
            d[s] = 0

d = sorted(d.keys())
print(d[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(len(S)-i):
        L.add((S[j:j+i+1]))
L = sorted(list(L))
print(L[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
substring=set()
for start in range(len(s)):
    for end in range(start+1,len(s)+1):
        substring.add(s[start:end])
print(sorted(list(substring))[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
if K > 50:
    print(0)
    exit()
sub = {s[i:j] for i in range(len(s)+1) for j in range(i+1,len(s)+1)}
sub = sorted(sub)
print(sub[K-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def ngram(text, n):
    return [text[i:i+n] for i in range(len(text) - n + 1)]

text = input()
k = int(input())
candidates = set()
for n in range(1,len(text) + 1):
    #_ = filter(lambda x:x[1] == 1,Counter(ngram(text,n)).items())
    candidates |= set(ngram(text,n))

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

Submission status: Time Limit Exceeded

Solution code:

import string

ch = string.ascii_lowercase

s = input()
K =  int(input())
pointer = 0
buf = []
boundary = [('a', i) for i in range(len(s)) if s[i] == 'a']
boundary.sort(key=lambda x: x[0])
while True:
  if len(buf) >= 5 or pointer >= len(ch):
    break
  tmp = len(boundary)
  if tmp > 0:
    for _ in range(1):
      element = boundary.pop(0)
      buf.append(element[0])
      buf = list(set(buf))
      if element[1] < len(s) - 1:
        next_element = (element[0] + s[element[1] + 1], element[1] + 1)
        boundary.append(next_element)
  if len(boundary) == 0:
    if pointer + 1 >= len(ch):
      break
    pointer += 1
    if s.find(ch[pointer]) != -1:
      boundary = [(ch[pointer], i) for i in range(len(s)) if s[i] == ch[pointer]]
  buf.sort()
  boundary.sort(key=lambda x: x[0])
  #print(boundary)
  #print(buf)
  
print(buf[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import string

ch = string.ascii_lowercase

s = input()
K =  int(input())
pointer = 0
buf = []
boundary = [('a', i) for i in range(len(s)) if s[i] == 'a']
boundary.sort(key=lambda x: x[0])
while True:
  if len(buf) >= 5 or pointer >= len(ch):
    break
  tmp = len(boundary)
  if tmp > 0:
    for _ in range(1):
      element = boundary.pop(0)
      buf.append(element[0])
      buf = list(set(buf))
      if element[1] < len(s) - 1:
        next_element = (element[0] + s[element[1] + 1], element[1] + 1)
        boundary.append(next_element)
  if len(boundary) == 0:
    if pointer + 1 >= len(ch):
      break
    pointer += 1
    boundary = [(ch[pointer], i) for i in range(len(s)) if s[i] == ch[pointer]]
  buf.sort()
  boundary.sort(key=lambda x: x[0])
  #print(boundary)
  #print(buf)
  
print(buf[K - 1])

Submission status: Time Limit Exceeded

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

def main(s, k):
    tmp = set()
    for i in range(1, len(s) + 1):
            tmp = tmp | n_gram(s, i)
    substr = sorted(list(tmp))
    print(substr[k-1])



if __name__ == '__main__':
    main(input(), int(input()))

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
k = int(input())
subs = set()
ds = {}

for i, c in enumerate(s):
  if c in ds:
    ds[c].append(i)
  else:
    ds[c] = [i]

for c, il in sorted(ds.items(), key=lambda x: x[0]):
  subs |= set([c])
  i = 2
  while il[0]+i <= len(s):
    for j in il:
      if j + i > len(s):
        break
      subs.add(s[j:j+i])
    i += 1
  if len(subs) >= k:
    break
print(list(sorted(subs))[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
substring = []

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

setsubstring = list(set(substring))
setsubstring.sort()

print(setsubstring[K-1])

Submission status: Time Limit Exceeded

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

A = []

k = 0

for i in range(len(s)+1):
    for j in range(len(s)+1 - i):
        A.append(s[j:j+i+1])
A = list(set(A))
A.sort()
A = A[1:]

    
print(A[n-1])

Submission status: Time Limit Exceeded

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

A = []

k = 0

for i in range(len(s)+1):
    for j in range(len(s)+1):
        A.append(s[j:j+i+1])
A = list(set(A))
A.sort()
A = A[1:]

    
print(A[n-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
k = int(input())
A = []

for i in range(len(S) + 1):
    for j in range(i + 1, len(S) + 1):
        A.append(S[i:j])
        
ans = sorted(list(set(A)))
print(ans[k - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
arr =[]
for i in range(len(s)):
    for j in range(i,len(s)):
        if s[i:j+1] != '' and s[i:j+1] not in arr:
            arr.append(s[i:j+1])
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep=" ",end="/")
    print()
   
arr = sorted(arr)
print(arr[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
K = int(input())
S = set()
anslength = 1
while len(s) >= anslength:
    for i in range(0,len(s)-anslength+1):
        S.add(s[i:i+anslength])
    anslength+=1
LS = list(S)
LS.sort()
print(LS[K-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
k = int(input())
n = len(S)
A = [[0] * n for _ in range(n)]

A[0][0] = S[0]
for i in range(1, n):
    A[0][i] = A[0][i - 1] + S[i]
    
for i in range(1, n):
    for j in range(0, n):
        A[i][j] = A[i - 1][j][1:]
        

flatA = []
for a in A:
    flatA.extend(a)

flatA.sort()
setA = set(flatA)

if '' in setA:
    setA.remove('')

finalA = list(setA)
finalA.sort()

print(finalA[k - 1])

Submission status: Time Limit Exceeded

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

c = []

for i in range(len(s)):
    for k in range(1,len(s)+1):
        c.append(s[i:i+k])

b = sorted(list(set(c)))

print(b[m-1])

Submission status: Time Limit Exceeded

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

dic = []

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

dic = (list)(set(dic))
dic.sort()

print(dic[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x=input()
k=int(input())
#print(x)

import itertools

text = x
l = len(text)
list1=[]
for s, e in itertools.combinations(range(l+1), 2):
  list1.append(text[s:e])
list1.sort()
list1=set(list1)
list1=list(list1)
list1.sort()
print(list1[k-1])

Submission status: Time Limit Exceeded

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

d = defaultdict(dict)

s_size = len(s)
for i in range(s_size):
    for j in range(s_size):
        t = (s[i:j+1])
        if (t != ''):
            d[t] = t
e = list(sorted(d))
print(e[k - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
N = len(S)

se = set()

for i in range(N):
    for j in range(N - i):
        s = S[j:j+i+1]
        se.add(s)
l = sorted(list(se))
ans = l[K - 1]
print(ans)

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+1, n+1):
        tmp = s[i:j]
        if len(tmp) > k:
            continue
        d.add(tmp)
a = sorted(list(d))
print(a[k-1])

Submission status: Time Limit Exceeded

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

n = len(s)

d = [set() for i in range(26)]

for i in range(n):
    for j in range(i+1, n+1):
        tmp = s[i:j]
        d[ord(tmp[0]) - 97].add(tmp)

for i in range(26):
    num = i
    if len(d[i]) >= k:
        break
    else:
        k -= len(d[i])

a = sorted(list(d[num]))
print(a[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+1, n+1):
        tmp = s[i:j]
        d.add(tmp)
a = sorted(list(d))
print(a[k-1])

Submission status: Time Limit Exceeded

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

arr = []

for i in range(len(s)):
    for j in range(i,len(s)):
        arr += [''.join(s[i:j+1])]

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
K = int(input())
table = []
for i, j in itertools.combinations(range(len(s) + 1), 2):
    if not s[i:j] in table:
        table = sorted(table + [s[i:j]])[0:5]
print(table[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
import itertools
s = input()
K = int(input())
table = []
for i, j in itertools.combinations(range(len(s) + 1), 2):
    index = bisect.bisect_left(table, s[i:j])
    if len(table) == index:
        table += [s[i:j]]
    elif table[index] != s[i:j]:
        bisect.insort_left(table, s[i:j])
print(table[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
K = int(input())
table = {}
for i, j in itertools.combinations(range(len(s) + 1), 2):
    table[s[i : j]] = 1
print(sorted(table)[K - 1])

Submission status: Time Limit Exceeded

Solution code:
def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s:
                indexes.append(i)
        for i in indexes:
            for j in range(1,iL -i+1):
                sDic.add(sS[i:i+j])
        aS = sorted(list(sDic))
        iLS = len(aS)
        if iC + iLS < iK:
            iC += iLS
            continue
        else:
            print(aS[iK -iC-1])
            exit()
解()

Submission status: Time Limit Exceeded

Solution code:
def 解():
    sS = input().rstrip()
    iK = int(input())
    iL = len(sS)
    iC = 0
    sAbc = "abcdefghijklmnopqrstuvwxyz"
    for s in sAbc:
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s:
                indexes.append(i)
        for i in indexes:
            for j in range(1,iL -i+1):
                sDic.add(sS[i:i+j])
        aS = sorted(list(sDic))
        iLS = len(aS)
        if iC + iLS < iK:
            iC += iLS
            continue
        else:
            print(aS[iK -iC-1])
            exit()
解()

Submission status: Time Limit Exceeded

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

if(len(s)==1):
    print(s)
else:
    substrings=[]
    for i in range(len(s)-1):
        for j in range(i,len(s)):
            if(i-j>K):
                continue
            str=s[i:(j+1)]
            substrings.append(str)

            substrings=list(set(substrings))
            substrings.sort()

            if(len(substrings)>K):
                substrings.pop()

    print(substrings[-1])

Submission status: Time Limit Exceeded

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

from heapq import *
def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(len(s), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))

Submission status: Time Limit Exceeded

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

known = set()
from heapq import *
hq = []
for i in range(len(s)):
    for j in range(len(s), i, -1):
        ss = s[i:j]
        if ss in known:
            break
        heappush(hq, ss)
        known.add(ss)
for i in range(K-1):
    heappop(hq)
print(heappop(hq))

Submission status: Time Limit Exceeded

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

known = set()
from heapq import *
hq = []
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        ss = s[i:j]
        if ss not in known:
            heappush(hq, ss)
            known.add(ss)
for i in range(K-1):
    heappop(hq)
print(heappop(hq))

Submission status: Time Limit Exceeded

Solution code:
#ABC097C
s=str(input())
K=int(input())
s_all=[]
s_ans=[]
for i in range(len(s)):
    for j in range(len(s)-i):
        s_all.append(s[j:j+i+1])
sorted_s_all=sorted(s_all)
for i in range(len(sorted_s_all)):
    if i==0:
        s_ans.append(sorted_s_all[i])
    elif sorted_s_all[i]!=sorted_s_all[i-1]:
        now=sorted_s_all[i]
        before=sorted_s_all[i-1]
        s_ans.append(sorted_s_all[i])
print(str(s_ans[K-1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
dict = []

for i in range(len(s)):
    for k in range(len(s)-i+1):
        if s[i:(k+i)] not in dict:
            dict.append(s[i:(k+i)])
dict.sort()
print(dict[K])