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:
#!/usr/bin/env python3
import sys


def solve(s: str, K: int):
    n = len(s)
    ss = {
        s[i:j]
        for i in range(n)
        for j in range(i + 1, n + 1)
    }
    print(sorted(ss)[K - 1])


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

Submission status: Time Limit Exceeded

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

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

    check = set()

    for left in range(0, len(s)):
        for right in range(left+1, len(s)+1):
            check.add(s[left:right])
    
    print(sorted(list(check))[k-1])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import string
letters=string.ascii_lowercase

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

ans = []
for i in range(26):
    for j in range(len(s)):
        if letters[i] == s[j]:
            for k in range(1, len(s)-j+1):
                if s[j:j+k] not in ans:
                    ans.append(s[j:j+k])
    ans = sorted(set(ans))
    if len(ans) >= K:
        break

print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
import string
letters=string.ascii_lowercase

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

ans = []
for i in range(26):
    for j in range(len(s)):
        if letters[i] == s[j]:
            for k in range(1, len(s)-j+1):
                ans.append(s[j:j+k])
    ans = sorted(set(ans))
    if len(ans) >= K:
        break

print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    k = int(input())
    NA = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            NA.append(s[i:j+1])

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



if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
# AtCoder
import itertools
s = input()
K = int(input())

substrings = set()
for left in range(len(s)):
    for right in range(1, len(s)+1):
        if not s[left:right]:
            continue

        substrings.add(s[left:right])
print(sorted(list(substrings))[K-1])

Submission status: Time Limit Exceeded

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

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

print(array[k])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    kinds = sorted(list(set(s)))
    skips = []
    if len(kinds) > K:
        skips = kinds[K+1:]
    for j in range(len(s)): # window starts at
        if s[j] in skips:
            continue
        for i in range(1, len(s)+1): # window size
            subs = s[j:j+i]
            mem.append(subs)
    mem = sorted(list(set(mem)))
    # print(mem)
    print(mem[K-1])


if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    kinds = list(set(s))
    skips = []
    if len(kinds) > K:
        skips = kinds[K+1:]
    for j in range(len(s)): # window starts at
        if s[j] in skips:
            continue
        for i in range(1, len(s)+1): # window size
            subs = s[j:j+i]
            if subs not in mem:
                mem.append(subs)
    mem.sort()
    # print(mem)
    print(mem[K-1])


if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    for i in range(1, len(s)+1): # window size
        for j in range(len(s)): # window starts at
            subs = s[j:j+i]
            if subs not in mem:
                mem.append(subs)
    mem.sort()
    # print(mem)
    print(mem[K-1])


if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
k = inp()
n = len(s)
t = []
for i in s:
    t.append(ord(i) - ord('a'))
se = set()
for i in range(26):
    for j in range(n):
        if t[j] == i:
            for l in range(j,n):
                tmp = s[j:l+1]
                if tmp == '':
                    continue
                se.add(tmp)
    if len(se) >= k:
        break
