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:
import sys
input = sys.stdin.readline
S = set()
s = list(input().rstrip())
K = int(input())
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if "".join(s[i:j]) not in S:
            S.add("".join(s[i:j]))
S = list(S)
S.sort()
print("".join(S[K-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
S = []
s = list(input().rstrip())
K = int(input())
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in S:
            S.append(s[i:j])
S.sort()
print("".join(S[K-1]))

Submission status: Time Limit Exceeded

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

substrings = set()
n = len(s)
for i in range(n):
  for j in range(i+1,n+1):    
    substrings.add(s[i:j])
    
print(sorted(substrings)[k-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    k = int(input())
    l = set()
    ls = len(s)
    clist = sorted(list(set(list(s))))
    ladd = l.add
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        ladd(i)
        for j in range(len(x)):
            idx = x[j]
            xxx = s[idx]
            for t in range(idx+1,ls):
                xxx = xxx +s[t]
                ladd(xxx)
        if len(l) >= k:
            l = list(l)
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    k = int(input())
    l = set()
    ls = len(s)
    clist = sorted(list(set(list(s))))
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        l.add(i)
        for j in range(len(x)):
            idx = x[j]
            xxx = s[idx]
            for t in range(idx+1,ls):
                xxx = xxx +s[t]
                l.add(xxx)
        if len(l) >= k:
            l = list(l)
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    k = int(input())
    l = set()
    ls = len(s)
    clist = sorted(list(set(list(s))))
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        for j in range(len(x)):
            idx = x[j]
            l.add(s[idx])
            xxx = s[idx]
            for t in range(idx+1,ls):
                xxx = xxx +s[t]
                l.add(xxx)
        if len(l) >= k:
            l = list(l)
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    k = int(input())
    l = []
    ls = len(s)
    clist = sorted(list(set(list(s))))
    for i in clist:
        x = []
        for j in range(ls):
            if i == s[j]:
                x.append(j)
        for j in range(len(x)):
            idx = x[j]
            l.append(s[idx])
            for t in range(idx+1,ls):
                l.append(l[-1]+s[t])
        if len(set(l)) >= k:
            l = list(set(l))
            print(sorted(l)[k-1])
            break
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    if cnt == 6:
        continue
    while (i + cnt <= N):
        ans_list.append(S[i:i+cnt])
        cnt += 1
ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        if cnt == 6:
            continue
        while (i + cnt <= N):
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))

if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))


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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
N = len(S)
al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    while i + cnt <= N:
        ans_list.append(S[i:i+cnt])
        cnt += 1
ans_list = list(set(ans_list))
if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))
if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))
ans_list.sort()
##print(ans_list)
print(ans_list[K-1])

Submission status: Time Limit Exceeded

Solution code:
def swap(lst, a, b):
    tmp = lst[a]
    lst[a] = lst[b]
    lst[b] = tmp

S = input()
K = int(input())
N = len(S)
substrings = [""] * 10

al = [chr(ord('a') + i) for i in range(26)]
tmp_al = []
if K==1:
    for s in al:
        if s in S:
            print(s)
            exit()

for s in al:
    if s in S:
        if len(tmp_al) == 3:
            break
        if N - S.rfind(s) >= K:
            tmp_al.append(s)
            break
        else:
            if N - S.find(s) >= K:
                tmp_al.append(s)
                break
            else:
                tmp_al.append(s)
                continue

count = [[] for _ in range(len(tmp_al))]
for i in range(len(tmp_al)):
    for k in range(N):
        if S[k] == tmp_al[i]:
            count[i].append(k)
ans_list = []
ans_list.append(tmp_al[0])
for i in count[0]:
    cnt = 1
    while i + cnt <= N:
        ans_list.append(S[i:i+cnt])
        cnt += 1
ans_list = list(set(ans_list))
if len(ans_list) < K:
    for i in count[1]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))
if len(ans_list) < K:
    for i in count[2]:
        cnt = 1
        while i + cnt <= N:
            ans_list.append(S[i:i+cnt])
            cnt += 1
