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())
seta = set()
for i in s:
    seta.add(i)
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        seta.add(s[i:j])
print(sorted(list(seta))[K-1])

Submission status: Time Limit Exceeded

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

D = {c:[] for c in "abcdefghijklmnopqrstuvwxyz"}
for i,c in enumerate(s):
    D[c].append(i)

ans = []
for I in D.values():
    t = []
    for l in range(1,len(s)+1):
        for i in I:
            if i+l < len(s)+1:
                t.append(s[i:i+l])
    ans += sorted(list(set(t)))
    if len(ans)>=K:
        break
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
N=int(input())
#s="atcoderandatcodeer"
#N=5
D={}

if(len(s)<=10):
    for i in range(1,len(s)+1):
        for j in range(len(s)):
            if D.get(s[j:j+i],None) == None:
                D[s[j:j+i]]=1
    D=sorted(D)
    print(D[N-1])
    exit()
else:
    t=sorted(s)
    i=0
    k=0
    for c in t:
        if(c!=k):
            i=0
            if(len(D)>=5):
                break
        k=c
        while(i<len(s)):
            if(s[i]==c):
                break
            i+=1
        j=i+1
        while(j<=len(s)):
            D[s[i:j]]=1
            j+=1
        i+=1
    
    D=sorted(D)
    print(D[N-1])
    exit()

Submission status: Time Limit Exceeded

Solution code:
s=input()
N=int(input())
D={}

for i in range(1,len(s)+1):
    for j in range(len(s)):
        if D.get(s[j:j+i],None) == None:
            D[s[j:j+i]]=1
D=sorted(D)
print(D[N-1])

Submission status: Time Limit Exceeded

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

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

