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: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
x = []
n = len(s)
for i in range(k):
    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: Accepted

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

L = set(list(S))

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

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

Submission status: Accepted

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, min(N, i+5)):
            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: Accepted

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

sb=set()
for i in range(len(s)):
    for ii in range(i,i+k):
        if ii<len(s):
#            print(s[i:ii+1])            
            sb.add(s[i:ii+1])
sb2=list(sb)
sb2.sort()
print(sb2[k-1])

Submission status: Accepted

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, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=input()
    K=int(input())
    l=[]
    for i in range(len(s)):
        for j in range(1,K+1):
            if i+j>len(s):
                continue
            l.append(s[i:i+j])
    l=list(set(l))
    l.sort()
    print(l[K-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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,min(n+1,v+6)):
            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: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input().rstrip()
l = len(s)
k = int(input())
chk = set()
for i in range(26):
  for j in range(l):
    if s[j] == chr(i+97):
      for m in range(min(5,l-j)):
        chk.add(s[j:j+1+m])
  if len(chk) >= k:
    break
    
chk = sorted(list(chk))
print(chk[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
# input処理を高速化する
input = lambda: sys.stdin.readline().rstrip()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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, min(n + 1, i + K + 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: Accepted

Solution code:
# solution

data = input()

qwe = int(input())

dic = set()

for i in range(len(data)):
    for j in range(qwe):
        if i+j+1 <= len(data):
            dic.add(data[i:i+j+1])
di = list(dic)
di.sort()
print(di[qwe-1])

Submission status: Accepted

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from bisect import *
s = str(input())
K = int(input())
ls = len(s)
l = []
for i in range(ls):
  for j in range(i+1,i+K+2):
    l.append(s[i:j])

l = list(set(l))
l = sorted(l)
print(l[K-1])

Submission status: Accepted

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()))


s = ns()
k = ni()

check = set()

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

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

Submission status: Accepted

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, left+k+1):
            check.add(s[left:right])
    
    print(sorted(list(check))[k-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
n = len(list(s))
kouho = set()
for i in range(n):
    for d in range(1, k + 1):
        if i + d <= n:
            kouho.add(s[i : i + d])
ans = list(kouho)
ans.sort()
# print(ans)
print(ans[k - 1])

Submission status: Accepted

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

lS = len(S)
asc = 97
while True:
    st = set()
    for i in range(lS):
        if S[i] == chr(asc):
            j = i + 1
            while j - i <= 5 and j <= lS:
                st.add(S[i:j])
                j += 1
    if len(st) >= K:
        print(sorted(list(st))[K - 1])
        break
    else:
        K -= len(st)
        asc += 1

Submission status: Accepted

Solution code:
s = input()
N = len(s)
K = int(input())
ss = []
for i in range(N):
    for j in range(1,6):
        if  i+j <= N:
            ss.append(s[i:i+j])

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

Submission status: Accepted

Solution code:
import sys

s, k = sys.stdin.read().split()
k = int(k)

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

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    s = IS()
    k = II()
    subs = []
    n = len(s)
    for i in range(k):
        for j in range(n-i):
            subs.append(s[j:j+(i+1)])
    subs = sorted(list(set(subs)))
    print(subs[k-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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())
    #LIST = {s}
    #for i in range(k):
    #    for j in range(len(s) - i):
    #        LIST.add(s[j:j+i+1])
    #print(LIST)
    #print(sorted(list(LIST))[k-1])
    # 辞書順で5番目、長さは最長でも5
    r = []
    for i in range(1,6): # 1 ~ 5 文字のながさ 1から5文字まで
        for j in range(len(s) - i + 1): # 見る範囲 len(s) - j  ~ len(s) - j + i まで最後まで見てる!
            r.append(s[j:j+i])
    #print(r)
    print(sorted((set(r)))[k-1])


if __name__ == '__main__':
  main()

Submission status: Accepted

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


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

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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

s_sorted = sorted(s)
array = set()

n = len(s)
for i in range(n):
  for j in range(n):
    if s_sorted[i] == s[j]:
      for l in range(k):
        if l+j >= n:
          break
        
        array.add(s[j:l+j+1])
      
  if len(array) >= k:
    break
    
array = sorted(array)
print(array[k-1])

Submission status: Accepted

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

s1list=[]
for i in range(len(s)):
  s1list.append((s[i],i))
s1list.sort()
#print(s1list)

cold=s1list[0][0]
sset=set()
for i in range(len(s1list)):
  c1,index=s1list[i]
  if cold!=c1 and len(sset)>=5:
    break
  else:
    cold=c1
  
  for j in range(5):
    sub=s[index:index+j+1]
    sset.add(sub)
    
slist=list(sset)
slist.sort()
print(slist[K-1])

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    for i in range(1, K+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: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
n = len(s)
lis = set()
for i in range(26):
    for j in range(len(s)):
        if s[j] == alpha[i]:
            for l in range(j, j+k+1):
                if l < n:
                    lis.add(s[j:l+1])
lis = list(lis)
lis.sort()
#print(lis)
#print(k)
print(lis[k-1])

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

s = input()
k = int(input())
strings = set()

for i in range(len(s)):
    for j in range(5):
        end = i+j+1
        if end > len(s):
            break
        strings.add(s[i:end])

strings = sorted(list(strings))
# print(strings)

print(strings[k-1])

Submission status: Accepted

Solution code:
def main():
    S = input()
    k = int(input())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
k = int(input())
d = 'abcdefghijklmnopqrstuvwxyz'
n = len(s)
lis = set()
for i in range(26):
    for j in range(len(s)):
        if s[j] == d[i]:
            for l in range(j, j+k+1):
                if l < n:
                    lis.add(s[j:l+1])
lis = list(lis)
lis.sort()
#print(lis)
#print(k)
print(lis[k-1])

Submission status: Accepted

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,min(j+k,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: Accepted

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

lst=[]
for length in range(1,K+1):
    for start in range(len(s)-length+1):
        lst.append(s[start:start+length])
#print(lst)
lst=sorted(list(set(lst)))
#print(lst)
print(lst[K-1])

Submission status: Accepted

Solution code:
s=list(input())
K=int(input())
substring=set()
alphabet=list('abcdefghijklmnopqrstuvwxyz')
l=0
while len(substring)<K:
    x=alphabet[l]
    l+=1
    for i in range(len(s)):
        if s[i]==x:
            string=s[i]
            substring.add(string)
            for k in range(1,5):
                try:
                    string+=s[i+k]
                    substring.add(string)
                except:
                    pass
ans=sorted(list(substring))
print(ans[K-1])

Submission status: Accepted

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

Submission status: Accepted

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,min(l,j+k)):
                ans.add(s[j:m+1])
    if len(ans)>=k:
        break
print(sorted(list(ans))[k-1])

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for c in list_Alph:
    q = [i for i, x in enumerate(list_S) if x == c]
    list_M = []
    for i in q:
        l = "".join(list_S[i:])
        list_M.append(l)
    list_M.sort()
    for s in list_M:
        m = list(s)
        for j in range(1,len(m)+1):
            b = "".join(m[:j])
            if b not in set_ANS:
                set_ANS.add(b)
                cnt += 1
                if cnt == k:
                    print(b)
                    exit()

Submission status: Accepted

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

import collections
S_count = collections.Counter(S)

ans_list = set()

for key in S_count:
    for idx, s in enumerate(S):
        if s == key:
            short_S = S[idx:min(idx+5, len(S))]
            append_s = ""
            for s in short_S:
                append_s += s
                ans_list.add(append_s)
    if len(ans_list) >= 5:
        break
# print(ans_list)
ans_list = sorted(list(ans_list))
print(ans_list[K-1])

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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,min(index+6,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: Accepted

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,min(i+2+k,len(s)+1)):
        a.append(s[i:j])
a=sorted(list(set(a)))
print(a[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
t = sorted(s)[min(k-1,len(s)-1)]
data = []
for i in range(len(s)):
    if s[i] <= t:
        data.append(s[i:])
data.sort()
if len(data) > k:
    data = data[:k]

ndata = []
for ss in data:
    for i in range(len(ss)):
        ndata.append(ss[:i+1])
ndata = list(set(ndata))
ndata.sort()
print(ndata[k-1])

Submission status: Accepted

Solution code:
s = input()
N = len(s)
K = int(input())
ords = [ord(_s) for _s in s]
order_set = sorted(list(set(ords)))
d = set()
def add_string(o):
  for i in range(N):
    if ords[i] == o:
      for k in range(1, K+1):
        d.add(s[i:i+k])

add_string(order_set[0])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

add_string(order_set[1])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

add_string(order_set[2])
if len(d) >= K:
  print(sorted(list(d))[K-1])
  quit()

Submission status: Accepted

Solution code:
import sys

import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    k = int(input())
    l = len(s)

    strs = set()

    for i in range(l):
        for j in range(k):
            if (i + j) < l:
                strs.add(s[i:i + j + 1])

    strl = list(strs)
    strl.sort()

    print(strl[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
cnt = 0
ans = set([])
head  = sorted(list(set(list(s))),reverse=True)
while cnt < k:
    tmp_h = head.pop()
    for n,i in enumerate(s):
        if i==tmp_h:
            for j in range(min(k,len(s)-n)):
                ans.add(s[n:n+j+1])
    cnt = len(ans)
ans = sorted(list(ans))
print(ans[k-1])

Submission status: Accepted

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

Submission status: Accepted

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, min(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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
ans=["zzzzzz"]*k
for i in range(len(s)):
  for j in range(i,min(i+8,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: Accepted

Solution code:
def Kth_Substring(s , k):

    ans = []
    sset = set()

    for i in range(len(s)):
        for w in range(1, k + 1):
            sset.add(s[i:i + w])
    ans = sorted(list(sset))
    return ans[k - 1]

def main():
    s = str(input())
    k = int(input())
    print(Kth_Substring(s , k))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

se = set()

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

l = sorted(list(se))
print(l[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

A = set()
for i in range(len(S)):
    for j in range(1, min(K + 1, len(S) - i + 1)):
        A.add(S[i:i + j])

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

Submission status: Accepted

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


def dfs(s, pos):
    global N, K
    ns = {}
    if len(A) > K:
        return
    for i in pos:
        ni = i + 1
        if ni < N:
            x = s + S[ni]
            if x in ns:
                ns[x].append(ni)
            else:
                ns[x] = [ni]
    candidate = []
    for x in list(ns.keys()):
        candidate.append((x, ns[x]))
    candidate.sort()
    for c, idx in candidate:
        A.add(c)
        dfs(c, idx)


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:
        pos = []
        for i, s in enumerate(S):
            if c == s:
                A.add(c)
                pos.append(i)
        dfs(c, pos)

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

Submission status: Accepted

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

ss = set()
for i in range(len(s)):
    for j in range(i+1, min(i+6, 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: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

words=[]
for i in range(len(s)):words.append(s[i:])
words.sort()

record=[]
for i in words:
    for j in range(len(i)):
        word="".join(i[:j+1])
        if word not in record:
            record.append(word)
    if len(record)>=k:
        print(record[k-1]);exit()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
se=set()
for i in range(len(s)):
    for j in range(1,6):
        if(i+j<=len(s)):
           se.add(s[i:i+j])
    
li=sorted(se)
#print(li)
print(li[k-1])

Submission status: Accepted

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

for i in range(1, min(k, 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: Accepted

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

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

Submission status: Accepted

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

lst = set()
for i in range(len(S)):
    for j in range(1, K+1):
        lst.add(S[i:i+j])

res = sorted(list(lst))
print(res[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

ln = len(s)
ans = set()

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

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

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
t = sorted(s)
u = []
v = []
for i in range(min(len(s), 5)):
    u.append(t[i])
for i in range(len(s)):
    if s[i] in u:
        if not [s[i]] in v:
            v.append([s[i]])
        l = [s[i]]
        for j in range(1, 5):
            if i + j == len(s):
                break
            l = l + [s[i + j]]
            if not l in v:
                v.append(l)
for i in range(len(v)):
    v[i] = "".join(v[i])
v.sort()
print(v[k - 1])

Submission status: Accepted

Solution code:
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    s = input().rstrip()
    K = int(input())
    a = sorted(set(s))
    res = set()
    n = len(s)
    for i in a:
        res.add(i)
        if len(res)>=K:
            res = sorted(res)
            print(res[K-1])
            exit()
        for j in range(n):
            if s[j] == i:
                for k in range(1, 5):
                    res.add(s[j:j+k+1])
        if len(res)>=K:
            res = sorted(res)
            print(res[K-1])
            exit()



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
K=int(input())
e=set()
for i in range(len(s)):
    for j in range(1,6):
        if(i+j>len(s)):
            break
        e.add(s[i:i+j])
li=sorted(e)
print(li[K-1])

Submission status: Accepted

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

substring = []

for i in range(min(n, k)):
    for j in range(n-i):
        substring.append(s[j:j+i+1])
        #print(s[j:j+i+1], j, j+i+1)

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

print(substring[k-1])