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())
pool = set()
n = 0
slist = list(s)

for i in range(26):
  c = s.count(chr(97+ i))
  for j in range(c):
    index = slist.index(chr(97+ i))
    slist[index] = ""
    for k in range(len(s)- index):
      pool.add(s[index:index+ k+ 1])
  if(len(pool)>= K):
    newlist = list(pool)
    newlist.sort()
    print(newlist[K- 1])
    break

Submission status: Time Limit Exceeded

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

for i in range(len(s)):
  for j in range(i+ 1, len(s)+ 1):
    news = s[i:j]
    pool.add(news)
    
plis = list(pool)
plis.sort()

print(plis[K- 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

array = set()
n = len(s)

for i in range(n):
    for j in range(i + 1, n + 1):
        ss = s[i:j]
        array.add(ss)
        if len(array) > k:
            array = sorted(array)
            array.pop()
            array = set(array)

array = sorted(array)
print(array[k - 1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

s = list(input())
n = len(s)
k = int(input())

part = set()
for i in range(n):
    for j in range(i, n):
        part.add("".join(s[i:j+1]))

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

s = list(input())
n = len(s)
k = int(input())

part = defaultdict(set)
for i in range(n):
    for j in range(i, n):
        part[s[i]].add("".join(s[i:j+1]))

cnt = 0
for i in range(ord('a'), ord('z')+1):
    m = len(part[chr(i)])
    if cnt < k <= cnt + m:
        l = sorted(list(part[chr(i)]))
        print(l[k-cnt-1])
        exit()
    cnt += m

Submission status: Time Limit Exceeded

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

lis=[]
for i in range(len(s)):
    lis.append(s[i:len(s)])
    lis.sort()

l=[]
for i in lis[:5]:
    for j in range(5):
        l.append(i[:j+1])

l=set(l)
l=list(l)

l.sort()

print(l[k-1])

Submission status: Time Limit Exceeded

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

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


print(lis[k-1])

Submission status: Time Limit Exceeded

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

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

print(lis[k-1])

Submission status: Time Limit Exceeded

Solution code:
#4問目
s = input()
K = int(input())
result = []
for i in range(1, len(s) + 1):
    if(i == 1):
        for j in list(s):
            result.append(j)
    else:
        n = 0
        m = n + i
        while m <= len(s):
            result.append(s[n:m])
            n += 1
            m = n + i

result = set(result)
s = sorted(result)
print(s[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

S = input()
N = len(S)
K = INT()

se = set()
ans = []
for i in range(N):
    if len(ans) >= 5:
        if S[i] > ans[4]:
            continue
    for j in range(i+1, N+1):
        T = S[i:j]
        se.add(T)
    ans = sorted(se)
    ans = ans[:5]
ans = sorted(se)
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
N = len(s)
K = int(input())
Ind = {chr(i):[] for i in range(97,123)}
for i in range(N):
    Ind[s[i]].append(i)
C = {}
cnt = 0
flag = 0
for j in range(97,123):
    for ind in Ind[chr(j)]:
        for i in range(ind+1,N+1):
            if s[ind:i] not in C:
                C[s[ind:i]] = 1
                cnt += 1
    if cnt>=K:break
A = sorted(list(C.keys()))
print(A[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    K = int(input())
    substr = set()
    N = len(s)
    for i in range(N):
        for j in range(i+1, N + 1):
            substr |= {s[i:j]}
    sl = list(substr)
    sl.sort()
    print(sl[K-1])

    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

s = input()
n = len(s)
k = int(input())
ans = []
used = set()

for i in range(n):
    start = list(s[i])
    if s[i] not in used:
        ans.append(s[i])
        used.add(s[i])
    for j in range(i + 1, n):
        start.append(s[j])
        temp = "".join(start)
        if temp not in used:
            ans.append(temp)
            used.add(temp)
ans.sort()
print(ans[k - 1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
s_dic = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, c in enumerate(s):
    s_dic[c].append(i)
substrings = set()
for lc in "abcdefghijklmnopqrstuvwxyz":
    for i in s_dic[lc]:
        for j in range(i + 1, len(s) + 1):
            substrings.add(s[i:j])
    if len(substrings) >= K:
        break
print(sorted(list(substrings))[K - 1])

Submission status: Time Limit Exceeded

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]

for i in range(97, 123):
    moji = chr(i)
    if moji not in dic:
        continue
    kouho = dic[moji]
    strings = set([])
    for idx in kouho:
        e = idx+1
        while e <= n:
            strings.add(s[idx:e])
            e += 1
    if len(strings) >= k:
        strings = list(strings)
        strings.sort()
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
visited = [False] * len(s)
substrings = set()
for lc in "abcdefghijklmnopqrstuvwxyz":
    for i in range(len(s)):
        if visited[i] or s[i] != lc:
            continue
        visited[i] = True
        for j in range(i + 1, len(s) + 1):
            substrings.add(s[i:j])
    if len(substrings) >= K:
        break
print(sorted(list(substrings))[K - 1])

Submission status: Time Limit Exceeded

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

n = len(s)

import copy
l = copy.copy(s)
l = set(l)
l = list(l)
l.sort()
#print(l)

ans = set()
for i in range(len(l)):
    for j in range(n):
        if s[j] == l[i]:
            p = j
            temp = []
            while p < n:
                temp.append(s[p])
                ans.add(''.join(temp))
                p += 1
    if len(ans) >= k:
        break
#print(ans)
ans = list(ans)
ans.sort()
print(ans[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
substrings = set()
for lc in "abcdefghijklmnopqrstuvwxyz":
    if lc not in s:
        continue
    for i in range(len(s)):
        if s[i] != lc:
            continue
        for j in range(i + 1, len(s) + 1):
            substrings.add(s[i:j])
    if len(substrings) >= K:
        break
print(sorted(list(substrings))[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

S = input()
N = len(S)
K = INT()

se = set()
for i in range(N):
    for j in range(i+1, N+1):
        T = S[i:j]
        se.add(T)
ans = sorted(se)
print(ans[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    s = input()
    k = ni()

    substring = set()
    for i in range(97, 97+26):
        word = chr(i)

        for j in range(len(s)):
            if s[j] == word:
                tmp = s[j:]

                while len(tmp) > 0:
                    if tmp in substring:
                        break
                    else:
                        substring.add(tmp)
                        tmp = tmp[:-1]

        if len(substring) >= k:
            break

    ans = list(substring)
    ans.sort()

    print(ans[k-1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import deque
s = input()
n = int(input())

le = len(s)
seed = tuple(combinations(range(le + 1), 2))

res = deque()
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")

for i, j in seed:
    ch = s[i:j]
    if ch in res:
        continue
    elif ch < max(res):
        res.remove(max(res))
        res.append(ch)

ans = sorted(res)
print(ans[n - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
s = input()
n = int(input())

le = len(s)
seed = tuple(combinations(range(le + 1), 2))

res = set()
for i, j in seed:
    res.add(s[i:j])

ans = sorted(res)
print(ans[n - 1])

Submission status: Time Limit Exceeded

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

alp = "abcdefghijklmnopqrstuvwxyz"

target = K
candidate = set()
for a in alp:
    idx_list = []
    for i, _s in enumerate(s):
        if a == _s:
            idx_list.append(i)
            candidate.add(_s)

    if len(candidate) >= K:
        break

    ng_idx_list = []
    for j in range(1, len(s) + 1):
        if set(ng_idx_list) == set(idx_list):
            break
        for _idx in idx_list:
            if _idx in ng_idx_list:
                continue
            if _idx + j > len(s) - 1:
                ng_idx_list.append(_idx)
                continue
            _sub = s[_idx: _idx + 1 + j]
            candidate.add(_sub)

    if len(candidate) >= K:
        break

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(i,N):
    p=s[i:j+1]
    if len(p)<=K:
      tmp.add(p)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify,heappush,heappop

s=input()
K=int(input())
N=len(s)
tmp=[]
heapify(tmp)

for i in range(N):
  for j in range(i,N):
    if len(s[i:j+1])<=K:
      heappush(tmp,s[i:j+1])
  
i=0
zumi=set()
while True:
  s=heappop(tmp)
  if s not in zumi:
    zumi.add(s)
    i += 1
    if i==K:
      print(s)
      exit()



#lis=sorted(tmp)
#print(lis)
#print(lis[K-1])

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify,heappush,heappop

s=input()
K=int(input())
N=len(s)
tmp=[]
heapify(tmp)

for i in range(N):
  for j in range(i,N):
    heappush(tmp,s[i:j+1])
  
i=0
zumi=set()
while True:
  s=heappop(tmp)
  if s not in zumi:
    zumi.add(s)
    i += 1
    if i==K:
      print(s)
      exit()



#lis=sorted(tmp)
#print(lis)
#print(lis[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(i,N):
    tmp.add(s[i:j+1])
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])

Submission status: Time Limit Exceeded

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

N=len(s)
L=[]
for i in range(N):
    for j in range(i,N):
        L.append(s[i:j+1])
L=sorted(list(set(L)))
print(L[K-1])

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

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

min_index = [n for n, v in enumerate(s) if v == min(s)]

ans_list = [min(s)]
queue = []
i = 2

while len(ans_list) < K:
    # 候補の生成
    for m in min_index:
        for i in range(1, 6):
            if m + i < len(s):
                heappush(queue, s[m:m+i])
    while queue:
        c = heappop(queue)
        if c not in ans_list:
            ans_list.append(c)

print(ans_list[K-1])

Submission status: Time Limit Exceeded

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

    tmp = [[] for _ in range(26)]
    for i in range(N):
        tmp[ord(S[i]) - ord('a')].append(i)

    lst = []
    lst_append = lst.append
    s = set()
    s_add = s.add
    for num in tmp:
        for i in num:
            for j in range(i + 1, N + 1):
                if S[i:j] in s:
                    continue
                else:
                    s_add(S[i:j])
                    lst_append(S[i:j])
        if len(s) >= K:
            lst.sort()
            print (lst[K - 1])
            # print (lst)
            return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

def main():
    finish = set()
    S = len(s)
    for i in range(S):
        for j in range(i+1,S+1):
            finish.add(s[i:j])

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

s_substr = sorted(list(set(s_substr)))

print(s_substr[K - 1])

Submission status: Time Limit Exceeded

Solution code:


import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = list(input().strip())
K = int(input())
N = len(s)

if N == 1:
    print(s[0])
    exit()
sub = set()
for i in range(N):
    for j in range(N):
        sub.add(''.join(s[i:j+1]))

print(sorted(sub)[K])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

finish = set()
S = len(s)

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

finish = list(finish)
finish.sort()

print(finish[k-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = str(input())
    K = int(input())

    N = len(S)
    lst = []
    lst_append = lst.append
    s = set()
    s_add = s.add
    for i in range(N):
        for j in range(i + 1, N + 1):
            if S[i:j] in s:
                continue
            else:
                s_add(S[i:j])
                lst_append(S[i:j])

    lst.sort()
    print (lst[K - 1])
    # print (lst)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = str(input())
    K = int(input())

    N = len(S)
    lst = []
    lst_append = lst.append
    s = set()
    s_add = s.add
    for i in range(N):
        for j in range(i + 1, N + 1):
            if S[i:j] in s:
                continue
            else:
                s.add(S[i:j])
                lst_append(S[i:j])

    lst.sort()
    print (lst[K - 1])
    # print (lst)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = input().strip()
K = int(input())
N = len(s)

if N == 1:
    print(s)
    exit()
sub = set()
for i in range(N):
    for j in range(N):
        sub.add(s[i:j+1])

print(sorted(sub)[K])

Submission status: Time Limit Exceeded

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

N = len(S)
lst = []
lst_append = lst.append
s = set()
s_add = s.add
for i in range(N):
    for j in range(i + 1, N + 1):
        if S[i:j] in s:
            continue
        else:
            s.add(S[i:j])
            lst_append(S[i:j])

lst.sort()
print (lst[K - 1])
# print (lst)

Submission status: Time Limit Exceeded

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

N = len(S)
lst = []
s = set()
for i in range(N):
    for j in range(i + 1, N + 1):
        if S[i:j] in s:
            continue
        else:
            s.add(S[i:j])
            lst.append(S[i:j])

lst.sort()
print (lst[K - 1])
# print (lst)

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(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

mem = []

for i in range(0,len(s)):
    j_end = i+5 if i+5 > len(s)+1 else len(s)+1
    for j in range(i+1, j_end):
        ext_s = s[i:j]
        #print(s[i:j])
        if not ext_s in mem:
            mem.append(ext_s)
                    
print(sorted(mem)[n-1])

Submission status: Time Limit Exceeded

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

N=len(s)
ln=0
siki_sub=''
result={}

for i in range(N):
    for j in range(N-i):
        if ln<K:
            if s[i:i+j+1] not in result:
                result[s[i:i+j+1]]=1
                siki_sub=max(result)
                ln+=1
        else:
            if siki_sub>s[i:i+j+1] and s[i:i+j+1] not in result:
                del result[siki_sub]
                result[s[i:i+j+1]]=1
                siki_sub=max(result)

print(siki_sub)

Submission status: Time Limit Exceeded

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

mem = [chr(ord('z')+1)]*5

for i in range(0,len(s)):
    j_end = i+5 if i+5 > len(s)+1 else len(s)+1
    for j in range(i+1, j_end):
        ext_s = s[i:j]
        #print(s[i:j])
        if not ext_s in mem:
            for k in range(len(mem)):
                if mem[k] > ext_s: 
                    mem.insert(k, ext_s)
                    del mem[-1]
                    break
print(mem[n-1])

Submission status: Time Limit Exceeded

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

mem = [chr(ord('z')+1)]*5

for i in range(0,len(s)):
    for j in range(i+1, len(s)+1):
        ext_s = s[i:j]
        #print(s[i:j])
        if not ext_s in mem:
            for k in range(len(mem)):
                if mem[k] > ext_s: 
                    mem.insert(k, ext_s)
                    del mem[-1]
                    break
print(mem[n-1])

Submission status: Time Limit Exceeded

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

sub_list = []
for i in range(0, len(s)):
    for j in range(1, len(s)-i+1):
        sub_list.append(s[i:j+i])
print(sorted(list(set(sub_list)))[k-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


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

    N = len(s)
    sub = set()
    for i in range(N):
        t = s[i]
        sub.add(t)
        for j in range(i+1, N):
            t = "".join([t, s[j]])
            sub.add(t)
    sub = sorted(sub)
    ans = sub[K-1]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

st = set()
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        st.add(s[i:j])
print(sorted(list(st))[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(i,n):
        a.append(s[i:j+1])
b = sorted(set(a))
print(b[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    N = len(S)
    substring = set()
    for i in range(N):
        for j in range(i + 1, N + 1):
            substring.add(S[i:j])

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__=='__main__':
    k_sub()

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    s = input()
    K = II()
    subs = set()
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            subs.add(s[i:j])
    subs = sorted(list(subs))
    print(subs[K-1])
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():

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

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

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


resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():

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

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

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


resolve()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = Scanner.string()
    k = Scanner.int()
    N = len(S)
    M = set()
    for i in range(N):
        for j in range(i + 1, N + 1):
            M.add(S[i:j])
    M = sorted(list(M))
    print(M[k - 1])


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

thedict= {}

reslist = []

for i in range (1, len(s)+1):
    for pos in range(0, len(s) - i + 1):
        thedict[s[pos: pos + i]] = 1

# print(thedict)

reslist = sorted(thedict)

print(reslist[K-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
N = len(S)
A = set([s for s in S])
A = sorted(A)
C = set()
k = 0
while len(C)<K:
    for i in range(N):
        if S[i]==A[k]:
            for j in range(i,N):
                C.add(S[i:j+1])
    k+=1
C = sorted(C)
print(C[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
N = len(S)
C = []
for i in range(N):
    for j in range(i,N):
        C.append(S[i:j+1])
C.sort()
b = ""
k = 0
for c in C:
    if b!=c:
        k+=1
        b=c
    if k==K:
        print(b)
        break

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    K = Scanner.int()
    m = []
    N = len(S)
    for i in range(N):
        for j in range(i, N):
            m.append(S[i: j + 1])
    m = sorted(set(m))
    print(m[K-1])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
d=dict()
if len(s)==1:
  print(s)
else:
  for i in range(len(s)):
    a=s[i]
    if a not in d:
      d[a]=0
    for j in range(i+1,len(s)):
      a+=s[j]
      if a not in d:
        d[a]=0
  l=list(d)
  l.sort()
  print(l[k-1])