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())
N = len(S)

l = []
for i in range(N):
    for j in range(i+1,N+1):
        j = min(j,i+K)
        s = S[i:j]
        l.append(s)
l = list(set(l))
l.sort()
print(l[K-1])

Submission status: Time Limit Exceeded

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

l = []
for i in range(N):
    for j in range(i+1,N+1):
        j = min(j,i+K)
        s = S[i:j]
        if s not in l:
            l.append(s)
l.sort()
print(l[K-1])

Submission status: Time Limit Exceeded

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

s = sorted(S)
s = s[0:4]

L = []
c = 0
for x in s:
    for i in range(N):
        if S[i] == x:
            for j in range(i+1,N+1):
                a = S[i:j]
                if a not in L:
                    L.append(a)
                    c += 1
    if c >= K:
        break
L.sort()
print(L[K-1])

Submission status: Time Limit Exceeded

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

s = sorted(S)
s = s[0:4]

L = []
for i in range(N):
    if S[i] in s:
        for j in range(i+1,N+1):
            a = S[i:j]
            if a not in L:
                L.append(a)
L.sort()
print(L[K-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

subst = set()
for fil_i in range(1, len(s)+1):
    for ix in range(0, len(s)):
        if ix + fil_i <= len(s):
            # print(ix,fil_i)
            # print(s[ix:ix+fil_i])
            subst.add(s[ix: ix + fil_i])
        else:
            break

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import nsmallest

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def get_char_ngram(n, s):
    char_gram = [''.join(s[i:i+n]) for i in range(len(s)-n+1)]
    return char_gram

s = input()
K = int(input())
res = set()
for i in range(1, len(s)+1):
    tmp = set(get_char_ngram(i, s))
    res = res.union(tmp)
res = sorted(list(res))
print(res[K-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    s = input()
    K = inputInt()
    
    d = []
    for i in range(len(s)+1):
        for j in range(i, len(s)+1):
            tmp = s[i:j+1]
            if not(tmp in d):
                d.append(tmp)
            
    d = d[0:-1]
    #d.sort(key=len)
    d.sort()
    
    #print(d)
    print(d[K-1])
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

    S1 = {}
    for i, s in enumerate(S):
        if not s in S1.keys():
            S1[s] = [i]
        else:
            S1[s].append(i)
    alp = sorted(list(S1.keys()))

    c = 0
    for a in alp:
        aset = set()
        inds = S1[a]
        for d in inds:
            for i in range(N-d+1):
                aset.add(S[d:d+i])
        L = len(aset)-1
        if L >= K-c:
            break
        c += L

    for _ in range(10):
        min = '何だこれはもうやめてくれよ'
        for a in aset:
            if a < min:
                min = a
        aset.discard(min)
        if min == '':
            continue
        c += 1
        if c >= K:
            ans = min
            break

    print(ans)



if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    L = len(aset)-1
    if L >= K-c:
        break
    c += L


for _ in range(10):
    min = '何だこれはもうやめてくれよ'
    for a in aset:
        if a < min:
            min = a
    aset.discard(min)
    if min == '':
        continue
    c += 1
    if c >= K:
        ans = min
        break

print(ans)

Submission status: Time Limit Exceeded

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

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    if len(aset)-1 >= K-c:
        break
    c += len(aset)-1


for _ in range(10):
    for i, a in enumerate(aset):
        if i == 0:
            min = a
            continue
        if a < min:
            min = a
    aset.discard(min)
    if min == '':
        continue
    c += 1
    if c >= K:
        ans = min
        break

print(ans)

Submission status: Time Limit Exceeded

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

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    if len(aset)-1 >= K-c: break
    c += len(aset)-1


while True:
    for i, a in enumerate(aset):
        if i == 0:
            min = a
            continue
        if a < min:
            min = a
    aset.discard(min)
    if min == '': continue
    c += 1
    if c >= K:
        ans = min
        break

print(ans)

Submission status: Time Limit Exceeded

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

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    if len(aset)-1 >= K-c:
        break
    c += len(aset)-1


while True:
    for i, a in enumerate(aset):
        if i == 0:
            min = a
            continue
        if a < min:
            min = a
    aset.discard(min)
    if min == '':
        continue
    c += 1
    if c >= K:
        ans = min
        break

print(ans)

Submission status: Time Limit Exceeded

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

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    alist = sorted(list(aset))
    for al in alist:
        if al == '':
            continue
        c += 1
        if c == K:
            ans = al
            break
    if c == K:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
cnt = defaultdict(int)

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

_len = len(S)
buff = []
for i in range(1, _len+1):
    for j in range(_len):
        # if j+i < _len+3:
        if cnt[S[j:j+i]]==0:
            cnt[S[j:j+i]] = 1
            buff.append(S[j:j+i])

buff.sort()
# buff = buff[::-1]
b_len = len(buff)
# for i in range(b_len):
#     # if buff[i] == buff[i+1]:

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

Submission status: Time Limit Exceeded

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

kouho = []
for i, c in enumerate(s):
    #if c == char:
    for j in range(1,len(s)-i+1):
        kouho.append(s[i:i+j])
kouho = list(set(kouho))
kouho.sort()
print(kouho[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
k = int(raw_input())
dic = {}
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        t = s[i:j]
        if t in dic:
            continue
        else:
            dic[t] = True
arr = list(dic.keys())
arr.sort()
print arr[k-1]

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

D = defaultdict(lambda: [])
for i, c in enumerate(S):
    D[c].append(i)

E = defaultdict(lambda: set())
for c in "abcdefghijklmnopqrstuvwxyz":
    for i in D[c]:
        for j in range(i + 1, len(S) + 1):
            E[c].add(S[i:j])
    if K - len(E[c]) <= 0:
        L = list(E[c])
        L.sort()
        print(L[K - 1])
        break
    else:
        K -= len(E[c])

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.sort()
a=[ans[0]]
for i in range(1,len(ans)):
    if ans[i-1]!=ans[i]:
        a.append(ans[i])
print(a[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):
        anss=""
        for l in range(i,j):
            anss+=s[l]
        ans.append(anss)
ans.sort()
a=[ans[0]]
for i in range(1,len(ans)):
    if ans[i-1]!=ans[i]:
        a.append(ans[i])
print(a[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
anslist = []
for i in range(0, len(S)):
	now = str(S[i])
	if len(anslist) != K and now not in anslist:
		anslist.append(now)
	elif len(anslist) == K and now < anslist[-1] and now not in anslist:
		anslist[-1] = now
	anslist.sort()
	for j in range(i+1, len(S)):
		now = now + str(S[j])
		if len(anslist) != K and now not in anslist:
			anslist.append(now)
		elif len(anslist) == K and now < anslist[-1] and now not in anslist:
			anslist[-1] = now
		anslist.sort()
print(anslist[-1])

Submission status: Time Limit Exceeded

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

for i in range(len(s)):
    x = s[i:]
    for j in range(len(x)):
        d.add(x[:j+1])

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

Submission status: Time Limit Exceeded

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


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


ans_lst = list(ans_set)
ans_lst.sort()
ans = ans_lst[k-1]


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

dic=[]

for i in range(1,6):
    for k in itertools.permutations('abcdefghijklmnopqrstuvwxyz', i):
        dic.append(''.join(k))
dic.sort()


ans=0
for str in dic:
    if str in s:
        ans+=1
    if ans==K:
        print(str)
        exit()

Submission status: Time Limit Exceeded

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

part_string_row = []
for i in range(len(line)):
	for j in range(len(line)):
		part_string_row.append(line[i:i+j+1])
part_string_row = sorted(list(set(part_string_row)))

print(part_string_row[k-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=int(input())
l=set()
for i in  range(len(s)):
    for j in range(len(s)):
        l.add(s[i:i+j+1])
ll=list(l)
ll.sort()

print(ll[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
substring = []
loong = False
for i in range(len(s)):
    for j in range(i, len(s)):
        if len(substring) <= 5:
            substring.append(s[i: j + 1])
            substring = list(set(substring))
            substring.sort()
            if len(substring) == 5:
                loong = True
        elif loong and substring[-1] > s[i: j + 1] and not s[i:j+1] in substring :
            substring[-1] = s[i: j + 1]
            substring.sort()

                
print(substring[K-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
s = input()
K = int(input())
substring = []
for i in range(len(s)):
    for j in range(i, len(s)):
        if len(substring) <= 5:
            substring.append(s[i: j + 1])
            substring = list(set(substring))
            substring.sort()
        elif substring[-1] > s[i: j + 1] and not s[i:j+1] in substring :
            bisect.insort_left(substring, s[i: j + 1])

                
print(substring[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
S = set(s)
SK2 = []
for a in range(len(S)):
  mn_S = min(S)
  SK2.append(mn_S)
  idx_mnS = [i for i, x in enumerate(s[:-1]) if x==mn_S]
  for i in idx_mnS:
    for j in range(i+2, len(s)+1):
      SK2.append(s[i:j])
  SK2 = list(set(SK2))
  if len(SK2)>=K:
    break
  else:
    S.remove(mn_S)
SK2.sort()
print(SK2[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(set(a))
c = []
INF = 97+26
for m in b:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        while i+j < len(s) or j < k:
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
                c.sort()
            if len(c) > 5:
                del c[-1]
            j += 1
    if len(c) >= k:
        break

print(c[k-1])

Submission status: Time Limit Exceeded

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(a)
m = b[0]
n = 0
c = []
INF = 97+26
while True:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        while i+j < len(s) or j < k:
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
                c.sort()
            if len(c) > 5:
                del c[-1]
            j += 1
    if len(c) >= k:
        break
    while b[n] == m:
        n += 1
    m = b[n]
print(c[k-1])

Submission status: Time Limit Exceeded

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(a)
m = b[0]
n = 0
c = []
INF = 97+26
while True:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        while i+j < len(s) or j < k:
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
            j += 1
    if len(c) >= k:
        break
    while b[n] == m:
        n += 1
    m = b[n]
c.sort()
print(c[k-1])

Submission status: Time Limit Exceeded

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(a)
m = b[0]
n = 0
c = []
INF = 97+26
while True:
    a1 = [i for i in range(len(s)) if a[i] == m]

    for i in a1:
        j = 0
        while i+j < len(s):
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
            j += 1
    if len(c) >= k:
        break
    while b[n] == m:
        n += 1
    m = b[n]
c.sort()
print(c[k-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
S = input()
K = int(input())
s_len = len(S)
s_set = set()
for i in range(1, s_len+1):
    j = 0
    while j+i <= s_len:
        s_set.add(S[j:j+i])
        j += 1
    
s_sort = sorted(list(s_set))
print(s_sort[K-1])

Submission status: Time Limit Exceeded

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

a = list(s)
a = [ord(i) for i in a]
m = 0
c = []
INF = 97+26
while len(c) < k:
    m = min(a, key=lambda x: x if x > m else INF)
    a1 = [i for i in range(len(s)) if a[i] == m]
    for i in a1:
        j = 0
        while i+j < len(s):
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
            j += 1

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

Submission status: Time Limit Exceeded

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

a = list(s)
a = [ord(i) for i in a]
m = 0
c = []
INF = 97+26
while len(c) < k:
    m = min(a, key=lambda x: x if x > m else INF)
    a1 = [i for i in range(len(s)) if a[i] == m]
    for i in a1:
        j = 0
        while i+j < len(s):
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
            j += 1

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

Submission status: Time Limit Exceeded

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

kn = len(s) * k
k_list = set(s)
for i in range(2, len(s)+1):
    if len(k_list) >= kn:
        break
    for j in range(len(s)+1-i):
        sub = s[j:j+i]
        k_list.add(sub)

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

Submission status: Time Limit Exceeded

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

k_list = set(s)
for i in range(2, len(s)+1):
    for j in range(len(s)+1-i):
        sub = s[j:j+i]
        k_list.add(sub)
        if len(k_list) > k * len(s):
            break
    if len(k_list) > k * len(s):
        break

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

Submission status: Time Limit Exceeded

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

k_list = set(s) 
for i in range(2, len(s)+1):
    for j in range(len(s)+1-i):
        sub = s[j:j+i]
        k_list.add(sub)
    if len(k_list) > k * len(s):
        break

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

Submission status: Time Limit Exceeded

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

k_list = set(s) 
for i in range(2, len(s)+1):
    for j in range(len(s)+1-i):
        sub = s[j:j+i]
        k_list.add(sub)

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

Submission status: Time Limit Exceeded

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

k_list = set() 
for i in range(1, len(s)+1):
    for j in range(len(s)+1-i):
        sub = s[j:j+i]
        k_list.add(sub)
k_list = list(k_list)
k_list.sort()
print(k_list[k-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
As=sorted(s)
ans=[]
for A in As:
    if len(ans)>K:break
    for j in range(1,K+1):
        ind=0
        for i in s:
            if i==A:
                if len(s[ind:ind+j])==j and (s[ind:ind+j] not in ans):
                    ans.append(s[ind:ind+j])
            ind+=1
print(sorted(ans)[K-1])

Submission status: Time Limit Exceeded

Solution code:
s=input()
K=int(input())
As=sorted(s)
ans=[]
for A in As:
    if len(ans)>K:break
    for j in range(1,K+1):
        ind=0
        for i in s:
            if i==A:
                if len(s[ind:ind+j])==j and (s[ind:ind+j] not in ans):
                    ans.append(s[ind:ind+j])
            ind+=1
print(sorted(ans)[K-1])

Submission status: Time Limit Exceeded

Solution code:
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            count2 = 0
            for j in range(len(s)-i):
                if s[i:i+j+1] not in li:
                    count += 1
                    count2 += 1
                    li.append(s[i:i+j+1])
                    if count2 >= k:
                        break
li.sort()
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(len(s)-i):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:


S = input()
N = int(input())
l = len(S)

sub = {}
for i in range(1,l+1):
    for j in range(0,l+1-i):
        temp = S[j:j+i]
        if temp not in sub:
            sub [temp]  = True

sub = list(sub.keys())
sub.sort()
print(sub[N-1])

Submission status: Time Limit Exceeded

Solution code:


S = input()
N = int(input())
l = len(S)

sub = []
for i in range(1,l+1):
    for j in range(0,l+1-i):
        sub.append(S[j:j+i])
sub = list(set(sub))
sub.sort()
print(sub[N-1])

Submission status: Time Limit Exceeded

Solution code:
def key(k):
    return (len(k), k)    

def solve(S, K):
    ss = set()
    for k in range(1, len(S)+1): 
        for i in range(0, len(S)-k+1):
            ss.add(S[i:i+k])
    ss = sorted(ss)
    return ss[K-1]
    
S = input().strip()
K = int(input())

print(solve(S, K))

Submission status: Time Limit Exceeded

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


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

    part_set = set()
    for c in string.ascii_lowercase:
        for i in range(len(s)):
            if c == s[i]:
                part_set |= set(itertools.accumulate(s[i:]))
        if len(part_set) >= K:
            print(sorted(part_set)[K-1])
            return
                


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
store = []
for i in range(len(S)):
  N = i+1
  while N <= len(S):
    store.append(S[i:N])
    N += 1
store_set = set(store)
store_list = list(store_set)

List = [ x for x in store_list  if len(x) <= K ]
List.sort()
print(List[K-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
K = int(input())
store = []
for i in range(len(S)):
  N = i+1
  while N <= len(S):
    store.append(S[i:N])
    N += 1
store_set = set(store)
store_list = list(store_set)
store_list.sort()
print(store_list[K-1])

Submission status: Time Limit Exceeded

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

lst = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
#        print ('i, j=', i, j)
        lst += [s[i:j]]

lst.sort()
#print (lst)
k = 0
flag = 0
ans = str()
check = True
while check:
    if ans != lst[flag]:
        #print ('k', k)
        k += 1
    ans = lst[flag]
    #print ('ans=', ans)
    flag += 1
    if k == K:
        ans = ''.join(ans)
        print(ans)
        check = not check

Submission status: Time Limit Exceeded

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

lst = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
#        print ('i, j=', i, j)
        lst += [s[i:j]]

lst.sort()
#print (lst)
k = 0
flag = 0
ans = str()
check = True
while check:
    if ans != lst[flag]:
        #print ('k', k)
        k += 1
    ans = lst[flag]
    #print ('ans=', ans)
    flag += 1
    if k == K:
        for l in ans:
            print (l, end ='')
        check = not check
print ()

Submission status: Time Limit Exceeded

Solution code:


def read_input():
    s = input()
    k = int(input())
    return s, k

def submit():
    s, k = read_input()

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

    subs = [[c for c in s] for s in subs]
    subs.sort()

    print(''.join(subs[k - 1]))

if __name__ == '__main__':
    submit()

Submission status: Time Limit Exceeded

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

l = {s}
for n in range(1, len(s)):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])

l = list(l)

l.sort()

print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
	S = input()
	K = int(input())
	sub = set()
	for i in range(len(S)):
		for j in range(i+1, len(S)+1):
			sub.add(S[i:j])
	sub_list = list(sub)
	sub_list.sort()
	ans = sub_list[K-1]
	print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

a=set([])

for x in range(len(s)):
	for y in range(x, len(s)):
		a.add(s[x:y+1])

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

Submission status: Time Limit Exceeded

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


def solve(s: str, K: int):
    queue = []
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            substr = s[i:j]
            if substr not in queue:
                queue.append(substr)
                queue.sort()
                if len(queue) > K:
                    queue = queue[0:K]
    print(queue[K-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

def solve():
  memo = []
  sortedS = sorted(set(s))
  for letter in sortedS:
    for start in [i for i in range(len(s)) if s[i]==letter]:
      for end in range(start+1, len(s)+1):
        substr = s[start:end]
        i = 0
        if substr in memo: continue
        while i<len(memo) and is_X_larger_than_Y(substr,memo[i]):
          i+=1
        if(len(memo)==0): memo.append(substr)
        else: memo.insert(i, substr)
    if k<=len(memo): return memo[k-1]
  

def is_X_larger_than_Y(x, y): # true: 1, false:0, equal: 2
  for i in range(min( len(x), len(y) )):
    if x[i]==y[i]: continue
    elif x[i] < y[i]: return 0
    else: return 1
  if len(x) == len(y): return 2
  elif len(x) < len(y): return 0
  else: return 1

print(solve())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
s = input()
K = int(input())
l = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in l:
            l.append(s[i:j])
l.sort()
print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
s = input()
K = int(input())

dp = ["z"] * 5000
l = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in l:
            l.append(s[i:j])
l.sort()
print(l[K-1])

Submission status: Time Limit Exceeded

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

n = len(s)

sub = []
alp = [chr(i) for i in range(ord('a'), ord('z')+1)]

for a in alp:
    if a in s:
        start = -1
        while True:
            start = s.find(a, start+1)
            if start==-1:
                break
            for j in range(start+1, n+1):
                if s[start:j] not in sub:
                    sub.append(s[start:j])
    if len(sub) > K:
        break

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
s = list(input())
k = int(input())

part = [[]]

for i in range(len(s)):
    for j in range(1,len(s)+1):
        if i + j > len(s):
            break
        part.append(s[i:i+j])
del part[0]

part.sort()

delete = []

for i in range(1,len(part)):
    if part[i-1] == part[i]:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del part[delete[i] - diff]
    diff += 1

print("".join(part[k-1]))