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

N = len(s)
words = set()
for i in range(N):
    for j in range(i+1, i+K+1):
        w = s[i:j]
        if w not in words:
            words.add(w)

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

Submission status: Accepted

Solution code:
import collections

S = str(input())
len_S = len(S)
K = int(input())
lst = []

for i in range(len_S):
	j = 1
	while i + j <= len_S:
		if j == 6: break
		lst.append(S[i : i + j])
		j += 1
lst.sort()

if K == 1:
	print(lst[0])
else:
	ctr = 1
	for i in range(1, len(lst)):
		if lst[i] != lst[i - 1]:
			ctr += 1
		if ctr == K:
			print(lst[i])
			break

Submission status: Accepted

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

li=set()

for p in range(5):
  for i in range(len(s)-p):
    li.add(s[i:i+1+p])
li=list(li)
li.sort()
#print(li)
print(li[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,min(i+5,len(s))):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()

Submission status: Accepted

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

#print(sub)
subl = list(set(sub))

subl.sort()
#print(subl)
 
print(subl[K-1])

Submission status: Accepted

Solution code:
import collections

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

l = len(s)
sub = set()

if l <= 50:
    for i in range(l):
        for j in range(i+1):
            sub.add(s[j:i+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    #print(subl)
    print(subl[K-1])

else:
    cl = collections.Counter(s).most_common()
    cl.sort(key=lambda x: x[0])
    #print(cl)
    d = 0
    while len(sub) < K:
        be = cl[d][0]
        for i in range(l):
            if s[i] == be:
                for j in range(K):
                    sub.add(s[i:min(i+j+1,l)])
        d += 1
    #print(sub)
    subl = list(sub)
    subl.sort()
    print(subl[K-1])

Submission status: Accepted

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

alpha = [0] * 27
for s in S:
  alpha[ord(s) - ord("a")] += 1

answer = []
for a in range(27):
  if alpha[a]:
    for i in range(N):
      if S[i] == chr(a+ord("a")):
        for j in range(1, 6):
          if i + j > N:
            break
          answer.append(S[i:i+j])
    answer = list(set(answer))
    if len(answer) >= K:
      answer.sort()
      print(answer[K-1])
      exit()

Submission status: Accepted

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

candidate.sort()
print(candidate[k])

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
candidate = []
for i in range(len(s)):
    for j in range(k+1):
        candidate.append(s[i:i+j])
for i in range(len(candidate)):
    candidate[i] = "".join(candidate[i])
candidate = list(set(candidate))
def sort_key(x):
    while len(x) < 5:
        x += "_"
    return x
candidate.sort(key = sort_key)
print(candidate[k])

Submission status: Accepted

Solution code:
# 問題文をよく読んで、制約をヒントに答えを導かないといけない問題

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

result = []

len_s = len(s)
for i in range(len_s):
  for j in range(min(len_s, 5)):
    if s[i:i+j+1]:
      result.append(s[i:i+j+1])

ans = []
for res in sorted(result):
  if not res in ans:
    ans.append(res)
    if len(ans) == K:
      print(ans[K-1])
      exit()

Submission status: Accepted

Solution code:
s = input()
k = int(input())
lst = []
m = min(5,len(s))
while True:
    if m<=0:
        break
    for i in range(len(s)-m+1):
        q = s[i:i+m]
        if not q in lst:
            lst.append(q)
    m -= 1

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

Submission status: Accepted

Solution code:
# K <= 5なので、5まで

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

substr = set()
for i in range(len(s)):
    for j in range(1,6):
        if i + j <= len(s):
            substr.add(s[i:i+j])
substrlist = list(substr)
substrlist.sort()
print(substrlist[K-1])

Submission status: Accepted

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


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

    candidate = set()
    N = len(s)
    for length in range(1,K+1):
        for i in range(N):
            if i+length>N:
                break
            candidate.add(s[i:i+length])
    
    candidate = sorted(list(candidate))
    print(candidate[K-1])
    return


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


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

    index_dict = {}
    for i in range(len(s)):
        if index_dict.get(s[i]) == None:
            index_dict[s[i]] = [i]
        else:
            index_dict[s[i]].append(i)

    value_list = sorted(set(list(s)))
    candidate = set()

    for string in value_list:
        index = index_dict[string]
        for i in index:
            tmp_s = ""
            for j in range(i,len(s)):
                if len(tmp_s) > K:
                    break
                tmp_s += s[j]
                candidate.add(tmp_s)
        if len(candidate) >= K:
            break
    candidate = list(candidate)
    candidate.sort()
    print(candidate[K-1])

    return


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:
s=input()
K=int(input())
a=set()

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

Submission status: Accepted

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

for i in range(K):
    for j in range(len(s)-i):
        a.append(s[j:j+i+1])
a.sort()
cnt=1
i=1
while cnt<K:
    if a[i]!=a[i-1]:
        cnt+=1
    i+=1
print(a[i-1])

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)

def main():
    res = set()
    for l in range(n):
        for r in range(l, min(l+k, n)):
            res.add(s[l:r+1])

    return sorted(res)[k-1]

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
l = []
for i in range(n):
    l.append(s[i])
for i in range(n-1):
    l.append(s[i:i+2])
for i in range(n-2):
    l.append(s[i:i+3])
for i in range(n-3):
    l.append(s[i:i+4])
for i in range(n-4):
    l.append(s[i:i+5])

res = list(set(l))
res.sort()
print(res[k-1])

Submission status: Accepted

Solution code:
from string import ascii_lowercase
s = input()
k = int(input())

sub = []
l = [[] for _ in range(5)]

for i in range(min(len(s),5)):
    if i == 0:
        for c in ascii_lowercase:
            if s.find(c) != -1:
                l[i].append(c)
                sub.append(c)
            if len(l[i]) >= k:
                break
    else:
        for ss in l[i-1]:
            for c in ascii_lowercase:
                tmp = ss + c
                if s.find(tmp) != -1:
                    l[i].append(tmp)
                    sub.append(tmp)
            if len(l[i]) >= k:
                break

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
#k<=5,|s|<=5000
#しらみつぶし
l = []
for i in range(1,min(len(s),k)+1):##
    for j in range(len(s)-i+1):##
        l.append(s[j:j+i])
l = list(set(l))

l.sort()
#print(l)
print(l[k-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)
K = INT()

subs = set()
for i in range(N):
    for j in range(i+1, N+1):
        # K文字以下だけ
        if j-i > K:
            break
        subs.add(S[i:j])

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

Submission status: Accepted

Solution code:
S = input()
K = int(input())
s = set()
for L in range(1,K + 1):
  for j in range(len(S)):
    s.add(S[j:L + j])
ss = sorted(list(s))
print(ss[K - 1])

Submission status: Accepted

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

n = len(s)
strs = set([])

for i in range(n):
    for j in range(i+1, min(i+k+1,n+1)):
        strs.add(s[i:j])
strs = list(strs)
strs.sort()
print(strs[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)
k = int(input())
substring_list = []
sappend = substring_list.append
for i in range(len_s):
    for j in range(5):
        sappend(s[i:min(i+1+j,len_s)])
substring_set = set(substring_list)
print(sorted(substring_set)[k-1])

Submission status: Accepted

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

subs = []
# sからi文字取り出す時の、文字列の組み合わせを全列挙
for i in range(1, 6):
	for j in range(len(s)-i+1):
		subs.append(s[j:j+i])

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

Submission status: Accepted

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

A = []
for i in range(len(s)):
    for j in range(k):
        if i+j+1 > len(s):
            continue
        tmp = s[i:i+j+1]
        A.append(tmp)

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

Submission status: Accepted

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

Submission status: Accepted

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

substr = set()

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

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

Submission status: Accepted

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

# うまいこと全列挙のする方法がわからなかったがこうやれば良いのか...
tmp = set()
for i in range(min(N,K)):
    for j in range(N-i):
        tmp.add(S[j:j+i+1])

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

Submission status: Accepted

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


def solve(s: str, K: int):
    # 解候補
    ans_ls = []
    for i in range(1, K + 1):
        for j in range(0, len(s) - i + 1):
            ans_ls.append(s[j : j + i])
    ans_set = list(set(ans_ls))
    print(sorted(ans_set)[K-1])
# Generated by 1.1.6 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: Accepted

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

Submission status: Accepted

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

one = []
check = set()

for s in S:
    if s not in check:
        one.append(s)
        check.add(s)

ans = set()
one.sort(reverse=True)
for i in range(5):
    if not one:
        break
    first = one.pop()
    ans.add(first)
    for j, s in enumerate(S):
        if s == first:
            length = 1
            while j+length < l and length < 5:
                length += 1
                string = S[j: j+length]
                ans.add(string)
        else:
            continue

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

Submission status: Accepted

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

List = []

for i in range(len(s)):
    for j in range(min(len(s)-i+1, k+1)):
        List.append(s[i:i+j])

set_List = set(List)
List = list(set_List)
List = sorted(List)
List.remove('')

ans = List[k-1]
print(ans)

Submission status: Accepted

Solution code:
s=input()
K=int(input())
n=len(s)
a=[s[i] for i in range(n)]+[s[i:j] for i in range(0, n-1) for j in range(i+2, min(n+1, i+K+1))]
a.sort()
i=1
counter=1
while counter<K:
  if a[i]!=a[i-1]:
    counter+=1    
  i+=1
print(a[i-1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
N = len(S)
K = INT()

min_s = min(S)
B = [s for s in S]
B.sort()
# print(B)

cursol = 0
min_s = 'ATCODER'
cand = []
while len(cand) < K:
	# print(cursol)
	if min_s == B[cursol]:
		cursol += 1
		continue
	else:
		min_s = B[cursol]
	for i,s in enumerate(S):
		if s == min_s:
			for j in range(i+1, i+1+K):
				if not cand.count(S[i:j]): cand.append(S[i:j])
	cursol += 1

cand.sort()
# print(cand)

s = min(S)
cnt = 0
for c in cand:
	cnt += 1
	if cnt == K:
		print(c)
		break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#97c
s = list(str(input()))
K = int(input())

char_place_dict = dict()

#key:文字、value:出てくる座標なdictを作る
for i in range(len(s)):
    if s[i] not in char_place_dict:
        char_place_dict[s[i]] = [i]
    else:
        char_place_dict[s[i]].append(i)
        
all_alphabet = list([chr(i) for i in range(97, 97+26)])

substrings_set = set()
break_flag = 0

s = ''.join(map(str,s))

for char in all_alphabet:
    if char in char_place_dict:
        substrings_set.add(char)
        #print(char)
        
        for place in char_place_dict[char]:
            for i in range(1,6):
                substrings_set.add(s[place:place+i])
                #print(s[place:place+i])
                
        if len(substrings_set)>=K:
            break_flag = 1
            break
        
    if break_flag == 1:
            break
            

substrings_list = list(substrings_set)
substrings_list.sort(reverse=False)
#print(substrings_list)
print(substrings_list[K-1])

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
k = int(input())
if k > n:
    K = n
else:
    K = k
anset = set()
for lenght in range(1,K+1):
    for i in range(n - lenght + 1):
        anset.add("".join(s[i:i+lenght]))
anset = list(anset)
anset.sort()
print(anset[k-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
s = []
ss = []
for i in range(len(S)):
    s.append(S[i:])
s.sort()
for i in range(len(s)-1):
    if s[i] != s[i+1][:len(s[i])]:
        ss.append(s[i])
ss.append(s[-1])
i = 0
while len(ss[i]) < K:
    K -= len(ss[i])
    i += 1
print(ss[i][:K])

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
K = int(input())
ans = []
for start in range(N):
    for end in range(K):
        if start + end >= N:
            break
        sentinel = min(N - 1 , start + end)
        ans.append(S[start:sentinel + 1])

i = 0
ans.sort()
answer = []
while len(answer) < K:
    if not ans[i] in answer:
        answer.append(ans[i])
    i += 1
print("".join(answer[K - 1]))

Submission status: Accepted

Solution code:
# TLE しないはず
s = input()
K = int(input())
T = list(s)
for i in range(2,6):
    for j in range(len(s)-i+1):
        T.append(s[j:j+i])
T = list(set(T))
T.sort()
print(T[K-1])

Submission status: Accepted

Solution code:
S=str(input())
K=int(input())
S_list=list(S)
J=[]
for i in range(len(S)):
  for j in range(i+1,min(i+6,len(S)+1)):
    J += [''.join(S[i:j])]
J=sorted(list(set(J)))
print(J[K-1])

Submission status: Accepted

Solution code:
s=input()
K=int(input())
a=list("abcdefghijklmnopqrstuvwxyz")
l=[]
S=set()
n=len(s)

for c in a:
	j=-1
	for i in range(s.count(c)):
		j+=s[j+1:].find(c)+1
		k=j+1
		while k<=n and k-j<=5:
			S.add(s[j:k])
			k+=1
	if len(S)>=5:
		break

A=sorted(S)
print(A[K-1])

Submission status: Accepted

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

n = len(s)
l = set()

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

l = list(l)
l.sort()

print(l[k-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#C
S = list(str(input()))
N = len(S)
K = int(input())

cand = []
for i in range(N):
    s = S[i]
    cand.append(s)
    for j in range(K):
        if i+j+1 < N:
            s+=S[i+j+1]
            cand.append(s)
            
cand.sort()
old = ""
shin = []
for c in cand:
    if c != old:
        shin.append(c)
        old = c
        
shin.sort()
print(shin[K-1])

Submission status: Accepted

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

minimum_canditates = sorted(set(s))
n_counted = 0

canditates = []


def add_canditate(target_chara):
    global n_counted

    canditates.append(target_chara)
    n_counted += 1
    for c in minimum_canditates:
        next_target = target_chara + c
        if n_counted < K and next_target in s:
            add_canditate(next_target)


for c in minimum_canditates:
    add_canditate(c)

print(canditates[K - 1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def examC():
    S = SI()
    K = I()
    d = set()
    for i in range(len(S)):
        for j in range(5):
            s = S[i:(i+j+1)]
            d.add(s)
    d = list(d)
    d.sort()
    print(d[K-1])

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
k = int(input())
se = set()

for i in range(len(s)):
    temp = ''
    last = min(i+5,len(s))
    for j in range(i,last):
        temp+=s[j]
        se.add(temp)
se = list(sorted(se))
print(se[k-1])

Submission status: Accepted

Solution code:
S = list(input())
k = int(input())
S_sorted = "".join(sorted(list(set(S))))
#print(S_sorted[:5])
Ans = []
counter = 0
for counter in range(0, 10000000):
  Ans_temp = []
  moji = S_sorted[counter]
  Index = [i for i, chr in enumerate(S) if moji == chr]
  for j in range(0, k + 1):
    for index in Index:
      if len(S[index : index+j]) != 0:
        Ans_temp.append("".join(S[index : index+j]))
#  print(Ans_temp)
  Ans = Ans + sorted(list(set(Ans_temp)))
  if len(Ans) >= k:
    break
print(Ans[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
substrings = []
if len(s) < 8:
    for i in range(1, len(s) + 1):
        substrings.extend([s[_:_ + i] for _ in range(len(s) - i + 1)])
else:
    for i in range(1, 8):
        substrings.extend([s[_:_ + i] for _ in range(len(s) - i + 1)])

print(sorted(list(set(substrings)))[k - 1])

Submission status: Accepted

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

def main():
    s = input()
    K = int(input())
    substrings = []

    for i in range(len(s)):
        for ii in range(i,len(s)):
            if len(s[i:ii+1]) > K:
                break
            if s[i:ii+1] not in substrings:
                substrings.append(s[i:ii+1])
    
    substrings.sort()
    print(substrings[K-1])
        

if __name__ == "__main__":
    main()

Submission status: Accepted

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



rank = []
for i in range(len(s)):
    for j in range(i+1, min(i+6,len(s)+1)):
        ss = s[i:j]
        rank.append(ss)

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

Submission status: Accepted

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

list_sub = []
for i in range(len(s)):
  temp = [s[i:i+j] for j in range(1, min(len(s)-i+1, k+1))]
  list_sub += temp

list_sub = list(set(list_sub))
list_sub.sort()

print(list_sub[k-1])

Submission status: Accepted

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

element =[]
for length in range(1,K+1):
    for i in range(len(string)-length+1):
        tmp = string[i:i+length] 

        if tmp not in element:
            element.append(tmp)
print(sorted(element)[K-1])

Submission status: Accepted

Solution code:
from heapq import nsmallest
def main():
    S = input()
    K = int(input())
    N = len(S)
    A = []
    for l in range(N):
        for r in range(l+1, min(N+1, l+K+1)):
            A.append(S[l:r])
    print(nsmallest(K, list(set(A)))[-1])

main()

Submission status: Accepted

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

for l in range(1, K+1):
    for i in range(len(s)+1-l):
        d |= {s[i:i+l]}
	
print(sorted(list(d))[K-1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class SuffixArray(object):
    def __init__(self,s):
        self.__s=s
        self.__n=len(s)
        self.__suffix_array()
        self.__lcp_array()
        self.__sparse_table()

    def __suffix_array(self):
        s=self.__s; n=self.__n
        sa=list(range(n))
        rank=[ord(s[i]) for i in range(n)]
        tmp=[0]*n
        k=1
        cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
        while(k<=n):
            sa.sort(key=cmp_key)
            tmp[sa[0]]=0
            for i in range(1,n):
                tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
            rank=tmp[:]
            k<<=1
        self.__sa=sa
        self.__rank=rank

    def __lcp_array(self):
        s=self.__s; n=self.__n
        sa=self.__sa; rank=self.__rank
        lcp=[0]*n
        h=0
        for i in range(n):
            j=sa[rank[i]-1]
            if(h>0): h-=1
            if(rank[i]==0): continue
            while(j+h<n and i+h<n and s[j+h]==s[i+h]): h+=1
            lcp[rank[i]]=h
        self.__lcp=lcp

    def __sparse_table(self):
        n=self.__n
        logn=max(1,(n-1).bit_length())
        table=[[0]*n for _ in range(logn)]
        table[0]=self.__lcp[:]
        from itertools import product
        for i,k in product(range(1,logn),range(n)):
            if(k+(1<<(i-1))>=n): table[i][k]=table[i-1][k]
            else: table[i][k]=min(table[i-1][k],table[i-1][k+(1<<(i-1))])
        self.__table=table

    @property
    def suffix(self):
        return self.__sa

    def lcp(self,a,b):
        if(a==b): return self.__n-a
        l,r=self.__rank[a],self.__rank[b]
        l,r=min(l,r)+1,max(l,r)+1
        i=max(0,(r-l-1).bit_length()-1)
        table=self.__table
        return min(table[i][l],table[i][r-(1<<i)])

def resolve():
    S=input()
    n=len(S)
    k=int(input())

    sa=SuffixArray(S)
    D=set()
    for i in sa.suffix:
        for j in range(i+1,n+1):
            D.add(S[i:j])
            if(len(D)==k):
                print(sorted(D)[-1])
                return
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class SuffixArray(object):
    def __init__(self,s):
        self.__s=s
        self.__n=len(s)
        self.__suffix_array()
        self.__lcp_array()
        self.__sparse_table()

    def __suffix_array(self):
        s=self.__s; n=self.__n
        sa=list(range(n))
        rank=[ord(s[i]) for i in range(n)]
        tmp=[0]*n
        k=1
        cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
        while(k<=n):
            sa.sort(key=cmp_key)
            tmp[sa[0]]=0
            for i in range(1,n):
                tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
            rank=tmp[:]
            k<<=1
        self.__sa=sa
        self.__rank=rank

    def __lcp_array(self):
        s=self.__s; n=self.__n
        sa=self.__sa; rank=self.__rank
        lcp=[0]*n
        h=0
        for i in range(n):
            j=sa[rank[i]-1]
            if(h>0): h-=1
            if(rank[i]==0): continue
            while(j+h<n and i+h<n and s[j+h]==s[i+h]): h+=1
            lcp[rank[i]]=h
        self.__lcp=lcp

    def __sparse_table(self):
        n=self.__n
        logn=max(0,(n-1).bit_length())
        table=[[0]*n for _ in range(logn)]
        table[0]=self.__lcp[:]
        from itertools import product
        for i,k in product(range(1,logn),range(n)):
            if(k+(1<<(i-1))>=n): table[i][k]=table[i-1][k]
            else: table[i][k]=min(table[i-1][k],table[i-1][k+(1<<(i-1))])
        self.__table=table

    @property
    def suffix(self):
        return self.__sa

    def lcp(self,a,b):
        if(a==b): return self.__n-a
        l,r=self.__rank[a],self.__rank[b]
        l,r=min(l,r)+1,max(l,r)+1
        i=max(0,(r-l-1).bit_length()-1)
        table=self.__table
        return min(table[i][l],table[i][r-(1<<i)])

def resolve():
    S=input()
    n=len(S)
    k=int(input())

    if(n==1):
        print(S)
        return

    sa=SuffixArray(S)
    D=set()
    for i in sa.suffix:
        for j in range(i+1,n+1):
            D.add(S[i:j])
            if(len(D)==k):
                print(sorted(D)[-1])
                return
resolve()

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()
n = int(stdin.readline().rstrip())
li = []

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
n = len(s)
A =[]
import bisect
for i in range(n):
    for j in range(1,K+1):
        sub = s[i:i+j]  
        if sub not in A:
            x = bisect.bisect_left(A,sub)
            A.insert(x,sub)
            if len(A) > K:
                A.pop(K)

print(A[K-1])

Submission status: Accepted

Solution code:
from collections import deque
S = input()
K = int(input())
ans = deque([])
for i in range(K):
  for j in range(len(S) - i):
    ans.append(S[j:j+i+1])
print(sorted(set(ans))[K-1])

Submission status: Accepted

Solution code:
s=input()
k=int(input())
def gets(n,s):
  l=[''.join(s[i:i+n]) for i in range(len(s)-n+1)]
  return l
x=[]
for i in range(1,k+1):
  x+=gets(i,s)
x=sorted(list(set(x)))
print(x[k-1])

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 13:42:36(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    s = sys.stdin.readline().rstrip()
    k = int(sys.stdin.readline().rstrip())
    n = len(s)
    
    substrings = []
    for i in range(1, k+1):
        for j in range(n-i+1):
            substring = s[j:j+i]
            substrings.append(substring)
    substrings = sorted(list(set(substrings)))
    print(substrings[k-1])


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
s=input()
K=int(input())
L=list(s)
S=sorted(set(L))
A=[]

for _ in range(min(3,len(S))):
    H=S[_]
    A.append(H)
    HN=[]
    for i in range(len(L)):
        if L[i]==H:
            HN.append(i)
    for i in HN:
        t=2
        while i+t<len(s)+1 and t<6:
            A.append(''.join(L[i:i+t]))
            t+=1

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

Submission status: Accepted

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

l = []
for i in range(1, K+1):
    for j in range(len(s)+1):
        if j+i > len(s):
            continue
        l.append(s[j:j+i])

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