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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations_with_replacement 
from collections import defaultdict
from operator import itemgetter
def main():
    s = readline().rstrip().decode()
    K = int(readline())
    N = len(s)
    p = [int(i) for i in range(N)]
    S = set()
    for pair in combinations_with_replacement(p, 2):
        l, r = pair
        S.add(s[l:r+1])
    lis = []
    for sub in S:
        lis.append(sub)
    lis.sort()
    print(lis[K-1])
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations_with_replacement 
from collections import defaultdict
from operator import itemgetter
def main():
    s = readline().rstrip().decode()
    K = int(readline())
    N = len(s)
    p = [int(i) for i in range(N)]
    S = set()
    for pair in combinations_with_replacement(p, 2):
        l, r = pair
        S.add(s[l:r+1])
    lis = []
    for sub in S:
        lis.append(sub)
    lis.sort()
    print(lis[K-1])
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

# print(s,k,n)

ks = {}
m = {}
for i in range(n):
    if s[i] in m.keys():
        m[s[i]] += [i]
    else:
        m[s[i]] = [i]

# "spam".startswith("sp")

m = list(m.items())
# print(m)
m.sort()
# print(m)

# for ky,ixs in m.items():
for ky,ixs in m:
    c = set()
    for i in ixs:
        for j in range(len(s[i:])):
            c.add(s[i:i+j+1])
            # print(s[i:i+j+1])
    c = list(c)
    c.sort()
    # print(len(c),c)
    # print('---')
    for ans in c:
        k -= 1
        if k == 0:
            print(ans)
            exit()
print(s)

Submission status: Time Limit Exceeded

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

c = set()
for i in range(n-1):
    for j in range(i+1, n+1):
        c.add(s[i:j])

if k <= len(c):
    c = list(c)
    c.sort()
    print(c[k-1])
else: print(s)

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, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

s = input()
K = INT()


substr = []

for l in range(len(s)):
	r = l+1
	while r < len(s)+1:
		#print(l, r, substr)
		if bisect(substr, s[l:r]) == 5:
			break
		elif s[l:r] not in substr:
			insort(substr, s[l:r])
			substr = substr[:5]
			if s[l:r] in substr:
				r += 1

		if r == l+1:
			r += 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s,K = open(0).read().split()
K = int(K)
ss = set()
temp = set([''])
for x in s:
    temp = set([''.join((y,x)) for y in temp])
    ss = ss | temp
    temp.add('')
l = sorted(ss)
print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
s,K = open(0).read().split()
K = int(K)
ss = set()
temp = set([''])
for x in s:
    t2 = set([''.join((y,x)) for y in temp])
    ss = ss | t2
    temp = t2.copy()
    temp.add('')
l = sorted(ss)
print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if string not in Dict.keys() and len(string)<=k:
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
k =  int(input())
s.append((''))
Dict = {}
dict_keys = []
for left in range(len(s)):
    for right in range(left+1,len(s)):
        string = ''.join(s[left:right])
        if string not in Dict.keys():
            Dict[string] = True
Dict = sorted(Dict.keys())
print(Dict[k-1])

Submission status: Time Limit Exceeded

Solution code:
from bisect import *

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

substrings = []
for i in range(1, n+1):
    for j in range(n-i+1):
        insort_left(substrings, s[j:j+i])

j = 0
ans = 0
cnt = 0
while j < k:
    if ans != substrings[cnt]:
        ans = substrings[cnt]
        j += 1
    cnt += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

print(substrings[k-1])

Submission status: Time Limit Exceeded

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    k = ii()
    n = len(s)

    L = list(set([s[i:j] for i in range(n) for j in range(i+1, n+1)]))
    print(nsmallest(k, L)[-1])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
a =[chr(ord('a') + i) for i in range(26)]

tar = set()
alpha_idx = 0
while len(tar) < k:
    alpha = a[alpha_idx]
    for i in range(len(s)):
        if s[i] == alpha:
            for j in range(i+1, len(s)+1):
                tar.add(s[i:j])
    alpha_idx += 1