ans_list = list(set(ans_list))
ans_list.sort()
##print(ans_list)
print(ans_list[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)+1):
        if S[i:j] != "":
            if len(S[i:j]) < 6:
                A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)
        
print(A[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)+1):
        if S[i:j] != "" and len(S[i:j]) < 6:
            A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)

print(A[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)+1):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)

B =[]
for i in A:
    if len(i) < 6:
        B.append(i)
        
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:

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

result = []

for i in range(len_s):

  count = 0
  for j in range(i+1, len_s+1):
    if count > 5:
      break
    x = s[i:j]
    if x not in result:
      result.append(x)
    count += 1

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

li=set()

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

li=list(li)
li.sort()

print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,len(s)):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,len(s)):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
 
l = len(s)
 
sub = []
 
for i in range(l):
    for j in range(i+1):
        sub.append(s[j:i+1])
 
#print(sub)
subl = list(set(sub))

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

Submission status: Time Limit Exceeded

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

l = len(s)

sub = set()

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

#print(sub)
subl = list(sub)

subl.sort()

#print(subl)

print(subl[K-1])

Submission status: Time Limit Exceeded

Solution code:
# 問題文をよく読んで、制約をヒントに答えを導かないといけない問題

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

result = []

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

ans = []
for res in sorted(result):
  if not res in ans:
    ans.append(res)
    if len(ans) == K:
      print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(s: str, K: int):

    index_dict = {}
    for i in range(len(s)):
        if index_dict.get(s[i]) == None:
            index_dict[s[i]] = [i]
        else:
            index_dict[s[i]].append(i)

    value_list = sorted(set(list(s)))
    candidate = set()
    for string in value_list:
        index = index_dict[string]
        for i in index:
            tmp_s = ""
            for j in range(i,len(s)):
                tmp_s += s[j]
                candidate.add(tmp_s)
        if len(candidate) >= K:
            break
    candidate = list(candidate)
    candidate.sort()
    print(candidate[K-1])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=int(input())
substrings=[]
for i in range(len(s)+1):
  for j in range(i+1,len(s)+1):
    substrings.append(s[i:j])
substrings=list(set(substrings))
substrings.sort()

print(substrings[n-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)

def main():
    res = set()
    for i in range(n):
        for j in range(i, n):
            res.add(s[i:j+1])
    return sorted(res)[k-1]

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Time Limit Exceeded

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

chars = list(s)
for w in range(2, len(s)+1):
    chars += [s[i:i+w] for i in range(len(s))]
chars = list(set(chars))
chars.sort()
print(chars[k-1])

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    k = I()
    seen = set()
    min_k = []
    for i in range(len(s)):
        curS = s[i]
        for j in range(i, len(s)):
            if j > i:
                curS += s[j]
            if curS not in seen:
                seen.add(curS)
                if len(min_k) < k:
                    min_k.append(curS)
                else:
                    if curS < min_k[-1]:
                        min_k[-1] = curS
                min_k = sorted(min_k)
    print(min_k[-1])
main()

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    k = I()
    seen = set()
    h = []
    for i in range(len(s)):
        curS = s[i]
        if curS not in seen:
            heapq.heappush(h, curS)
            seen.add(curS)
        for j in range(i+1, len(s)):
            curS += s[j]
            if curS not in seen:
                heapq.heappush(h, curS)
                seen.add(curS)
    print(heapq.nsmallest(k, h)[-1])

main()

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    k = I()
    seen = set()
    for i in range(len(s)):
        curS = s[i]
        seen.add(curS)
        for j in range(i+1, len(s)):
            curS += s[j]
            seen.add(curS)
    print(sorted(list(seen))[k-1])

main()

Submission status: Time Limit Exceeded

Solution code:
def subString(st, n, m):
    st = set()
    for i in range(m):
        pp = ""
        for j in range(i, i + m):
            if (j >= m):
                break
            pp += string[j]
            st.add(pp)

    arr = list(st)
    arr.sort()
    print(arr[n - 1])


string = input()
n = int(input())
subString(string, n, len(string))

Submission status: Time Limit Exceeded

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

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 ** 18
MOD = 10 ** 9 + 7

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

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

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

Submission status: Time Limit Exceeded

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

n = len(s)
strs = set([])

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)
k = int(input())
substring_list = []
sappend = substring_list.append
for i in range(len_s):
    for j in range(i,len_s):
        sappend(s[i:j+1])