res = sorted(list(se))
print(res[k-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
se = set()
k = inp()
for i in range(n):
    for j in range(n):
        if s[i:j+1] == '':
            continue
        se.add(s[i:j+1])
res = sorted(list(se))
# print(res)
print(res[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=str(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])
#print(ans)
ans=sorted(list(set(ans)))
#print(ans)
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
k=int(input())
alp=[chr(i) for i in range(97, 97+26)]
ans=set()
for i in range(26):
    for j in range(l):
        if s[j]==alp[i]:
            for m in range(j,l):
                ans.add(s[j:m+1])
    if len(ans)>=k:
        break
print(sorted(list(ans))[k-1])

Submission status: Time Limit Exceeded

Solution code:
list_S = list(input())
k = int(input())
set_ANS = set()
list_Alph = list(set(list_S))
list_Alph.sort()
cnt = 0

for c in list_Alph:
    q = [i for i, x in enumerate(list_S) if x == c]
    for j in range(1, len(list_S)+1):
        for i in q:
            if i + j <= len(list_S):
                l = "".join(list_S[i:i+j])
                if l not in set_ANS:
                    set_ANS.add(l)
                    cnt += 1
    if cnt >= k:
        list_ANS = list(set_ANS)
        list_ANS.sort()
        print(list_ANS[k-1])
        exit()

Submission status: Time Limit Exceeded

Solution code:
list_S = list(input())
k = int(input())
set_ANS = set(list_S)

for i in range(len(list_S)-1):
    c = list_S[i]
    for j in range(i+1, len(list_S)):
        c += list_S[j]
        set_ANS.add(c)

list_ANS = list(set_ANS)
list_ANS.sort()

print(list_ANS[k-1])

Submission status: Time Limit Exceeded

Solution code:
list_S = list(input())
k = int(input())
set_ANS = set()

for i in range(len(list_S)):
    for j in range(i, len(list_S)+1):
        set_ANS.add(''.join(list_S[i:j]))

list_ANS = list(set_ANS)
list_ANS.sort()

print(list_ANS[k])

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    k = int(input())
    ss = set()
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            ss |= {s[i:j]}
    print(sorted(ss)[k-1])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S=input()
K=int(input())
l = []
for alpha in [chr(i) for i in range(97, 97+26)]:
  indexs = [k for k, v in enumerate(list(S)) if v == alpha]
  for index in indexs:
    for j in range(index,len(S)+1):
      sub_s = S[index:j]
      l.append(sub_s)
  l = sorted(list(set(l)))
  if '' in l:
    l.remove('')
  if len(l) >= K:
    break
print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
from operator import mul
from functools import reduce
import bisect

#n,m=map(int,input().split())

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

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
from operator import mul
from functools import reduce
import bisect

#n,m=map(int,input().split())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
import heapq

def main():
    s = input().strip()
    n = len(s)
    stq = set()
    k = int(input().strip())
    for i in range(n):
        for j in range(i+1, max(i+1+k+1, n+1)):
            stq.add(s[i:j]) 
    stq = list(stq)
    heapq.heapify(stq)
    for i in range(k):
        ans = heapq.heappop(stq)
        if i == k-1:
            print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
import heapq

def main():
    s = input().strip()
    n = len(s)
    stq = set()
    k = int(input().strip())
    for i in range(n):
        for j in range(i+1, n+1):
            stq.add(s[i:j])
    stq = list(stq)
    heapq.heapify(stq)
    for i in range(k):
        ans = heapq.heappop(stq)
        if i == k-1:
            print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    n = len(s)
    stset = set()
    k = int(input().strip())
    for i in range(n):
        for j in range(i+1, n+1):
            stset.add(s[i:j])
    print(sorted(stset)[k-1])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
ans=["zzzzzz"]*k
for i in range(len(s)):
  for j in range(i,len(s)):
    A=s[i:j+1]
    if A>ans[k-1]:
      continue
    if A in ans:
      continue
    for ii in range(k):
      if A<ans[ii]:
        break
    for jj in range(k-1,ii,-1):
      ans[jj]=ans[jj-1]
    ans[ii]=A
print(ans[-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
strings = []
for start in range(len(s)):
    for end in range(start+1, len(s)+1):
        moji = s[start:end]
        strings.append(moji)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

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

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(sub):
    global N, K
    nsub = {}
    for i in list(sub.keys()):
        ni = i + 1
        if ni < N:
            s = sub[i] + S[ni]
            nsub[ni] = s
            A.add(s)
    if len(nsub) > 0:
        dfs(nsub)


S = list(input())
N = len(S)
K = int(input())
alpha = [chr(ord('a') + i) for i in range(26)]

A = set()
for c in alpha:
    if len(A) < K:
        sub = {}
        for i, s in enumerate(S):
            if c == s:
                A.add(s)
                sub[i] = c
        dfs(sub)

A = list(A)
A.sort()
print(A[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])

for i, s in enumerate(sorted(ss), start=1):
    if i == k:
        print(s)
        break

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
answers=[]
S=[a for a in s]
N=len(S)
for a in range(N):
    number = 0
    while a + number <= N :
        z = S[a:a + number]
        answers.append(z)
        number += 1
kotae = []
for a in answers:
    if a in kotae:
        pass
    else:
        kotae.append(a)
kotae = sorted(kotae)
answer=kotae[K]
moji=''
for a in answer:
    moji+=a
print(moji)

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
answers=[]
S=[a for a in s]
N=len(S)
for a in range(N):
    number = 0
    while a + number <= N and number<=K:
        z = S[a:a + number]
        answers.append(z)
        number += 1
kotae = []
for a in answers:
    if a in kotae:
        pass
    else:
        kotae.append(a)
kotae = sorted(kotae)
answer=kotae[K]
moji=''
for a in answer:
    moji+=a
print(moji)

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
answers=[]
S=[a for a in s]
N=len(S)
for a in range(N):
    number = 0
    while a + number <= N and number<=K:
        z = S[a:a + number]
        moji = ''
        for y in z:
            moji += y
            answers.append(moji)
        number += 1
kotae = []
for a in answers:
    if a in kotae:
        pass
    else:
        kotae.append(a)
kotae = sorted(kotae)
print(kotae[K - 1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
answers=[]
S=[a for a in s]
N=len(S)
for a in range(N):
    number = 0
    while a + number <= N and number<=5:
        z = S[a:a + number]
        moji = ''
        for y in z:
            moji += y
            answers.append(moji)
        number += 1
kotae = []
for a in answers:
    if a in kotae:
        pass
    else:
        kotae.append(a)
kotae = sorted(kotae)
print(kotae[K - 1])

Submission status: Time Limit Exceeded

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

word=[]
for i in range(26):
    t=chr(97+i)
    for j,k in enumerate(s):
        if t==k:
            add=j
            while add<length:
                w="".join(s[j:add+1])
                if w not in word:
                    word.append(w)
                add +=1
    if len(word)>K:break

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

Submission status: Time Limit Exceeded

Solution code:
#097_C
s = input()
k = int(input())
ans = set()

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000000)

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


def calculate(str, k):
    s = sorted(list(set(str)))
    criteron = s[:k]
    objs = {}
    for index, s in enumerate(str):
        if s in criteron:
            for i in range(index+1,len(str)+1):
                objs.__setitem__(str[index:i],True)

    arr = sorted(objs.keys())

    print(arr[k-1])

calculate(s, K)

Submission status: Time Limit Exceeded

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

def calculate(s,k):
    length = len(s)

    objs = {}
    for i in range(1,length+1):
        for j in range(0,length +1 - i):
            objs.__setitem__(s[j:j+i],True)

    s = sorted(objs.keys())

    print(s[k-1])


calculate(s,K)

Submission status: Time Limit Exceeded

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

l = []
for i in range(len(s)):
    for y in range(i+1,len(s)+1):
        #print(''.join(s[i:y]))
        if not ''.join(s[i:y]) in l:
            l.append(''.join(s[i:y]))

l.sort()
if not l:
    print(s[0])
else:
    print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()

n=int(input())

ans = []

for i in range(len(s)+1):
    for j in range(i):
        if s[j:i] not in ans:
            ans.append(s[j:i])
ans.sort()
print(ans[n-1])

Submission status: Time Limit Exceeded

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

#t=[]
#for kk in range(k):
#    t.append(s)

t=["zzzzz"]*k

for i in range(len(s)):
    for j in range(i,len(s)):
        sij=s[i:j+1]
        for kk in range(k):
            if t[kk]==sij:
                break
        if t[kk]>sij:
            t[kk]=sij
            t.sort()
        
print(t[k-1])  
#print(t)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

t=[]
d=dict()
di=0
for i in range(len(s)):
    for j in range(i,len(s)):
        if s[i:j+1] not in d:
            di=di+0
            d[s[i:j+1]]=di
            
d_sorted = sorted(d.items(), key=lambda x:x[0])
            
astr=d_sorted[k-1][0]
        
print(astr)

Submission status: Time Limit Exceeded

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

t=[]
for i in range(len(s)):
    for j in range(i,len(s)):
        t.append(s[i:j+1])
        
t.sort()
t1=t[0]
t2=[t[0]]
kk=0
for i in range(1,len(t)):
    if t1!=t[i]:
        t2.append(t[i])
        t1=t[i]
        kk=kk+1
        if kk==k-1:
            break
        
print(t2[k-1])

Submission status: Time Limit Exceeded

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

t=[]
for i in range(len(s)):
    for j in range(i,len(s)):
        t.append(s[i:j+1])
        
t.sort()
t1=t[0]
t2=[t[0]]
for i in range(1,len(t)):
    if t1!=t[i]:
        t2.append(t[i])
        t1=t[i]
        
print(t2[k-1])

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc097/tasks/arc097_a
# まずは愚直に実装してみる

S = input()
K = int(input())
candi = []
for s in range(len(S)):
    for e in range(s + 1, len(S) + 1):
        candi.append(S[s:e])
candi = list(set(candi))
candi.sort()
print(candi[K - 1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
target = []
def func(split_range):
    for i in range(0,len(S)-split_range+1):
        #print(S[0:0])
        #print(S[0:1])
        #print(S[i:i+split_range])
        #print(S[i:i+split_range])
        target.append(S[i:i+split_range])

for i in range(1,len(S)+1):
    #print(i)
    func(i)
#print(target)
print(sorted(set(target))[K-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	s = input()
	s = s[:-1]
	k = inputInt()

	stringss = []
	for i in range(len(s)):
		for j in range(i+1,len(s)+1):
			tmp = s[i:j]
			if tmp in stringss:
				pass
			else:
				stringss.append(tmp)

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

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  s=input()
  k=int(input())
  substr=[]
  l=len(s)
  
  for i in range(l):
    substring=''
    for j in range(i,l):
      substring+=s[j]
      substr.append(substring)
  substr.sort()
  #print(substr)
  cnt,i=1,0
  ans=substr[0]
  while cnt<k :
    if substr[i]!=substr[i+1]:
      cnt+=1
      if cnt==k:
        ans=substr[i+1]
        break
    i+=1
  print(ans)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  s=input()
  k=int(input())
  substr=set()
  l=len(s)
  for i in range(l):
    substring=''
    for j in range(i,l):
      substring+=s[j]
      substr.add(substring)
  substr=list(substr)
  substr.sort()
  print(substr[k-1])
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
w=input()
n=int(input())
import itertools as it
s={w}
for i,j in it.product(range(len(w)),repeat=2):
  if i<=j: s.add(w[i:j+1])
print(sorted(s)[n-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
k = int(input())
cnt = 0
itl = sorted(list(set(S)))
ans = set([])
for w in itl:
    for i, s in enumerate(S):
        if s != w:
            continue
        else:
            for j in range(i+1, n+1):
                ans.add(S[i:j])
    cnt += len(ans)
    if cnt >= k:
        break
    else:
        ans.clear()

ans = list(ans)
ans.sort()
index = k - 1 - (cnt - len(ans))
print(ans[index])

Submission status: Time Limit Exceeded

Solution code:
S=input()
K=int(input())
K-=1
D={}
for s in range(len(S)):
    for e in range(s,len(S)):
        D[S[s:e+1]]=1
        #print(S[s:e+1])
D=list(D)
D.sort()
print(D[K])

Submission status: Time Limit Exceeded

Solution code:
cha = input()
num = int(input())
list = []
for i in range(len(cha)):
  for j in range(num):
    if list.count(cha[i:i+j+1])==0:
      list.append(cha[i:i+j+1])
list.sort()

print(list[num-1])

Submission status: Time Limit Exceeded

Solution code:
cha = input()
num = int(input())
list = []
for i in range(len(cha)):
  for j in range(len(cha)-i):
    if list.count(cha[i:i+j+1])==0:
      list.append(cha[i:i+j+1])
list.sort()
print(list[num-1])

Submission status: Time Limit Exceeded

Solution code:
s=list(map(str,input()))
A=int(input())
V=[]
S=[]
ct=0
for i in range(1,len(s)+1):
  for j in range((len(s)-(i-1))):
    V.append("".join(s[j:j+i]))
S=sorted(set(V))
#print(S)
print(S[A-1])

Submission status: Time Limit Exceeded

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

anslist=[]
str=""

if len(s)==1:
    print(s[0])
else:
    for i in range(len(s)):
        anslist+=s[i]
        for j in range(i+1,len(s)):
            str+=s[j]
            anslist.append(s[i]+str)
        str=''
    anslist=sorted(list(set(anslist)))
    print(anslist[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
s = input()
k = int(input())
anss = []
for bit in product(list(range(len(s)+1)), repeat=2):
    if bit[0] < bit[1] and s[bit[0]:bit[1]] not in anss:
        anss.append(s[bit[0]:bit[1]])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

x = dict()
y = []
for i in range(5000):
    y.append([])

#O(N^2)
"""
for i in range(n):
    t = ""
    for j in range(i,n):
        t += s[j]
        if len(t) in x:
            if t not in y[len(t)]:
                y[len(t)].append(t)
        else:
            x[len(t)] = t
            y[len(t)].append(t)
X = []
for i in range(5000):
    if len(y[i]) == 0:
        continue
    y[i].sort()
    for j in range(len(y[i])):
        X.append(y[i][j])
"""
for i in range(n):
    t = ""
    for j in range(i,n):
        t += s[j]
        x[t] = t
X = []
for i in x:
    X.append(i)
X.sort()


#print(X)
print(X[K-1])

Submission status: Time Limit Exceeded

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

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

substr = sorted(list(substr))
print(substr[k-1])

Submission status: Time Limit Exceeded

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

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

substr = sorted(list(substr))
print(substr[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
l = int(input())
s1 = sorted(s)
ans = set()

for i in range(len(s)):
    sta = s1[i]
    for j in range(len(s)):
        if s[j] == sta:
            ans.add(s[j])
            check = s[j]
            for k in range(j+1,len(s)):
                check = check+s[k]
                ans.add(check)
    if len(ans) >= l:
        ans1 = sorted(ans)
        print(ans1[l-1])
        exit()
ans1 = sorted(ans)
print(ans1[l-1])

Submission status: Time Limit Exceeded

Solution code:
#X = ["a", "ba", "zxx", "abb", "ab"]
#print(sorted(X))

s = str(input())
K = int(input())
ans = []
N = len(s)

for i in range(N):
  for j in range(i + 1,N + 1):
    x = s[i:j]
    if x not in ans:
      ans.append(x)
#print(ans)
  
print(sorted(ans)[K - 1])

Submission status: Time Limit Exceeded

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

N = len(S)
substr = []
for i in range(N):
    for j in range(i, N):
        tmp_substr = S[i:j+1]
        
        if tmp_substr in substr:
            continue

        if len(substr) <= 4:
            substr.append(tmp_substr)
            substr.sort()
        else:
            substr.append(tmp_substr)
            substr.sort()
            del substr[-1]

print(substr[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, i+K+1):
        if s[i:j] not in S:
            S.append(s[i:j])
S.sort()
print("".join(S[K-1]))