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

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



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

    d = defaultdict(list)
    for i in range(n):
        d[s[i]].append(i)


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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
	s = input()
	k = int(input())
	cnt = set()
	for i in range(len(s)):
		for j in range(1, k+1):
			if j > k:
				break
			cnt.add(s[i:i+j])
	v = sorted(list(cnt))[k-1]
	print(v)
resolve()

Submission status: Accepted

Solution code:
from collections import deque
s=list(input())
K=int(input())
#max(K)=5でaaaaaはa,aa,aaa,aaaa,aaaaaの順
#よって5文字まで取れば良い
d=deque()
for i in range(len(s)):
    d.append(s[i])
comp=[]
#print(d)
for i in range(len(s)):
    buf=deque()
    for j in range(len(d)):
        v=d.popleft()
        buf.append(v)
        if j<5:
            comp.append("".join(buf))
    d=deque()
    for j in range(len(buf)):
        d.append(buf[j])
    d.popleft()
comp=list(set(comp))
comp.sort()
print(comp[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    places = defaultdict(list)
    for i in range(N):
        places[S[i]].append(i)

    places = sorted(places.items(), key=lambda x: x[0])
    words = set()
    for k, v in places:
        for start in v:
            cnt = 0
            for end in range(start + 1, N + 1):
                words.add(S[start:end])
                cnt += 1

                if cnt == 5:
                    break

        if len(words) >= 5:
            break

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
S_list = sorted(set(list(S)))

memo = {}

for small_char in S_list:
    for i in range(N):
        if S[i] == small_char:
            for j in range(i+1, i+K+1):
                word = S[i:j]
                memo[word] = None
    if len(memo) >= K:
        break

ans_list = sorted(list(memo.keys()))
print(ans_list[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
k=I()
n=len(s)
strs=[]
for i in range(n):
    for j in range(1,k+1):
        strs.append(s[i:i+j])
print(sorted(list(set(strs)))[k-1])

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pri = lambda x: print(*x, sep='\n')

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

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

Submission status: Accepted

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


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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    K = int(input())
    r = set()
    for i in range(97, 97 + 26):
        for j, v in enumerate(s):
            if v == chr(i):
                for k in range(5):
                    r.add(s[j:j+k+1])
        if len(r) > 5:
            break
    l = list(r)
    l.sort()
    return l[K-1]
print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

s = input()
K = getN()

# K <= 5なのでS[i] ~ s[i:i + k]までを取り出すだけでOK
sub = set()
for k in range(1, 6):
    for i in range(len(s)):
        sub.add(s[i:i + k])

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

Submission status: Accepted

Solution code:
from itertools import*;s=input();k=int(input());print(sorted(set(s[i:j]for i,j in combinations(range(len(s)+1),2)if j-i<=k))[k-1])

Submission status: Accepted

Solution code:
from itertools import*
s = input()
k = int(input())
l = len(s)
print(sorted(set(s[i:j] for i, j in combinations(range(l+1), 2) if j - i <= k))[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

'''
alphabets = list('abcdefghijklmnopqrstuvwxyz')
l = []

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

    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()
'''
l = []
for i in range(N):
    for j in range(1, K+1):
        if i+j-1 < N:
            l.append(S[i:i+j])

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

Submission status: Accepted

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

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


alphabets = list('abcdefghijklmnopqrstuvwxyz')
l = []

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

Submission status: Accepted

Solution code:
S, k = open(0).read().split()
k = int(k)
x = set(sorted(S)[:min(k, len(S))])
A = set()
for i, c in enumerate(S):
    if c in x:
        s = ''
        for j in range(i, min(i+k, len(S))):
            s += S[j]
            A.add(s)
print(sorted(A)[k-1])

Submission status: Accepted

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

cand = []

ilis = sorted(range(len(s)), key=lambda k: s[k])

visited = set()

for i in range(len(s)):
    for j in range(5):
        cand.append(s[ilis[i]:ilis[i]+j+1])

cand.sort()

ret = sorted(list(set(cand)))

print(ret[k-1])

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
ngrams = set(S)
for n in range(2, 6):
    for i in range(N - n + 1):
        ngrams.add(S[i:i + n])
print(sorted(ngrams)[K - 1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
K = int(input())
substr= []
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        substr.append(s[k: k + i])
substr = sorted(list(set(substr)))
print(substr[K - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
  for j in range(k):
    l = s[i:(i+j+1)]
    if l in ans:
      continue
    bisect.insort_left(ans,l)
  ans = ans[:k]
print(ans[-1])

Submission status: Accepted

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

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 #length = n
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    
chars=chars|subset(s[max(l-10,0):],0)
for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)

#print(min_c,chars)

'''
for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])
'''

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

Submission status: Accepted

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

ans = []
table ={}

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

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

Submission status: Accepted

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

ans = []
table ={}

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

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

Submission status: Accepted

Solution code:
A="abcdefghijklmnopqrstuvwxyz"
S=input()
k=int(input())
n=len(S)

C=[]

for a in A:
    now=""
    cnt=0
    if not a in S:
        continue
    for i in range(n):
        if S[i]==a:
            for j in range(5):
                if i+j<n:
                    C.append(S[i:i+j+1])
                else:
                    break
    C.sort()
    for c in C:
        if now!=c:
            now=c
            cnt+=1
        if cnt==k:
            break
    if cnt==k:
        break
print(now)

Submission status: Accepted

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

words = []

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

words.sort()

ans = set()

for word in words:
    for i in range(len(word)):
        ans.add(word[:i+1])
    if len(ans) >= 5:break
lst = list(ans)
lst.sort()

print(lst[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

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


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


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

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

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

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

    return arr

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

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

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

# 素数判定



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

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

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

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

    else:
        ret = []

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

        for i in S:

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

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

        return ret


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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    k = int(input())
    d = len(s)
    m = set()
    if k >= d:
        for i in range(d):
            for j in range(1, d - i + 1):
                m.add(s[i:i + j])
    else:
        for i in range(d):
            for j in range(1, k + 1):
                m.add(s[i:i + j])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    k = int(input())
    d = len(s)
    m = set()
    if k >= d:
        for i in range(d + 1):
            for j in range(1, d - i + 1):
                m.add(s[i:i + j])
    else:
        for i in range(d):
            for j in range(1, k + 1):
                m.add(s[i:i + j])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    for l in range(1, K+1):
        for i in range(len(S)):
            subs.add(S[i: i+l])
            # スライスのストップ条件はインデックス外でもよい

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

abc097_c()

Submission status: Accepted

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

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

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

abc097_c()

Submission status: Accepted

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

    N = len(S)

    st = set()

    for left in range(N):
        for right in range(left+1,N+1):
            if right - left > K:
                break
            st.add(S[left:right])
    
    tmp = list(st)
    tmp.sort()
    print(tmp[K-1])

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

anslist = sorted(list(ansset))

print(anslist[k-1])

Submission status: Accepted

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

Submission status: Accepted

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


def dfs(sub, i):
  if sub in s:
    i += 1
    if i == k:
      print(sub)
      exit()
    for c in range(ord('a'), ord('z') + 1):
      c = chr(c)
      i = dfs(sub + c, i)
  return i
  
dfs('', -1)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()
    K=int(readline())

    N=len(s)
    words=[]
    for i in range(N):
        words.append(s[i])
    for i in range(N-1):
        words.append(s[i:i+2])
    for i in range(N-2):
        words.append(s[i:i+3])
    for i in range(N-3):
        words.append(s[i:i+4])
    for i in range(N-4):
        words.append(s[i:i+5])
    words=set(words)
    words=list(words)
    words.sort()
    print(words[K-1])
    
if __name__=="__main__":
    main()

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:i+j])
S = list(S)
S.sort()
print(S[K-1])

Submission status: Accepted

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

for i in range(n):
  if n+1>=i+6:
    l+=[s[i:j] for j in range(i+1,i+6)]
  else:
    l+=[s[i:j] for j in range(i+1,n+1)]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

class dd:
	def __init__(self, k):
		d='zzzzzz'
		self.v = [d]*k
		#self.v[0]='a'
		#pa(self.v)
		
	def add(self, v):
		if v in self.v:
			pass
		elif self.v[-1] <= v:
			pass
		else:
			for i,c in enumerate(self.v):
				if v < c:
					self.v = self.v[:i]+[v]+self.v[i:-1]
					break
		#pa((v, self.v))
				
	def get(self):
		return self.v[-1]


def main():
	#a = int(input())
	#b , c = IN()
	s = input()
	k = int(input())
	rs=dd(k)
	for i in range(1, 5+1):
		for j in range(len(s)-i+1):
			v = s[j:j+i]
			rs.add(v)
			
	r=rs.get()
	print(r)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

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())
print(sorted(list({s[i:i+f] for i in range(len(s)) for f in range(1,k+1)}))[k-1])

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc097/tasks/arc097_a
# 0:37-0:50 chudan
# 12:14-12:20
# 12:30-
# 14:40-14:53


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

    def rec(tree, substr):
        if len(substr) > 0:
            ans.append(substr)

        if len(ans) == K:
            return None

        keys = sorted(tree.keys())
        for key in keys:
            rec(tree[key], substr+key)
    
    min_char_list = sorted(list(set(S)))

    ans = []
    for min_char in min_char_list:
        if len(ans) >= K:
            break

        min_char_i = []
        for i, s in enumerate(S):
            if s == min_char:
                min_char_i.append(i)

        substrs = []
        for i in min_char_i:
            substrs.append(S[i:min(i+(K-len(ans)), N)])

        prefix_tree = {}
        for substr in substrs:
            tree = prefix_tree
            for c in substr:
                if c not in tree:
                    tree[c] = {}
                tree = tree[c]

        # prefix tree starting the minimum letter: created

        rec(prefix_tree, "")

    return ans[K-1]


print(main())

Submission status: Accepted

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

x = set(list(S))

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

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

Submission status: Accepted

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

target_ls = []
for start in range(len(s)):
    for length in range(1,k+1):
        target_ls.append(s[start:start + length])
unique_ls = list(set(target_ls))
unique_ls.sort()
print(unique_ls[k-1])