print(S[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    m=int(input())
    tank=[]
    n=len(s)
    alpha=[chr(i) for i in range(97, 97+26)]
    for i in range(26):
        for j in range(n):
            if alpha[i]==s[j]:
                for k in range(n-j):
                    if s[j:j+k+1] not in tank:
                        tank.append(s[j:j+k+1])
        if len(tank)>=m:
            break
    tank.sort()
    print(tank[m-1])
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    k=int(input())
    tank=[]
    n=len(s)
    for length in range(1,n+1):
        for i in range(n-length+1):
            if s[i:i+length] not in tank:
                tank.append(s[i:i+length])
    tank.sort()
    print(tank[k-1])      
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
uselist=[]
count=0
checker=0

alphabet="abcdefghijklmnopqrstuvwxyz"
while count<=5 and checker<=26:
    for i in alphabet:
        for j in range(len(s)):
            if s[j]==i:
                uselist.append((j,i))
                count+=1
        checker+=1
anslist=[]
for some in uselist:
    for j in range(some[0],len(s)):
        anslist.append(s[some[0]:j+1:])
anslist=sorted(set(anslist))
print(anslist[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
uselist=[]
count=0
checker=0

alphabet="abcdefghijklmnopqrstuvwxyz"
while count<=5 and checker<=26:
    for i in alphabet:
        for j in range(len(s)):
            if s[j]==i:
                uselist.append((j,i))
                count+=1
        checker+=1
anslist=[]
for some in uselist:
    for j in range(some[0],len(s)):
        anslist.append(s[some[0]:j+1:])
anslist=sorted(set(anslist))
print(anslist[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = list()

for i in range(1,27):
    b = set()
    for j in range(len(s)):
        if(ord(s[j])==(i+96)):
            for m in range(j,len(s)):
                #print(s[j:m+1])
                b.add(s[j:m+1])
    a.append(list(b))

for i in range(26):
    a[i].sort()
    
cn = 0
for i in range(26):
    if(len(a[i])+cn>=k):
        for j in range(len(a[i])):
            cn += 1
            if(cn == k):
                print(a[i][j])
    else:
        cn += len(a[i])
        
#print(a)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
s += '0'
k = int(input())
result = []
if k > len(s):
    for i in range(1, k+1):
        for j in range(len(s)-i):
            result.append(s[j:j+i])
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)):
            result.append(s[i:j])
r = set(result)
out = list(r)
out.sort()

print(out[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
k = int(input())
s += '0'
result = []
for i in range(1, k+1):
    for j in range(len(s)-i):
        if all(s[j:j+i] != x for x in result):
            result.append(s[j:j+i])
result.sort()
print(result[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
k = int(input())
s += '0'
result = []
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        if all(s[i:j] != x for x in result):
            result.append(s[i:j])
result.sort()

print(result[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(n,0,-1):
    l.append(s[i:i+j])
print(sorted(set(l))[k-1])

Submission status: Time Limit Exceeded

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

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

# print(ans)
print(sorted(list(ans))[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      for k in range(len(s)):
        if j+k == len(s):
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
uni = set()
for i in range(1, len(s)+1):
    for j in range(len(s)):
        if len(s) - (j+i) < 0: break
        uni.add(s[j:j + i])

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
l = ['zzzzzzzzzzzzzzz','zzzzzzzzzzzzzzz','zzzzzzzzzzzzz','zzzzzzzzzzzz','zzzzzzzzz']
N = len(s)

for i in range(N):
    for j in range(N-i):
        tmp = s[j:j+i+1]
        if tmp not in l:
            l.append(tmp)
        l.sort()
        l = l[0:5]


l.sort()
#print(l)


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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
K = int(input())
l = []
N = len(s)

for i in range(N):
    for j in range(N-i):
        tmp = s[j:j+i+1]
        l.append(''.join(tmp))

l = list(set(l))
l.sort()
#print(l)


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

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = int(input())
c = {}
for i in range(len(a)):
    for j in range(i + 1, len(a) + 1):
        c[a[i:j]] = 1
d = sorted(c.keys())
e = 0
for k in d:
    e += 1
    if e == b:
        print(k)

Submission status: Time Limit Exceeded

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

lst = []

for start in range(len(S)):
    for end in range(start,len(S)):
        lst.append("".join(S[start:end+1]))
lst = list(set(lst))
lst.sort()

print(lst[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

s = input()
K = int(input())
subs=[]
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        subs.append(s[i:j])

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

Submission status: Time Limit Exceeded

Solution code:
# ARC097C - K-th Substring
def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, len(s) + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=input()
length=len(s)

K=int(input())
#print(s,K)

left=0
right=0
#ss=s[left:right]
#print(ss)

ss=deque()
for left in range(length+1):
    for right in range(left+1,length+1):
        ss.append(s[left:right])

myset=set(ss)
for i in range(K):
    tmp=min(myset)
    myset.remove(tmp)
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=input()
length=len(s)

K=int(input())
#print(s,K)

left=0
right=0
#ss=s[left:right]
#print(ss)

ss=deque()
for left in range(length+1):
    for right in range(left+1,length+1):
        ss.append(s[left:right])
#print(ss)
myset=set()
for i in ss:
    myset.add(i)
mylist=list(myset)
mylist.sort()
#print(mylist)
print(mylist[K-1])

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+1, len(s)+1):
        ans.add(s[i:j])
ans = sorted(ans)
print(ans[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
C = [chr(i) for i in range(ord('a'), ord('z') + 1)]
D = {c: [] for c in C}
for i, c in enumerate(S):
    D[c].append(i)
for k in C:
    v = D[k]
    substr = set()
    for i in v:
        for j in range(i + 1, len(S) + 1):
            substr.add(S[i:j])
    if len(substr) < K:
        K -= len(substr)
        continue
    substr = list(substr)
    substr.sort()
    print(substr[K - 1])
    break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
C = [chr(i) for i in range(ord('a'), ord('z') + 1)]
D = {c: [] for c in C}
for i, c in enumerate(S):
    D[c].append(i)
SUBSTR = []
for k in C:
    v = D[k]
    substr = set()
    for i in v:
        for j in range(i + 1, len(S) + 1):
            substr.add(S[i:j])
    substr = list(substr)
    substr.sort()
    SUBSTR.extend(substr)
print(SUBSTR[K - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
strs = [[] for _ in range(26)]
cnts = [0]*26

for ind,i in enumerate(s):
    if(sum(cnts[:ord(i)-97])>=5):
        continue
    for j in range(1,len(s)-ind+1):
        st = s[ind:ind+j]
        if(not st in strs[ord(i)-97]):
            strs[ord(i)-97].append(st)
            cnts[ord(i)-97]+=1


cnt = 0
num = 0
while(cnt<K):
    cnt += len(strs[num])
    num += 1
num -= 1
cnt -= len(strs[num])
strs[num].sort()
print(strs[num][K-cnt-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
strs = [[] for _ in range(26)]

for ind,i in enumerate(s):
    for j in range(1,len(s)-ind+1):
        st = s[ind:ind+j]
        if(not st in strs[ord(i)-97]):
            strs[ord(i)-97].append(st)


cnt = 0
num = 0
while(cnt<K):
    cnt += len(strs[num])
    num += 1
num -= 1
cnt -= len(strs[num])
strs[num].sort()
print(strs[num][K-cnt-1])

Submission status: Time Limit Exceeded

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

a = []
for l in range(1, len(S) + 1):
	for i in range(len(S) - l + 1):
		a += [S[i:i + l]]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
N = len(s)
subs = set()
for i in range(1, N):
    l = s[:i]
    r = s[i:]
    while not l == '':
        subs.add(l)
        l = l[1:]
    while not r == '':
        subs.add(r)
        r = r[:-1]
subs.add(s)
subs = sorted(subs)
print(subs[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
K = int(input())
lt = []
for start in range(len(s)):
	for end in range(start + 1, len(s) + 1):
		lt.append(s[start:end])
lt = list(set(lt))
lt.sort()
print(lt[K-1])

Submission status: Time Limit Exceeded

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

S = list(set(s for s in (S[i:j] for i in range(len(S)) for j in range(i + 1, len(S) + 1)) if len(s) <= K))
S.sort()
print(S[K - 1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
l = len(s)
substrings = [None]*(l*(l+1)//2)
ind = 0
for i in range(1,l+1):
    for j in range(l-i+1):
        substrings[ind] = s[j:j+i]
        ind += 1
substrings = sorted(set(substrings))
print(substrings[k-1])

Submission status: Time Limit Exceeded

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

sub = []

for i in range(l):
    for j in range(i+1,l+1):
        if (not s[i:j] in sub) and (len(s[i:j]) <= n):
            sub.append(s[i:j])
        if len(s[i:j]) > n:
            break

sub = sorted(sub)

print(sub[n-1])

Submission status: Time Limit Exceeded

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

sub = []

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

sub = sorted(sub)

print(sub[n-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = []
charGram = [[''.join(s[i:i + n]) for i in range(len(s) + 1 - n)] for n in range(1,len(s) + 1)]

for i in range(len(charGram)):
    res += charGram[i]

res = sorted(set(res))
print(res[K - 1])

Submission status: Time Limit Exceeded

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

res = []
for n in range(1,len(s) + 1):
    charGram = [''.join(s[i:i + n]) for i in range(len(s) + 1 - n)]
    res += charGram

res = sorted(set(res))
print(res[K - 1])

Submission status: Time Limit Exceeded

Solution code:
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
S = []
ss = ''
w = []
for i in range(len(s)):
    if s[i] in w:
        pass
    else:
        S.append(s[i])
        w.append(s[i])
    for j in range(i+1, K+i+1):
        ss = ''
        if j >= len(s):
            continue
        ss = s[i] + s[i+1:j+1]
        if ss in w:
            continue
        S.append(ss)
        w.append(ss)

S.sort()

print(S[K-1])

Submission status: Time Limit Exceeded

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

list_rank = []
for i in range(len(s)):
    if i < len(s) - K + 1:
        for j in range(K+1):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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

Submission status: Time Limit Exceeded

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

alp = 'abcdefghijklmnopqrstuvwxyz'
loc = []
ini = []
flg = 0
rem = 0
for i in alp:
    flg_2 = 0
    idx = 0
    for j in s:
        if j == i:
            if flg_2 == 0:
                flg_2 = 1
                ini.append(i)
                loc.append((idx, i))
                rem += len(s[idx:])
                if rem >= K:
                    flg = 1
            else:
                loc.append((idx, i))
        idx += 1
    if flg == 1:
        break

len_s = len(s)
list_rank = []
for i in ini:
    tmp = [j for j in loc if j[1] == i]
    for j in tmp:
        idx = j[0]
        for k in range(len_s-idx):
            if len(s[idx:idx+k+1]) <= K:
                if s[idx:idx+k+1] not in list_rank:
                    list_rank.append(s[idx:idx+k+1])
    if len(list_rank) >= K:
        break

list_rank.sort()

print(list_rank[K-1])

Submission status: Time Limit Exceeded

Solution code:
import re
s=input()
K=int(input())
chars=[chr(i) for i in range(97,97+26)]
subs=[]
for char in chars:
  length=0
  while True:
    r = re.compile('{0}\w{{{1}}}'.format(char,length))
    l = r.findall(s)
    if l==[]:
      break
    else:
      subs = sorted(subs+list(set(l)))
      length+=1
  if len(subs)>=K:
    break
print(subs[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=s[:]
K=int(input())
subs=[t]
while len(t)>0:
  subs.append(t)
  if len(t)>1:
    for j in range(1,len(t)):
      subs.append(t[:j])
      subs.append(t[j:])
  t = t[1:-1]
print(sorted(list(set(subs)))[K-1])

Submission status: Time Limit Exceeded

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

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

slist = sorted(slist)

if K == 1:
    print(slist[0])
else:
    c = 1
    ss = slist[0]
    for i in range(1, N ** 2):
        if ss != slist[i]:
            c += 1

        if K == c:
            print(slist[i])
            break

        ss = slist[i]

Submission status: Time Limit Exceeded

Solution code:

import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]
    input_raw = read_func().strip().split()
    [K] = [int(input_raw[0])]
##    if len(S) >= K:
##        min_s = "zzzzzzz"
##        for i in range(len(S) - K):
##            if S[i : i + K]< min_s:
##                min_s = S[i : i + K]
##        print min_s
##        return
##    else:
    sub_list = set([])
    for i in range(len(S)):
        for j in range(i + 1, len(S) + 1):
            sub_list.add(S[i:j])

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

keys = []
for start in range(len(s)):
  for end in range(start+1, len(s)+1):
    key = s[start:end]
    if key in keys:
      continue
    if len(keys) < 5:
      keys.append(key)
      keys.sort()
    elif keys[-1] > key:
      keys.append(key)
      keys.sort()
      keys = keys[:-1]
print(keys[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
l=len(s)
d=[[s[i],l-i] for i in range(len(s))]
d=sorted(d)
h=dict()
ans=0
ca=d[0][0]   

for i in d:
    if(i[0]!=i[0][0]):
        break
    for j in range(1,max(i[1]+1,6)):
        if(s[l-i[1]:l-i[1]+j] not in h):
            ans+=1
            h.update({s[l-i[1]:l-i[1]+j]:1})
        else:
            pass


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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,len(s)+1):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) > ord(note):
        continue
    for j in range(i+1,len(s)+1):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


def li():
	return list(map(int , input().split()))


def num():
	return map(int , input().split())


def nu():
	return int(input())


def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x


s=input()
k=nu()
n=len(s)
z=set()
for i in range(n):
	pp=""
	for j in range(i,n):
		pp+=s[j]
		z.add(pp)
fin=list(z)
fin.sort()
print(fin[k-1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

q = []

for i in range(len(S)):
    for j in range(i, len(S) + 1):
        heapq.heappush(q, S[i:j])

last = ''
while K > 0:
    s = heapq.heappop(q)
    if s != last:
        K -= 1
        last = s

print(last)

Submission status: Time Limit Exceeded

Solution code:
list_alp = list("abcdefghijklmnopqrstuvwxyz")
s = str(input())
k = int(input())
s_sort = sorted(s)
len_s = len(s)
dict_s = {}
trigger = []
count = 0
trigger = sorted(s)[0:5]
for i in range(len_s):
    if not s[i] in trigger[0]:
        continue
    else:
        for j in range(i,min(i+5,len_s)):
            try:
                dict_s[ s[i:j+1] ] += 1
            except KeyError:
                dict_s[ s[i:j+1] ] = 1

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[1]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[2]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[3]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[4]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

list_ans = []
for key in dict_s.keys():
    list_ans.append(key)
list_ans.sort()
print(list_ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
def min5(numbers):
    list_n = list(numbers)
    min1 = "zzzzzz"
    min2 = "zzzzzzz"
    min3 = "zzzzzzzz"
    min4 = "zzzzzzzzz"
    min5 = "zzzzzzzzzz"
    for num in list_n:
        if num < min1:
            min1,min2,min3,min4,min5 = num,min1,min2,min3,min4
        elif min1 <= num < min2:
            min2,min3,min4,min5 = num,min2,min3,min4
        elif min2 <= num < min3:
            min3,min4,min5 = num, min3,min4
        elif min3 <= num < min4:
            min4,min5 = num,min4
        elif min4 <= num < min5:
            min5 = num
        else:
            pass
    return min1,min2,min3,min4,min5

list_alp = list("abcdefghijklmnopqrstuvwxyz")
s = str(input())
k = int(input())
len_s = len(s)
dict_s = {}
trigger = []
count = 0
trigger = min5(s)
for i in range(len_s):
    if not s[i] in trigger[0]:
        continue
    else:
        for j in range(i,min(i+5,len_s)):
            try:
                dict_s[ s[i:j+1] ] += 1
            except KeyError:
                dict_s[ s[i:j+1] ] = 1
if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[1]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[2]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[3]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

if len(dict_s) < 5:
    try:
        for i in range(len_s):
            if not s[i] in trigger[4]:
                continue
            else:
                for j in range(i,max(i+5,len_s)):
                    try:
                        dict_s[ s[i:j+1] ] += 1
                    except KeyError:
                        dict_s[ s[i:j+1] ] = 1
    except IndexError:
        pass

list_ans = []
for key in dict_s.keys():
    list_ans.append(key)
print(min5(list_ans)[k-1])