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 = str(input())
K = int(input())

def find(str):
	lt = []
	for start in range(len(str)):
		for end in range(start + 1, len(str) + 1):
			lt.append(str[start:end])
	lt = list(set(lt))
	lt.sort()

	return lt

s_pt = list(set(list(s)))
s_pt.sort()
ans = []
for i in range(min(5, len(s_pt))):
	ind = [ix for ix, x in enumerate(s) if x == s_pt[i]]
	for j in ind:
		ans += find(s[j:min(j+5, len(s))])
	ans = list(set(ans))
	if len(ans) >= 5:
		break
ans = list(set(ans))
ans.sort()
print(ans[K-1])

Submission status: Accepted

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

    cand = set()
    for e,c in enumerate(s):
        for i in range(1, K+1):
            if e+i > len(s): break                
            sub = s[e:e+i]
            cand.add(sub)
    cand = list(cand)
    cand.sort()

    print(cand[K-1])

    
    
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

C = list(set(S[i:i + j + 1] for i in range(N) for j in range(K) if i + j < N))
C.sort()
print(C[K - 1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
S = set()
ans = []

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math

# def compare_each(a, b):
#     """辞書で比べる，もしaの方が小さければ，false，大きければtrue"""
#     if a is None:
#         return True
#     len_a = len(a)
#     len_b = len(b)
#     length = min(len_a, len_b)
#     for i in range(length):
#         if ord(a[i]) < ord(b[i]):
#             return False
#         elif ord(a[i] > b[i]):
#             return True
#     if len_a <= len_b:
#         return False
#     else:
#         return True

# def compare(str_, str_lists, K):
#     """str_listsは昇順で並んでいる．ここにstr_が入るのか戦う"""
#     for i in range(K, 0, -1):
#         print(str_lists[i - 1], str_)
#         if compare_each(str_lists[i - 1], str_):
#            str_lists.insert(i - 1, str_)
#            break
#     return str_lists[:K]


def main():
    s = input()
    K = int(input())
    str_lists = []
    for str_num in range(1, K + 1):
        for i in range(len(s)):
            str_ = s[i: i + str_num]
            if str_ not in str_lists:
                str_lists.append(str_)
    str_lists = sorted(str_lists)
    print(str_lists[K - 1])
    
            

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = set()
for i in range(1, 6):  # i文字
    for j in range(n - (i - 1)):  # j回
        a.add(s[j:j + i])
print(sorted(a)[K - 1])

Submission status: Accepted

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

l = len(s)
o = []
for j in range(1,6):
    for i in range(l):
        a = s[i:i+j]
        if not(a in o):
            o.append(a)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
head = [h for h in s]

head = set(head)
head = list(head)
head.sort()

cnt = 0
ans = []
idx = 0
while cnt < K:
    for i in range(len(s)):
        if s[i] == head[idx]:
            for k in range(i+1, min(len(s)+1, i+6)):
                ans.append(s[i:k])
        ans = set(ans)
        ans = list(ans)
        cnt = len(ans)
    idx += 1
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# a〜z
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

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

l2=[]

a=''
for x in l:
  if x in s:
    a=x
    for i in range(len(s)):
      if s[i]==a:
        for j in range(6):
          l2.append(''.join(s[i:i+j]))

l2=list(set(l2))
l2.remove('')
l2.sort()
print(l2[K-1])

Submission status: Accepted

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

res = []
charGram = [[''.join(s[i:i + n]) for i in range(len(s) + 1 - n)] for n in range(1,K + 1)]

for i in range(len(charGram)):
    res += charGram[i]

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

Submission status: Accepted

Solution code:
from sys import stdin
s=stdin.readline().rstrip()
K=int(stdin.readline().rstrip())
subs=[]
for i in range(K):
  for j in range(0, len(s)-i):
    subs.append(s[j:j+i+1])
subs=list(set(subs))
subs.sort()
print(subs[K-1])

Submission status: Accepted

Solution code:
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            if (j+1 - i) > k:
                break

            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

t = []

for i in range(len(s)):
    string = ""
    if i < 4:
        for j in range(0,i+1):
            string = s[i-j] + string
            if string not in t:
                t.append(string)
            else:
                continue
    else:
        for j in range(0,5):
            string = s[i-j] + string
            if string not in t:
                t.append(string)
            else:
                continue
t.sort()
print(t[n-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
l=set()
for i in range(len(s)):
    for j in range(5):
        if i+j>len(s)-1:
            continue
        l.add(s[i:i+j+1])
list=list(l)
list.sort()
print(list[K-1])

Submission status: Accepted

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

sub = []
for i in range(1, K+1):
    for k in range(len(s)-i+1):
        sub.append(s[k:k+i])

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(s)):
    S.add(s[i])
    for j in range(i+1, K+i+1):
        ss = ''
        if j >= len(s):
            continue
        ss = s[i] + s[i+1:j+1]
        S.add(ss)
        
S = list(S)
S.sort()

print(S[K-1])

Submission status: Accepted

Solution code:
S = [i for i in input()]
K = int(input())
chars = []
i =0
for i in range(len(S)):
    for j in range(1,K+1):
        chars.append("".join(S[i:i+j]))
chars=sorted(set(chars))
print(chars[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        break

key = i

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


s = IS()
K = II()
substring = []
for i in range(1,K+1):
    for j in range(len(s) - i + 1):
        substring.append(s[j:j+i])
print(sorted(set(substring))[K-1])

Submission status: Accepted

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

a = sorted(set(s))[:5]
for num in range(2,6):
  if len(s) >= num:
    b = sorted(set([s[i:i+num] for i in range(len(s)-num+1)]))[:5]
    a.extend(b)
  else:
    break

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

Submission status: Accepted

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

a = sorted(set(s))[:5]
if len(s) >= 2:
  b = sorted(set([s[i:i+2] for i in range(len(s)-1)]))[:5]
  a.extend(b)
if len(s) >= 3:
  c = sorted(set([s[i:i+3] for i in range(len(s)-2)]))[:5]
  a.extend(c)
if len(s) >= 4:
  d = sorted(set([s[i:i+4] for i in range(len(s)-3)]))[:5]
  a.extend(d)
if len(s) >= 5:
  e = sorted(set([s[i:i+5] for i in range(len(s)-4)]))[:5]
  a.extend(e)

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

Submission status: Accepted

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

strs = set()
for k in range(1, K+1):
    for i in range(len(s)+1-k):
        strs.add(s[i:i+k])

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

Submission status: Accepted

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

s1 = list(set(s.copy()))
s1.sort()
for i in range(5):
  s.append('')

if(len(s1) >=3):  n1 = 3
else:  n1 = len(s1)
first = []
for i in range(n1):
  first.append(s1[i])

s2 = []
for i in range(n):
  for j in first:
    if(s[i] == j):
      s2.append(s[i]),s2.append(s[i]+s[i+1]),s2.append(s[i]+s[i+1]+s[i+2])
      s2.append(s[i]+s[i+1]+s[i+2]+s[i+3]),s2.append(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
s2 = list(set(s2))
s2.sort()
ans = s2[K-1]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import string
import itertools

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

def it(s):
    subs = sorted(s[i:] for i in range(len(s)))
    writed = set()
    for sub in subs:
        for i in range(len(subs)):
            w = sub[:i+1]
            if w not in writed:
                yield w
                writed.add(w)

for ans in itertools.islice(it(s), k-1, k):
    print(ans)

Submission status: Accepted

Solution code:
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(input())])

Submission status: Accepted

Solution code:
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(len(s)*6)})[int(input())])

Submission status: Accepted

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

L = sorted(L)

sub = ""
x = 0
for i in L:
	if sub != i:
		sub = i
		x += 1
	
	if x == K:
		print(sub)
		break

Submission status: Accepted

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

for i in range(len(s)):
    S.add(s[i])
    S.add(s[i:i+2])
    S.add(s[i:i+3])
    S.add(s[i:i+4])
    S.add(s[i:i+5])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input();print(sorted(set(s[t:t+i]for t in range(len(s))for i in range(1,9)))[int(input())-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

chars = sorted(set(s))
n = len(s)

for j in range(min(3, len(chars))):
  ans = chars[j]
  K -= 1
  if K == 0:
    print(ans)
    break
  while True:
    places = []
    index = -1
    while True:
      index = s.find(ans, index+1)
      if index == -1:
        break
      places.append(index)
      
    if len(ans) == len(s) - places[0]:
      break

    next_char = 'z' * 6
    for k in places:
      if k >= len(s)-len(ans):
        break
      next_char = min(next_char, s[k+len(ans)])

    ans += next_char
    K -= 1
    if K == 0:
      print(ans)
      sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]
    input_raw = read_func().strip().split()
    [K] = [int(input_raw[0])]
##    if len(S) >= K:
##        min_s = "zzzzzzz"
##        for i in range(len(S) - K):
##            if S[i : i + K]< min_s:
##                min_s = S[i : i + K]
##        print min_s
##        return
##    else:
    sub_list = set([])
    for i in range(len(S)):
        for j in range(i + 1, i + 6):
            sub_list.add(S[i:j])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

keys = []
for start in range(len(s)):
  for end in range(start+1, min(start+6, len(s)+1)):
    key = s[start:end]
    if key in keys:
      continue
    if len(keys) < 5:
      keys.append(key)
      keys.sort()
    elif keys[-1] > key:
      keys.append(key)
      keys.sort()
      keys = keys[:-1]
print(keys[k-1])

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
koho=[]
for i in range(n):
    for j in range(k):
        if len(s[i:i+j+1])<=k:
            koho.append(s[i:i+j+1])

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
l=len(s)
d=[[s[i],l-i] for i in range(len(s))]
d=sorted(d)
h=dict()
ans=0
ca=d[0][0]   

for i in d:
    if(i[0]!=i[0][0]):
        break
    z=min(i[1]+1,6)
    for j in range(1,z):
        if(s[l-i[1]:l-i[1]+j] not in h):
            ans+=1
            h.update({s[l-i[1]:l-i[1]+j]:1})
        else:
            pass


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

Submission status: Accepted

Solution code:
def solve(s, k):
    buff = []
    for start in range(len(s)):
        for end in range(1, k+1):
            if start + end > len(s):
                continue
            buff.append(s[start:start+end])
    buff = list(set(buff))
    buff.sort()
    return buff[k-1]

def main():
    s = input()
    k = int(input())
    ans = solve(s, k)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
p=[chr(ord("a")+i)for i in range(26)]
l=[]
for i in range(26):
    if p[i] in s:
        h=[j for j,x in enumerate(s) if x==p[i]]
        for t in range(len(h)):
            for d in range(5):
                if h[t]+d>len(s)-1:
                    break
                else:
                    l.append(s[h[t]:h[t]+d+1])
        else:
            l=list(set(l))
            if len(l)>=k:
                l.sort()
                print(l[k-1])
                break

Submission status: Accepted

Solution code:
import string


def solve(s, K):
    candidate = set()
    for char in string.ascii_lowercase:
        for i, c in enumerate(s):
            if c == char:
                for j in range(i + 1, min(len(s), i + 5) + 1):
                    candidate.add(s[i:j])
        if len(candidate) >= K:
            break
    return sorted(list(candidate))[K - 1]

if __name__ == "__main__":
    s = input()
    K = int(input())
    print(solve(s, K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = raw_input()
K = input()
suffix_array = [s[-i:] for i in range(1, len(s) + 1)]
suffix_array.sort()
cand = set()
for s in suffix_array[:K]:
    for i in range(1, len(s) + 1):
        sub = s[:i]
        cand.add(sub)
        if len(cand) == K:
            print sub
            sys.exit()

Submission status: Accepted

Solution code:
s=list(input())
t=set()
for i in s:
  t.add(i)
for i in range(len(s)-1):
  t.add(s[i]+s[i+1])
for i in range(len(s)-2):
  t.add(s[i]+s[i+1]+s[i+2])
for i in range(len(s)-3):
  t.add(s[i]+s[i+1]+s[i+2]+s[i+3])
for i in range(len(s)-4):
  t.add(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
u=list(t)
u.sort()
print(u[int(input())-1])

Submission status: Accepted

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

ans_stack = []

for i in range(len(s)):
    str_length = 1
    while str_length <= K and i+str_length <= len(s):
        if not s[i:i+str_length] in ans_stack:
            ans_stack.append(s[i:i+str_length])
            ans_stack = sorted(ans_stack)[0:K]
#        print(ans_stack)
#        print(s[i:i+str_length])
#        print()
        str_length += 1
print(ans_stack[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
part_list = []
# o(n^2)
for i in range(len(s)):
    for j in range(i+1,i+6):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Submission status: Accepted

Solution code:
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Submission status: Accepted

Solution code:
def cut_kouho(s, char):
    ret = []
    for i in range(s.count(char)):
        ind = s.find(char)
        ret.append(s[ind:])
        if ind == len(s) -1 :
            break
        s = s[ind+1:]
    #print(ret)
    return ret

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

if len(s) < 51 and False:
    tmp = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            tmp.append(s[i:j+1])
    a = list(set(tmp))
    a.sort()
    print(a[k-1])
else:
    char = list(set(list(s)))
    char.sort()
    #print(char)
    nokori = k
    for c in char:
        kouho = cut_kouho(s, c)
        # k文字まで減らしていい
        kouho = [i[:min(nokori, len(i))] for i in kouho]
        # 全探索
        #print(kouho)
        tmp = []
        for string in kouho:
            for i in range(len(string)):
                tmp.append(string[:i+1])
        a = list(set(tmp))
        a.sort()
        #print(a)
        if len(a) >= nokori:
            print(a[nokori-1])
            exit()
        else:
            nokori -= len(a)

Submission status: Accepted

Solution code:
s=input().strip()
K=int(input().strip())
minst='z'
for i in range(len(s)):
    if s[i]<minst:
        minst=s[i]
stset=[]
for i in range(len(s)):
    for j in range(K):
        if i+j<=len(s)-1:
            stset.append(s[i:i+j+1])
stset.sort()
kst=''
ct=0
for i in range(len(stset)):
    if kst!=stset[i]:
        ct+=1
        kst=stset[i]
    if ct==K:
        break
print(kst)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

substringset = set()

top5 = sorted(list(set(list(s))))[0:5]

for i in range(0, len(s)):
    c = s[i:i+1]
    if not c in top5:
        continue

    for end in range(i + 1,  i + 6):
        substringset.add(s[i:end])

ret = sorted(list(substringset))[K-1]
print(ret)

Submission status: Accepted

Solution code:
def main():
    s = input()
    k = int(input())
    substr = []
    for l in range(len(s)):
        for r in range(l+1,len(s)+1):
            if r-l > k:
                break
            substr.append(s[l:r])
    c=sorted(set(substr))

    print(c[k-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


def li():
	return list(map(int , input().split()))


def num():
	return map(int , input().split())


def nu():
	return int(input())


def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x


s=input()
k=nu()
n=len(s)
m=k
z=set()
for i in range(n):
	pp=""
	for j in range(i,i+m):
		if(j>=n):
			break
		pp+=s[j]
		z.add(pp)
fin=list(z)
fin.sort()
print(fin[k-1])

Submission status: Accepted

Solution code:
import heapq

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

q = []

for i in range(len(S)):
    for j in range(i, min(len(S), i + K) + 1):
        heapq.heappush(q, S[i:j])

last = ''
while K > 0:
    s = heapq.heappop(q)
    if s != last:
        K -= 1
        last = s

print(last)

Submission status: Accepted

Solution code:
S = input()
K = int(input())
N = len(S)
spyon = set([])
alp = alp2 = alp3 = 'z'
for i in range(N):
    alp = min(alp,S[i])
if N - S.rfind(alp) + 1 < K:
    for i in range(N):
        if S[i] == alp:
            continue
        alp2 = min(alp2,S[i])
if 2*N - S.rfind(alp)- S.rfind(alp2) + 2 < K:
    for i in range(N):
        if S[i] == alp or S[i] == alp2:
            continue
        alp3 = min(alp3,S[i])

for i in range(N):
    if S[i] != alp and S[i] != alp2 and S[i] != alp3:
        continue
    for j in range(6):
        spyon.add(S[i:i+j])
print(sorted(spyon)[K])

Submission status: Accepted

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

def solve():
    s = input()
    k = int(input())
    subs = sorted([s[i:] for i in range(len(s))])

    cnt = 0
    checked = set()
    for sub in subs:
        for i in range(len(sub)):
            term = sub[:i+1]
            if term not in checked:
                cnt += 1
                checked.add(term)
                if cnt == k:
                    print(term)
                    return


solve()

Submission status: Accepted

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

ll = []

for i in [1,2,3,4,5]:
    for j in range(len(s)-i+1):
        ll.append(s[j:j+i])
ll.sort()

now = ll[0]
K -= 1
counter = 1
while K!= 0:
    if ll[counter] != now:
        K-=1
        now = ll[counter]
        counter += 1
    else:
        counter += 1
print(now)

Submission status: Accepted

Solution code:
import re
""" 
よく分からないけれど1つWA
--> reはnon-overlapping にマッチする 
"""

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

substrings = []
min_s = ''
while True:
    if min_s == '':
        temp_min_s = min(list(s))
    else:
        temp_min_s = min(list(re.sub('[%s]' % min_s, '', s)))
    min_s += temp_min_s

    word_len = 1
    while word_len < K+1:
        if re.search('%s[a-z]{%d}' % (temp_min_s, word_len-1), s) == None:
            break
        substrings.extend(list(set(re.findall('(?=(%s[a-z]{%d}))' %\
                (temp_min_s, word_len-1), s))))
        # 肯定的先読み
        word_len += 1

    if len(substrings) >= K:
        print(sorted(substrings)[K-1])
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

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

    n = len(s)
    substrings = set()
    for i in range(n):
        maxlen = min(5, n - i)
        for l in range(1, maxlen + 1):
            ss = s[i:i + l]
            substrings.add(ss)

    li = list(sorted(list(substrings)))
    print(li[k - 1])

main()

Submission status: Accepted

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

sn = len(s)
sub = set()

for subl in range(5+1):
    for i in range(len(s)):
        if i+subl <= sn:
            sub.add(s[i:i+subl])

subsort=sorted(sub)
#print(subsort)
print(subsort[K])

Submission status: Accepted

Solution code:
s = str(input())
k = int(input())
sub = []
c = 5
if len(s)  < 5:
  c = len(s)
for i in range(c):
  for j in range(len(s)-i):
    sub.append(s[j:j+i+1])

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=input()
l=[]
for i in range(97,123):
    c=chr(i)
    ind=0
    while s.find(c,ind)!=-1:
        ind=s.find(c,ind)
        for j in range(1,6):
            if s[ind:ind+j] not in l:
                l.append(s[ind:ind+j])
        ind+=1
    if len(l)>=5:
        break
l.sort()
print(l[int(input())-1])

Submission status: Accepted

Solution code:


s = input()
k = int(input())
n = len(s)
res = []

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        if s1 not in res:
            for m in range(len(res)):
                if s1 < res[m]:
                    res.insert(m, s1)
                    break
            res.append(s1)
        res = res[0:k]
print(res[-1])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


s = S()
k = I()
n = len(s)
res = []

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        if s1 not in res:
            for m in range(len(res)):
                if s1 < res[m]:
                    res.insert(m, s1)
                    break
            res.append(s1)
        res = res[0:k]
print(res[-1])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


s = S()
k = I()
n = len(s)
res = []

def push(res,s):
    if s not in res:
        for i in range(len(res)):
            if s<res[i]:
                res.insert(i,s)
                break
        res.append(s)
    return(res[0:k])

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        res = push(res,s1)

print(res[-1])