substring_set = set(substring_list)
print(sorted(substring_set)[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

List = []

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

set_List = set(List)
List = list(set_List)
List = sorted(List)
List.remove('')

ans = List[k-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

min_s = min(S)
B = [s for s in S]
B.sort()
# print(B)

cursol = 0
min_s = 'ATCODER'
cand = []
while len(cand) < K:
	# print(cursol)
	if min_s == B[cursol]:
		cursol += 1
		continue
	else:
		min_s = B[cursol]
	for i,s in enumerate(S):
		if s == min_s:
			for j in range(i+1, N+1):
				if not cand.count(S[i:j]): cand.append(S[i:j])
	cursol += 1

cand.sort()
# print(cand)

s = min(S)
cnt = 0
for c in cand:
	cnt += 1
	if cnt == K:
		print(c)
		break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
K=int(input())
S_list=list(S)
J=[]
for i in range(len(S)):
  for j in range(i+1,len(S)+1):
    J += [''.join(S[i:j])]
J=sorted(list(set(J)))
print(J[K-1])

Submission status: Time Limit Exceeded

Solution code:
#C
S = list(str(input()))
N = len(S)
K = int(input())

cand = []
for i in range(N):
    s = S[i]
    cand.append(s)
    for j in range(K):
        if i+j+1 < N:
            s+=S[i+j+1]
            cand.append(s)
            
shin = []
for c in cand:
    if c not in shin:
        shin.append(c)
        
shin.sort()
print(shin[K-1])

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
k = int(input())
S_sorted = "".join(sorted(list(set(S))))
#print(S_sorted[:5])
Ans = []
counter = 0
for counter in range(0, 10000000):
  Ans_temp = []
  moji = S_sorted[counter]
  Index = [i for i, chr in enumerate(S) if moji == chr]
  for index in Index:
    for j in range(0, len(S) + 1):
      if len(S[index : index+j]) != 0:
        Ans_temp.append("".join(S[index : index+j]))
#  print(Ans_temp)
  Ans = Ans + sorted(list(set(Ans_temp)))
  if len(Ans) >= k:
    break
print(Ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def main():
    s = input()
    K = int(input())
    substrings = []

    for i in range(len(s)):
        for ii in range(i,len(s)):
            if s[i:ii+1] not in substrings and len(s[i:ii+1]) <= K:
                substrings.append(s[i:ii+1])
    
    substrings.sort()
    print(substrings[K-1])
        

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def main():
    s = input()
    K = int(input())
    substrings = []

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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



rank = []
for i in range(len(s)):
    for j in range(i+1, max(i+6,len(s)+1)):
        ss = s[i:j]
        rank.append(ss)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
  s = input()
  k = int(input())
  alphabet = sorted(list(set(list(s))))

  list_sub = []
  num = 1
  while num <= k:
    temp = list(itertools.product(alphabet, repeat=num))
    temp = ["".join(com) for com in temp if "".join(com) in s]
    list_sub.extend(temp)
    num += 1
  list_sub.sort()
  print(list_sub[k-1])

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
k = int(input())
alphabet = sorted(list(set(list(s))))

list_sub = []
num = 1
while num <= k:
  temp = list(itertools.product(alphabet, repeat=num))
  temp = ["".join(com) for com in temp if "".join(com) in s]
  list_sub.extend(temp)
  num += 1
list_sub.sort()
print(list_sub[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    k=int(input())
    n=len(S)
    D=set()
    for j in range(n+1):
        for i in range(j):
            D.add(S[i:j])
    print(sorted(D)[k-1])
resolve()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

s = stdin.readline().rstrip()
n = int(stdin.readline().rstrip())
li = []

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import bisect
from itertools import accumulate
import numpy as np

s = stdin.readline().rstrip()
n = int(stdin.readline().rstrip())
li = []
for i in range(1,len(s)+1):
    for j in range(len(s)-i+1):
        li.append(s[j:j+i])
li = list(set(li))
li.sort()
print(li[n-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
 
sub_s = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in sub_s and len(s[i:j]) <= K:
            sub_s.append(s[i:j])
 
sub_s = sorted(sub_s)        
#print(sub_s)
print(sub_s[K-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

i = l
b = 1
cnddt = set()
while i:
    for j in range(l-i+1):
        cnddt.add(s[j:j+i])
    i -= 1
print(sorted(list(cnddt))[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
n = len(s)
A =[]
import bisect
for i in range(n):
    for j in range(1,K+1):
        sub = s[i:i+j]  
        if sub not in A:
            x = bisect.bisect_left(A,sub)
            A.insert(x,sub)

print(A[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
n = len(s)
A =[]
import bisect
for i in range(n):
    for j in range(i+1,n+1):
        sub = s[i:j]  
        if sub not in A:
            x = bisect.bisect_left(A,sub)
            A.insert(x,sub)
print(A[K-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
keys = sorted(list(set(list(S))))
c = 0
l = 1
ans = []
for key in keys:
  ans.append(key)
  while l <= len(S):
    for i, s in enumerate(S):
      if i + l >= len(S):
        l += 1
        break
      elif s[0] == key:
        ans.append(S[i:i+l+1])
    ans = sorted(list(set(ans)))
  else:
    l = 1
  if len(ans) >= K:
    print(ans[K-1])
    exit()

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
l = []
for c in range(1, len(s)+1):
  l += list(set([s[i:i+c] for i in range(len(s)-c+1)]))
print(sorted(l)[K-1])

Submission status: Time Limit Exceeded

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 13:42:36(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    s = sys.stdin.readline().rstrip()
    k = int(sys.stdin.readline().rstrip())
    n = len(s)

    substrings = []
    for i in range(1, n+1):
        for j in range(n-i+1):
            substring = s[j:j+i]
            substrings.append(substring)
            
    substrings = sorted(list(set(substrings)))
    print(substrings[k-1])


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
l=[]
for i in range(n):
    curr=''
    for j in range(i,min(i+10,n)):
        curr+=s[j]
        if curr not in l:
            l.append(curr)
l.sort()
#print(l)
print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
chars=[i for i in set(s)]
chars.sort() 
i=0 
l=[]
cnt=0 
while i<len(chars): 
    #temp=[]
    for ind in range(n): 
        if s[ind]==chars[i]:
            curr=''
            for j in range(ind,n):
                curr+=s[j]
                if curr not in l:
                    l.append(curr)
                    cnt+=1 
    if cnt>k:
        break 
    i+=1 
l.sort()
#print(l)
print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
n=len(s)
chars=[i for i in set(s)]
chars.sort() 
i=0 
l=[]
while i<len(chars): 
    for ind in range(n): 
        if s[ind]==chars[i]:
            curr=''
            for j in range(ind,n):
                curr+=s[j]
                if curr not in l:
                    l.append(curr)
    if len(l)>k:
        break 
    i+=1 
l.sort()
#print(l)
print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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


if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
K = INT()

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
k=int(input())
lst=list(s)
lst.sort()
ans=[]
for i in range(min(k,n)):
    a=lst[i]
    for j in range(n):
        if s[j]==a:
            for l in range(min(5,n-j)):
                ans.append(s[j:j+l+1])
ans.sort()
t=1
while t<len(ans):
    if ans[t]==ans[t-1]:
        ans.pop(t)
    else:
        t+=1
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
k=int(input())
lst=list(s)
lst.sort()
ans=[]
for i in range(min(k,n)):
    a=lst[i]
    for j in range(n):
        if s[j]==a:
            for l in range(min(5,n-j)):
                ans.append(s[j:j+l+1])
ans.sort()
t=1
while t<len(ans):
    if ans[t]==ans[t-1]:
        ans.pop(t)
    else:
        t+=1
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
#ABC097  C
s = input()
k = int(input())

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