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:
from heapq import heappush, heappop
S = input()
K = int(input())

H = []
D = {}
for i in range(len(S)):
    heappush(H, (S[i], i, 1))

while K:
    s, i, l = heappop(H)
    if s not in D:
        if K == 1:
            print(s)
            break
        K -= 1
        D[s] = 1
    ne = S[i:i+l+1]
    if ne not in D:
        heappush(H, (ne, i, l+1))

Submission status: Accepted

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

substring=set()
for i in range(len(S)):
  for j in range(1,k+1):
    substring.add(S[i:i+j])
substring=sorted(list(substring))
print(substring[k-1])

Submission status: Accepted

Solution code:
S = list(input())
K = int(input())
st = set()
for i in range(len(S)):
    for j in range(6):
        st.add(''.join(S[i:i+j]))

st_list = sorted(list(st))
if '' in st_list:
    st_list.remove('')
print(st_list[K-1])

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
l=set()
for i in range(n):
    curr=''
    for j in range(i,min(i+7,n)):
        curr+=s[j]
        l.add(curr)
l=[i for i in l]
l.sort()
#print(l)
print(l[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
subs = []
for i in range(len(s)):
  subs += [s[i:i+j] for j in range(1,min(len(s)-i+1,K+1))]

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

Submission status: Accepted

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

slist = []
for i in range(len(s)):
    slist += [s[i:i+j] for j in range(1, min(len(s) - i + 1, K + 1))]

slist = list(set(slist))
slist.sort()

print(slist[K-1])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	s = input()
	K = INT()

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


if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
k=int(input())
lst=list(s)
lst.sort()
ans=[]
for i in range(min(k,n)):
    a=lst[i]
    count=0
    for j in range(n):
        if s[j]==a:
            count+=1
            for l in range(min(5,n-j)):
                ans.append(s[j:j+l+1])
    if count>=5:
        break
ans.sort()
t=1
while t<len(ans):
    if ans[t]==ans[t-1]:
        ans.pop(t)
    else:
        t+=1
print(ans[k-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
str_arr = []

for k in range(1,K+1):
  for i in range(len(S)-k+1):
    str_arr.append(S[i:i+k])
    
print(sorted(set(str_arr))[K-1])

Submission status: Accepted

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

c = []
for i in range(1,6):
	for j in range(len(s)):
		if s[j:j+i] not in c:
			c.append(s[j:j+i])
c.sort()
print (c[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(1, 6):
        a.add(s[i:i + j])
print(sorted(list(a))[k])

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    s = input()
    k = int(input())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

N=len(s)
S=set()
for i in range(N):
    for j in range(i+1,min(i+6,N+1)):
        S.add(s[i:j])
l=sorted(list(S))
print(l[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(1, 6):
        a.add(s[i:i + j])
print(sorted(list(a))[k])

Submission status: Accepted

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

Submission status: Accepted

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

r = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        x = s[i:j]
        r.append(x)
        if len(x) == 5:
            break

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

Submission status: Accepted

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

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        cnt = 0
        for j in range(i, len(s)):
            x = s[i:j+1]
            st.add(x)
            cnt += 1
            # print('cnt', cnt)
            if cnt > 5:
                break
    return sorted(list(st))

r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
# print(r)
print(ans)

Submission status: Accepted

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

S = []
for len_i in range(1,k+1):
	for left_j in range(len(s)-len_i+1):
		cur_s = s[left_j:left_j+len_i]
		if cur_s not in S:
			S.append(s[left_j:left_j+len_i])
S.sort()
# print(S)
print(S[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
lst = []
for end in range(1, min(K+1, len(s)+1)):
    start = 0
    while end < len(s)+1:
        if s[start:end] not in lst:
            lst.append(s[start:end])
        start += 1
        end += 1
lst.sort()
print(lst[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
substrings = set()
index = []
for ss in sorted(list(s)):
  index_list = [n for n, v in enumerate(s) if v == ss]
  for i in index_list:##初期位置
    for j in range(1,min(k+1,len(s)-i+1)):##長さ
      substrings.add(s[i:i+j])
  if len(substrings) >= k:
    break
print(sorted(list(substrings))[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]
  for i in index_list:##初期位置
    for j in range(1,min(k+1,len(s)-i+1)):##長さ
      substrings.append(s[i:i+j])
  if len(set(substrings)) >= k:
    break
print(sorted(list(set(substrings)))[k-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
s = set()
for i in "abcdefghijklnmopqrstuvwxyz":
    for j in range(len(S)):
        if i == S[j]:
            for k in range(K):
                s.add(S[j:j+k+1])
    if len(s) >= K:break
print(sorted(s)[K-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

s=input()
n=len(s)
S=set()
k=int(input())
for j in range(1,k+1):
    for i in range(n-j+1):
        S.add(s[i:i+j])
L=sorted(S)
# print(L)
print(L[k-1])

Submission status: Accepted

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

dic={}
for i in range(len(s)):
    dic[s[i]]=1
    
dic=sorted(dic,key=lambda x:x[0])
check=0
se=set()
for i in dic:
    for j in range(len(s)):
        if s[j]!=i:
            continue
        k=j+1
        se.add(i)
        sss=i
        while k<len(s):
            sss+=s[k]
            se.add(sss)
            k+=1
            if k-j>kk:
                break
    if len(se)>=kk:
        break
se=sorted(list(se))
print(se[kk-1])

Submission status: Accepted

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

for k in range(1, K+1):
    for j in range(len(s)):
        if j+k == len(s)+1:
            break
        t.add(s[j:j+k])
t = sorted(t)
print(t[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
N = len(s)
substrs = []
for i in range(N):
    substrs.append(s[i:])
substrs.sort()
k = 0
prev = ''
for t in substrs:
    L = min(len(prev),len(t))
    i = 0
    while i < L and prev[i] == t[i]:
        i += 1
    for j in range(i+1,len(t)+1):
        k += 1
        if k == K:
            print(t[:j])
            exit()
    prev = t

Submission status: Accepted

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

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)<K:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
sub = []
for i in range(len(S)):
  range = 1
  while range < K + 1 and len(S) >= (i + range):
    sub.append(S[i:i+range])
    range += 1
sub = sorted(set(sub))
print(sub[K-1])

Submission status: Accepted

Solution code:
s = input()
n = int(input())
S = set()
for i in "abcdefghijklmnopqrstuvwxyz":
    for j in range(len(s)):
        if i == s[j]:
            for k in range(n):
                S.add(s[j:j+k+1])
    if len(S) >= 5:break
S = sorted(S)
print(S[n-1])

Submission status: Accepted

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

# K <= 5なので5文字のsubstringまで調べれば十分
substrings = set()
for length in [1,2,3,4,5]:
    for idx in range(len(s)):
        if len(s[idx:idx+length]) == length:
            substrings.add(s[idx:idx+length])

substrings = list(substrings)
substrings.sort()

print(substrings[K-1])

Submission status: Accepted

Solution code:
def main():
    s = str(input())
    N = int(input())
    l = len(s)
    string = []
    for i in range(l):
        for j in range(min(5,l-i)):
            a = s[i:i+j+1]
            string.append(a)

    string = list(set(string))
    string.sort()
    print(string[N-1])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for s in range(N):
    for e in range(s+1,min(N+1,s+1+K+1)):
        Data.add(S[s:e])
print(sorted(Data)[K-1])

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()
k = I()
L = []
for i in range(len(s)):
    for j in range(i + 1, i + 1 + k):
        L.append(s[i:j])



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

Submission status: Accepted

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

words = []

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

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
n = len(s)
substring = []

for i in range(n):
    tmp = ""
    for l in s[i:i + k:]:
        tmp += l
        if tmp in substring:
            continue

        else:
            substring.append(tmp)

substring.sort()

print(substring[k - 1])

Submission status: Accepted

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

# Sのsubstring全列挙を行う
ans = []

for i in range(len(S)):
    for j in range(i+1, i+K+1):
        ans.append(S[i:j])

ans = list(set(ans))
ans.sort()

print(ans[K-1])

Submission status: Accepted

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

s_set = set()

for i in range(len(s)):
    sub_s = s[i]
    s_set.add(sub_s)
    for j in range(i+1, len(s)):
        sub_s += s[j]
        s_set.add(sub_s)
        if len(sub_s) == 5:
            break


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
can = []
for i in range(1,K+1):
    for j in range(0,N-i+1,1):
        s = S[j:j+i]
        if s not in can:
            can.append(s)
print(sorted(can)[K-1])

Submission status: Accepted

Solution code:
s=list(input())

K=int(input())

L=[]

for i in range (1,K+1):
    for j in range (0, len(s)-i+1):
        L.append("".join(s[j:j+i]))

L=sorted(set(L))

print(L[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())
S = []

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

Submission status: Accepted

Solution code:
s = input().strip()
K = int(input())
B = []
for i in range(len(s)):
    for j in range(1,K+1):
        if i+j<=len(s):
            B.append(s[i:i+j])
B = sorted(set(B))
print(B[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n = len(s)

l = []

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

l.sort()

index = 0
while k > 0:
  if k == 1:
    print(l[index])
    k = 0
  else:
    index += 1
    k -= 1
    while l[index - 1] == l[index]:
      index += 1

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ret = []
slen = len(s)
for i in range(1, 5 + 1) :
    for j in range(slen - i + 1) :
        t = s[j:j+i]
        if not t in ret :
            ret.append(t)
        if len(ret) > K :
            ret.sort()
            ret.pop()
            
print(ret[-1])

Submission status: Accepted

Solution code:
def main():
  join = ''.join
  def getCharNGram(n,s):
      charGram = [join(s[i:i+n]) for i in range(len(s)-n+1)]
      return charGram
  S = input()
  K = int(input())
  ans = []
  from collections import Counter
  for i in range(K,0,-1):
      l = getCharNGram(i,S)
      ans= ans+l
  ans = list(set(ans))
  ans.sort()
  print(ans[K-1])
main()

Submission status: Accepted

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

L = []
for i in range(len(s)):
    L.append(s[i])
    
L.sort()
cnt = 0
for i in range(len(L)):
    if L[i] == L[0]:
        cnt += 1

word_list = []
idx = 0
if len(s) >= 20:
    if cnt <= 5:
        while idx < len(s):
            if s[idx] == L[0] or s[idx] == L[cnt]:
                for j in range(1, K+1):
                    word_list.append(s[idx:idx+j])
            idx += 1
    else:
        while idx < len(s):
            if s[idx] == L[0]:
                for j in range(1, K+1):
                    word_list.append(s[idx:idx+j])
            idx += 1
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            word_list.append(s[i:j])
    
word_set = set(word_list)
word_list = list(word_set)
word_list.sort()
print(word_list[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

subs = set()

for i in range(1, min(N,K)+1):
    for j in range(N-i+1):
        subs.add(S[j:j+i])

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

Submission status: Accepted

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

d = set()
header, i = sorted(list(set(s))), 0
while len(d) <= K and i < len(header):
    indexes = [j for j, x in enumerate(s) if x == header[i]]
    for j in indexes:
        for k in range(j+1, min(j+K, len(s))+1):
            d.add(''.join(s[j:k]))
    i += 1
d = sorted(list(d))
print(d[K-1])

Submission status: Accepted

Solution code:
s = input()
n = int(input())
ans = "zzzzz"
anslist = set()
for i in range(0,5):
    for j in range(0,5):
        if i < j <= len(s):
            if i != 0:
                anslist.add(s[-j:-i])
            else:
                anslist.add(s[-j:])
for i in range(len(s)-5):
    if s[i:i+5] < ans:
        ans = s[i:i+5]
for i in range(1, 6):
    anslist.add(ans[0:i])
anslist = list(anslist)
anslist.sort()
print(anslist[n-1])

Submission status: Accepted

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

tmp = set()
for i in range(len(s)):
    for j in range(5, 0, -1):
        tmp.add(s[i:i + j])

tlst = list(tmp)
tlst.sort()

print(tlst[K - 1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s_sub = list([''])
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])

s_sub.sort()

sum = 0
for j in range(1,s_len+2):
    
    current = s_sub[j]
    before = s_sub[j-1]

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
            
    pre = sum +len(current) - z
    if pre >= K:
        print(current[:K-sum+z])
        break
    sum = pre

Submission status: Accepted

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

s_sub = list()
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])
    
s_sub.sort()
s_sub.append('')

pre_sum = 0
sum = len(s_sub[0])
z=0
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    
    if sum >= K:
        print(before[:K-pre_sum+z])
        break

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
    pre_sum =  sum 
    sum += len(current) - z

Submission status: Accepted

Solution code:
S = input()
K = int(input())
str_set = set()
for i in range(1, 6):
  for n in range(len(S)):
    if i + n <= len(S):
      str_set.add(S[n:i+n])
str_set = list(str_set)
str_set.sort()
print(str_set[K-1])

Submission status: Accepted

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

s_head = sorted(list(set(s)), reverse=True)
res = [s_head.pop()]
while len(res) < k:
    tmp = res[-1]
    tmp_list = []
    for i in range(len(s)-len(tmp)):
        if s[i:i+len(tmp)] == tmp:
            tmp_list.append(s[i:i+len(tmp)+1])
    if len(tmp_list) == 0:
        res.append(s_head.pop())
    elif min(tmp_list) == tmp:
        res.append(s_head.pop())
    else:
        res.append(min(tmp_list))

print(res[k-1])

Submission status: Accepted

Solution code:
# ABC097 C - K-th Substring
s = input()
k = int(input())

n = len(s)
d = set()
l = []

for i in range(k):
    for j in range(n-i):
        d.add(s[j:j+i+1])
l = list(d)
l.sort()

print(l[k-1])

Submission status: Accepted

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

unigram = sorted(set(S))

for u in unigram:
  now_subset = set()
  for i,c in enumerate(S):
    if c != u: continue
    for j in range(1,min(K,len(S)-i)+1):
      now_subset.add(S[i:i+j])
  if len(now_subset) < K:
    K -= len(now_subset)
  else:
    print(sorted(now_subset)[K-1])
    exit()

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

Submission status: Accepted

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

S = [ss for ss in s]
S_set = list(set(S))
S_set.sort()

substring = []
for c in S_set:
  idx_c = [i for i, x in enumerate(s) if x == c]
  substring_c = []
  for x in idx_c:
    for dx in range(1, min(5, len(s)-x)+1):
      substring_c.append(s[x:x+dx])
  substring_c = list(set(substring_c))
  substring += substring_c
  if len(substring) >= 5:
    break

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
k = []

for i in range(len(s)):
  if s[i] not in k:
    k.append(s[i])
  
if len(s) >= 2:
  for i in range(len(s)-1):
    if s[i] + s[i+1] not in k:
      k.append(s[i] + s[i+1])
    
if len(s) >= 3:
  for i in range(len(s)-2):
    if s[i] + s[i+1] + s[i+2] not in k:
      k.append(s[i] + s[i+1] + s[i+2])
    
if len(s) >= 4:
  for i in range(len(s)-3):
    if s[i] + s[i+1] + s[i+2] + s[i+3] not in k:
      k.append(s[i] + s[i+1] + s[i+2] + s[i+3])
    
if len(s) >= 5:
  for i in range(len(s)-4):
    if s[i] + s[i+1] + s[i+2] +s[i+3] + s[i+4] not in k:
      k.append(s[i] + s[i+1] + s[i+2] +s[i+3] + s[i+4])
    
new = sorted(k)

print(new[K-1])

Submission status: Accepted

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

    s_l = sorted(set(s))
    ans = set()
    cnt = 0
    for i in s_l:
        ans.add(i)
        cnt += 1
        if cnt >= K:
            break
        cur = set()
        for j in range(len(s)):
            if not s[j] in cur or s[j] == i:
                cur.add(s[j:min(j+5,len(s))])
        for c in cur:
            cnt += 1
        for c in cur:
            for k in range(5):
                ans.add(c[:min(k+1,len(c))])
        if cnt >= K:
            break
        print(ans)
    print(sorted(ans)[K-1])
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    S = input().strip()
    K = int(input())
    D = [[] for _ in range(26)]
    for i,c in enumerate(S):
        d = D[ord(c)-ord("a")]
        for j in range(5):
            s = S[i:i+j+1]
            if s != "" and s not in d:
               d.append(s)
    for d in D:
        d.sort()

    k = 1
    for d in D:
        for s in d:
            if k == K:
                print(s)
                return
            k += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
K = int(input())
w = []
for i in range(len(s)):
  for j in range(i,min(i+K,len(s))):
    temp = s[i:j+1]
    if temp not in w:
      w.append(temp)
      
w.sort()
print(w[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    K = int(inputs[1])

    sets = set()
    for i in range(len(S)):
        j = i
        while j < len(S) and j - i <= K:
            j += 1
        sets.add(S[i:j])
    new_sets = set()

    for k in sets:
        for i in range(len(k)):
            j = i
            while j < len(k) and j - i <= K:
                j += 1
                new_sets.add(k[i:j])
    l = list(new_sets)
    l.sort()
    return l[K-1]


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
text=input()
K=int(input())
N=len(text)
dic={}
for i in range(N):
  dic[text[i:i+5]]=1
ls=list(dic)
ls.sort()
dic2={}
for e in ls[0:K]:
  for i in range(len(e)):
    dic2[e[0:i+1]]=1
ls2=list(dic2)
ls2.sort()
print(ls2[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
sub = []

for i in range(k):
  for j in range(len(s)-i):
    sub.append(s[j:j+i+1])
    
print(sorted(list(set(sub)))[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
a = sorted(set(s))
ans = set()

for i in a:
    for j in range(len(s)):
        if s[j] == i:
            for k in range(5):
                ans.add(s[j:j + k + 1])
    if len(ans) >= K:
        print(sorted(list(ans))[K - 1])
        exit()

Submission status: Accepted

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

N = len(s)
Ans = ["z"*5000]*5
for i in range(N):
    for j in range(i,min(N,i+5)):
        tmp = s[i:j+1]
        for k in range(5):
            if Ans[k] > tmp:
                if not (tmp in Ans):
                    for l in range(4-k):
                        Ans[4-l] = Ans[3-l]
                    Ans[k] = tmp
                    break       
print(Ans[K-1])

Submission status: Accepted

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

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

a = sorted(list(set(substring)))

print(a[k - 1])

Submission status: Accepted

Solution code:
import bisect

def main():
    s = input()
    k = int(input())
    n = len(s)
    dp = []
    for l in range(n):
        for r in range(l + 1, min(n + 1, l + 6)):
            t = s[l:r]
            i = bisect.bisect_right(dp, t)
            if i > 0:
                if t == dp[i - 1]: continue
            if len(dp) < k:
                bisect.insort(dp, t)
            elif t < dp[-1]:
                dp.pop()
                bisect.insort(dp, t)
    print(dp[-1])

main()

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
sub = []
for i in range(1, min(len(s) + 1, k + 1)):
    for j in range(1, len(s) + 2 - i):
        if not([s[s_i - 1] for s_i in range(j, j + i)] in sub):
            sub.append([s[s_i - 1] for s_i in range(j, j + i)])
sub.sort()
print(''.join(sub[k-1]))

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline()))
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

s =  sys.stdin.readline().rstrip()
K =  int(sys.stdin.readline())


current = s[0]
cnt = 0
L = []
for stride in range(1, K + 1):
    for i in range(len(s) - stride + 1):
        L.append(s[i:i + stride])

print(sorted(list(set(L)))[K - 1])

Submission status: Accepted

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

import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

f = defaultdict(lambda : 0)
s = input()
k = I()
n = len(s)
for i in range(1,k+1):
    for j in range(n-i+1):
        f[s[j:j+i]] = 1
f = sorted(f.items())
print(f[k-1][0])