tar = list(tar)
tar.sort()
print(tar[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
ans = []
ref = sorted(set(s))
for i in ref:
    for j in range(len(s)):
        if s[j] == i:
            ans += [s[j:j+k] for k in range(1,len(s)-j+1)]
            ans = sorted(set(ans))
    if len(ans)>=k:
        print(ans[k-1])
        break
    else:
        continue
    break

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N = len(S)
    K = int(input())
    top_k = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            st = S[i:j]
            top_k.append(st)
            if len(top_k) > K:
                top_k = list(set(top_k))
                top_k.sort()
                top_k = top_k[:K]
    top_k.sort()
    print(top_k[-1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def main():
    s = input()
    N = len(s)
    K = int(input())
    X = set()
    for i in range(1,N+1):
        for j in range(N-i+1):
            X.add(s[j:j+i])
    print(sorted(X)[K-1])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

data = sorted(set(data))
print(data[k - 1])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))

S = input()
#S = 'abcdefghijklmnopqrstuvwxyz'*200
K = ii()
N = len(S)
'''
N = len(S)
d = defaultdict(int)
for i in range(N+1):
    for j in range(N-i+1):
        d[S[j:j+i+1]] += 1
l = sorted(d.keys())
#print(l)
print(l[K])
'''

alphabets = list('abcdefghijklmnopqrstuvwxyz')

#print(len(alphabets))
l = []
for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            for j in range(1, N-i+1):
                l.append(S[i:i+j])

    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
#S = 'abcdefghijklmnopqrstuvwxyz'*200
K = ii()
N = len(S)
'''
N = len(S)
d = defaultdict(int)
for i in range(N+1):
    for j in range(N-i+1):
        d[S[j:j+i+1]] += 1
l = sorted(d.keys())
#print(l)
print(l[K])
'''

alphabets = list('abcdefghijklmnopqrstuvwxyz')
#print(len(alphabets))
l = []
for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            for j in range(N-i):
                if S[i:i+j+1] not in l:
                    l.append(S[i:i+j+1])
                    K -= 1
    if K <= 0:
        l = sorted(l)
        #print(l)
        print(l[K-1])
        exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = []
table ={}

for i in range(len(S)):
    for j in range(len(S)+1):
        if (j-i)>=6:
            break
        if i==j:
            s = S[i]
            if s in table:
                continue
            table[s] = 1
            ans.append(s)
            continue
        if S[i:j]=="":
            continue
        s = S[i:j]
        if s in table:
            continue
        table[s] = 1
        ans.append(s)

ans = sorted(ans)
print(ans[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(len(S)+1):
        if (j-i)>=6:
            break
        if i==j:
            ans.append(S[i])
            continue
        if S[i:j]=="":
            continue
        ans.append(S[i:j])
ans = sorted(list(set(ans)))
print(ans[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(len(S)+1):
        if (j-i)>=6:
            break
        if i==j:
            ans.add(S[i])
            continue
        if S[i:j]=="":
            continue
        ans.add(S[i:j])
ans = sorted(list(ans))
print(ans[K-1])

Submission status: Time Limit Exceeded

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

ans = set()

for i in range(len(S)):
    for j in range(len(S)+1):
        if i==j:
            ans.add(S[i])
            continue
        if S[i:j]=="":
            continue
        ans.add(S[i:j])
ans = sorted(list(ans))
print(ans[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
s = input()
k = int(input())
n = len(s)
a = set()
for i in range(n):
    for j in range(i + 1, n + 1):
        a.add(s[i : j])
# print(a)
b = sorted(list(a))
# print(b)
ans = b[k - 1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def abc097_c():
    S = str(input())
    K = int(input())
    pos = dict()
    subs = set()

    for i, c in enumerate(S):
        if pos.get(c):
            pos[c].append(i)
        else:
            pos[c] = [i]

    keys = sorted(list(pos.keys()))
    for c in keys:
        for st in pos[c]:
            for ed in range(st+1, len(S)+1):
                subs.add(S[st:ed])
        if len(subs) >= K:
            break

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

abc097_c()

Submission status: Time Limit Exceeded

Solution code:
def abc097_c():
    S = str(input())
    K = int(input())
    subs = set()

    for n in range(1, len(S)+1):
        for i in range(0, len(S)-n+1):
            subs.add(S[i: i+n])

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

abc097_c()

Submission status: Time Limit Exceeded

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

ansset= set()
from itertools import combinations_with_replacement

c = list(combinations_with_replacement(range(n),2))
#print(c)

for i in range(len(c)):
    ansset.add(s[c[i][0]:c[i][1]+1])
ans = sorted(list(ansset))

print(ans[k-1])

Submission status: Time Limit Exceeded

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

ansset= set()

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

anslist = sorted(list(ansset))

print(anslist[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
d = list()
for l in range(len(s)):
  for r in range(l,len(s)): #左からl番目、右からr番目までの文字列
    n = s[l:r+1]
    if n not in d:
      d.append(n)
    d.sort()
    d = d[:5]
print(d[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
d = list()
for l in range(len(s)):
  for r in range(l,len(s)): #左からl番目、右からr番目までの文字列
    n = s[l:r+1]
    if n not in d:
      d.append(n)
    d.sort()
    d = d[:6]
print(d[K-1])

Submission status: Time Limit Exceeded

Solution code:
import string
s = input()
k = int(input())
d=[]
for sp in string.ascii_lowercase:
  for i,sd in enumerate(s,start=0):
    if sp == sd:
      for l in range(1, len(s)+1):
        if i+l > len(s):
          break
        d.append(s[i:i+l])
  d=list(set(d))
  if len(d) >= k:
    break

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

Submission status: Time Limit Exceeded

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

s = list(s)
ans = []
for i in range(n + 1):
    for j in range(i + 1, n + 1):
        ans.append(str(''.join(s[i:j])))

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
d=[]
for l in range(1, len(s)+1):
  for j in range(len(s)):
    if j+l > len(s):
      break
    d.append(s[j:j+l])
d=list(set(d))
d=sorted(d)
print(d[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
d = set([])
n = len(s)
for i in range(n):
    substring = ''
    for t in s[i:n]:
        substring = substring + t
        d.add(substring)
print(sorted(d)[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
d = []
n = len(s)
for i in range(n):
    substring = ''
    for t in s[i:n]:
        substring = substring + t
        d.append(substring)
print(sorted(set(d))[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if len(s_first) >=6:
  s_first = s_first[:5]
  
s_list = set(s_list)
s_list = list(s_list)
new = []
for i in range(len(s_list)):
  if s_list[i][0] not in s_first:
    continue
  else:
    new.append(s_list[i])
    
new.sort()
print(new[k-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def main():
    S = readline().rstrip()
    K = int(readline())
    N = len(S)
    d = {}
    for i in range(N):
        s = ''
        head = S[i]
        d.setdefault(head, set())
        for j in range(i, N):
            s += S[j]
            d[head].add(s)

    for key, val in sorted(d.items()):
        if K <= len(val):
            print(sorted(list(val))[K-1])
            return
        else:
            K -= len(val)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=list(input())
n=len(s)
K=int(input())
d=deque()
l=["" for _ in range((n*(n+1))//2)]
li=[]
cnt=0
st=""
cnt=0
for i in range(n):
    d.append(s[i])
#print(s,len(s))
for i in range(n):
    buf=deque()
    #print(s[i])
    #piv=ord(s[i])-97
    for j in range(n-i):
        v=d.popleft()
        buf.append(v)
        st="".join(buf)
        l[cnt]=st
        cnt=cnt+1
    buf.popleft()
    d=buf
l=list(set(l))
l.sort()
#print(l)
print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=list(input())
n=len(s)
K=int(input())
d=deque()
l=[{} for _ in range(26)]
li=[]
cnt=0
st=""

for i in range(n):
    d.append(s[i])
#print(s,len(s))
for i in range(n):
    buf=deque()
    #print(s[i])
    piv=ord(s[i])-97
    for j in range(n-i):
        v=d.popleft()
        buf.append(v)
        st="".join(buf)
        l[piv][st]=cnt
    buf.popleft()
    d=buf
#print(l)
buf=[]
for i in range(26):
    #print(l[i],len(l[i]))
    if len(l[i])<K:
        K=K-len(l[i])
    else:
        buf = list(l[i])
        buf.sort()
        print(buf[K-1])
        break

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=list(input())
n=len(s)
K=int(input())
d=deque()
l=[{} for _ in range(26)]
li=[]
cnt=0
st=""

for i in range(n):
    d.append(s[i])
#print(s,len(s))
for i in range(n):
    buf=deque()
    #print(s[i])
    piv=ord(s[i])-97
    for j in range(n-i):
        v=d.popleft()
        buf.append(v)
        st="".join(buf)
        l[piv][st]=cnt
    buf.popleft()
    d=buf
#print(l)
buf=[]
for i in range(26):
    buf=list(l[i])
    if len(buf)<K:
        K=K-len(buf)
    else:
        buf.sort()
        print(buf[K-1])
        break

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=list(input())
n=len(s)
K=int(input())
d=deque()
l={}
li=[]
cnt=0
for i in range(n):
    d.append(s[i])
for i in range(n):
    buf=deque()
    for j in range(n-i):
        v=d.popleft()
        buf.append(v)
        s="".join(buf)
        l[s]=cnt
    buf.popleft()
    d=buf
#print(l)
li=list(l)
li.sort()

#print(l)
print(li[K-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=list(input())
n=len(s)
K=int(input())
d=deque()
l=[]
for i in range(n):
    d.append(s[i])
for i in range(n):
    buf=deque()
    for j in range(n-i):
        v=d.popleft()
        buf.append(v)
        l.append("".join((buf)))
    buf.popleft()
    d=buf
l=list(set(l))
l.sort()
#print(l)
print(l[K-1])

Submission status: Time Limit Exceeded

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

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, N):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
st=[[] for i in range(26)]
n=len(s)
for i in range(n):
    st[ord(s[i])-97].append(i)

pre=0
now=set()
for i in st:
    for v in i:
        for c in range(v+1,n+1):
            now.add(s[v:c])
    if len(now)+pre<k:pre+=len(now);now=set()
    else:
        print(sorted(list(now))[k-pre-1]);exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

try:
    from typing import Set
except ImportError:
    pass


def f(s: "Set[str]", p: int, i: int):
    bins = Counter(sj[p:p + 1] for sj in s)
    cum = 0
    key = ""
    cnt = 0
    for key, cnt in sorted(bins.items()):
        cum += cnt
        if cum > i:
            break
    else:
        raise IndexError(i)
    new_s = {sj for sj in s if sj[p:p + 1] == key}
    if len(new_s) == 1:
        return list(new_s)[0]
    return f(new_s, p + 1, i - cum + cnt)


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(f(ss, 0, 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()