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

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

Submission status: Accepted

Solution code:
import string


def make_string(string, flag_matched=False, N=5000):
    if string[-1] == 'z':
        string = string[:-1]
        flag_matched = False
    if flag_matched == False or len(string) == N:
        string = string[:-1] + chr(ord(string[-1] )+1)
    else:
        string += 'a'
    return(string)


S = input()
k = int(input())

N = len(S)
if N <= 50:

    A = []

    for i in range(N):
        for j in range(1, N+1-i):
            A.append(S[i:i+j])

    A = list(set(A))
    A.sort()

    print(A[k-1])

else:

    c = 0
    q = 'a'

    while True:
        if q in S:
            c += 1
            if c == k:
                break
            else:
                q  = make_string(q, True, N)
        else:
            q  = make_string(q, False, N)

    print(q)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
alphabets = sorted(set(list(s)))

# 答えとなるsubstringは必ずK文字以下
res = set()
# 頭文字(alphabetsの添字)
prefix = 0
while len(res)<k:
    # 頭文字のみの場合
    res.add(alphabets[prefix])
    for i in range(len(s)):
        #print(i,res)
        if s[i]==alphabets[prefix]:
            # 2文字以上の部分文字列をresに追加
            length = 2
            while length<=k:
                if i+length>len(s):
                    break
                res.add(s[i:i+length])
                length += 1
    prefix += 1

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

Submission status: Accepted

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

sublist = []
for i in range(len(s)):
  for j in range(K):
    sublist.append(s[i:i+j+1])

#print(sublist)
print(sorted(list(set(sublist)))[K-1])

Submission status: Accepted

Solution code:
from collections import Counter
S = input()
K = int(input())
N = len(S)
d = []
for i in range(N):
  for j in range(i,min(i+5,N)):
    d.append(S[i:j+1])
print(sorted(Counter(d))[K-1])
quit()

Submission status: Accepted

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

D = []
m = []

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

for n in range(3):
    if chars != []:
        m.append(min(chars))
        chars = chars[1:]

m.reverse()

t = m.pop()
D.append(t)

while len(D) < K:
    p = re.compile(t + '[a-z]')
    ma = list(set(p.findall(s)))
    ma.sort()
    if ma == []:
        if D.index(t) < len(D)-1:
            t = D[D.index(t)+1]
        else:
            t = m.pop()
            D.append(t)
    else:
        D.append(ma[0])
        t = ma[0]

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def main():
    s = input()
    K = int(input())
    c = Counter(s)

    se = set()
    for k, v in sorted(c.items()):
        for i in range(len(s)):
            for n in range(1, 6):
                if s[i] == k and i + n <= len(s):
                    se.add(s[i:i+n])
        if len(se) > K:
            break

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Aug  7 23:57:38 2018

@author: Yuki
"""

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

string_cands = []
s_length = len(s)
for i in range(s_length):
    for ii in range(1, K+1):
        string_cands.append(s[i:i+ii])
print(sorted(set(string_cands))[K-1])

Submission status: Accepted

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

length = len(s)
substring_list = []
for i in range(length):
    for j in range(1,k+1):
        substring_list.append(s[i:i+j])
result = list(set(substring_list))
result.sort()

print(result[k-1])

Submission status: Accepted

Solution code:

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

S = input()
K = int(input())
li = []
for i in range(len(S)):
	for j in range(1,6):
		li.append(S[i:i+j])

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

Submission status: Accepted

Solution code:
import numpy as np

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

# Number of alphabets are 27.
# 1 <= len(s) <= 5000
# 1 <=     K  <= 5

dic = set()

for l in range(1, K+1):
    for i in range(len(s) - l + 1):
        substr = s[i:i+l]
        dic.add(substr)

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

Submission status: Accepted

Solution code:
import sys

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

N = len(S)

if(K >= len(S)):
    ans_set = set()
    for i in range(len(S)):
        for j in range(1, K + 1):
            if(i + j > N):
                break
            ans_set.add(S[i:i + j])
    ans = sorted(list(ans_set))
    print(ans[K - 1])
    sys.exit()

alpha = [chr(i) for i in range(97, 97 + 26)]
min_dic = 25
ans_set = set()
for i in range(0, N):
    if(min_dic < alpha.index(S[i:i + 1])):
        continue
    else:
        min_dic = alpha.index(S[i:i + 1])

    for j in range(1, K + 1):
        if(i + j > N):
            break
        ans_set.add(S[i:i + j])

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

Submission status: Accepted

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

len_s = len(s)

sub_set = set()
for k in range(1,6):
    for i in range(len_s-k+1):
        sub_set.add(s[i:i+k])
        
sub_list = list(sub_set)
sub_list.sort()
print(sub_list[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def n_gram(s, n):
	return [s[i:i+n] for i in range(len(s)-n+1)]

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

subs = set()
for k_i in range(1, k+1):
	subs = subs | set(n_gram(s, k_i))
print(sorted(subs)[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
s = input()
K = int(input())
n = len(s)
alpha = list("abcdefghijklmnopqrstuvwxyz")
ans = []
for al in alpha:
    if al in s:
        for i in range(n):
            if al == s[i]:
                for j in range(1,6):
                    if i+j <= n:
                        ans.append(s[i:i+j])
        ans = dict.fromkeys(ans)
        ans = list(ans.keys())
    if len(ans) >= 5:
        break

ans.sort()
try:
    ans.remove("")
except:
    pass
print(ans[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
N = int(input())
len_s = len(s)

sub_set = set()

for start in range(len_s):
    k = 1
    while k <= min(len_s-start, N):
        sub_set.add(s[start:start+k])
        k += 1
        

sub_list = list(sub_set)
sub_list.sort()

print(sub_list[N-1])

Submission status: Accepted

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

substr_set = set()

for i in range(1, K + 1) : # max length of string
    if i >= len(s) :
        substr_set.add(s)
    else :
        for j in range(len(s) - i + 1) :
            if s != '' :
                substr_set.add(s[j:j+i])
    
sublist = list(substr_set)

sublist.sort()
# sublist.sort(key = len, reverse = False)

print(sublist[K - 1])

Submission status: Accepted

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

def solve(s,k):
    temp = []
    for i in range(len(s)):
        for j in range(i + 1, i + k + 1):
            if j <= len(s)+1:
                temp.append(s[i:j])
    temp = sorted(set(temp))
    ans = temp[k - 1]
    return ans

print(solve(s,k))

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

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

    A = []
    for i in range(len(S)):
        for j in range(i+1, min(i+6, len(S)+1)):
            A.append(S[i:j])

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

main()

Submission status: Accepted

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

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

    a = set()

    for i in range(len(s)):
        for j in range(K):
            a.add(s[i:i+j+1])
            if i + j > len(s):
                break
    a_list = list(a)
    a_list.sort()
    print(a_list[K-1])
            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def m():
    s = input()
    k = int(input())
    a = set()
    for i in range(len(s)):
        for j in range(5):
            a.add(s[i:i+j+1])
    b = list(a)
    b.sort()
    return b[k-1]

print(m())

Submission status: Accepted

Solution code:
s = input()
K = int(input())
S = set()
for i in range(1, K+1):
    S |= set([s[n:n+i] for n in range(0, max(len(s)-i+1, 0))])
print(sorted(list(S))[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jul  6 22:20:31 2018
ABC097A
@author: maezawa
"""

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

perm = []

n = len(s)
for i in range(1, 6):
    for j in range(n-i+1):
        perm.append(s[j:j+i])
    
ans_array = sorted(set(perm))
#print(ans_array)
print(ans_array[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
str_len = len(s)
substrings = []

def get_substrings(substr_len):
    if substr_len == K + 1:
        return
    else:
        for i in range(0, str_len + 1 - substr_len):
            sub_s = s[i:i+substr_len]
            if not(sub_s in substrings):
                substrings.append(sub_s)
        get_substrings(substr_len + 1)

get_substrings(1)
substrings.sort()

print(substrings[K - 1])

Submission status: Accepted

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

l = len(s)
substr = []

for i in range(l):
    for k in range(K):
        substr.append(s[i:i+k+1])
        if i+k+1 >= l: break

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

Submission status: Accepted

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

Submission status: Accepted

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

substr = []
# O(n*K)
for i in range(n):
    for j in range(i, i+K):
        substr.append(s[i:j+1])

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = input()
    K = int(input())

    subs = []
    for i in range(len(s)):
      for j in range(K):
            try:
                subs.append(s[i:i+j+1])
            except:
                break
    subs = set(subs)
    print(sorted(list(subs))[K-1])

Submission status: Accepted

Solution code:

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

    ss = []
    for i in range(0, len(s)):
        for j in range(i, i + k + 1):
            if i == j:
                continue
            if len(ss) == 6:
                if ss[-1] > s[i:j]:
                    ss[-1] = s[i:j]
                    ss = list(set(ss))
                    ss.sort()
            else:
                ss.append(s[i:j])
                ss = list(set(ss))
                ss.sort()

    print(ss[k-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

sss = set()
M = len(s)
for end in range(1, K+1):
    for i in range(M):
        sss.add(s[i:(i+end)])

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

Submission status: Accepted

Solution code:
# 5000**2、5000**3
# 5文字以下だよ。辛いよ。
s = input()
k = int(input())
sbst = set()
for i in range(1, k+1):
    for j in range(len(s)-i+1):
        sbst.add(s[j:j+i])
sbstl = sorted(list(sbst))
print(sbstl[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
s=input()
K=int(input())


def calc(s, K):
    a = defaultdict(list)
    for i, c in enumerate(s):
        a[c].append(i)
    result = set()
    for i in range(ord('a'), ord('z')+1):
        for j in a[chr(i)]:
            for l in range(min(K, len(s[j:]))):
                result.add(s[j:j+l+1])
        if len(result) >= K:
            return sorted(list(result))[K-1]

print(calc(s, K))

Submission status: Accepted

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

list = []
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    tmp = s[i:j]
    if len(list)>=K:
      if tmp>list[-1]:
        break
      else:
        if not tmp in list:
          list.append(tmp)
          list.sort()
          list = list[:K]
    else:
      if not tmp in list:
        list.append(tmp)
        list.sort()
        if len(list)>K:
          list = list[:K]

print(list[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
l = []
for i in range(len(s)):
    l.append(s[i:])
    l.sort()
    if len(l) > 5:
        l.pop()

p = set()
for i in l:
    for j in range(1,len(i)+1):
        p.add(i[:j])

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for code in range(ord('a'),ord('z')+1):
    for right in d[chr(code)]:
        for sl in range(min(K,len(s[right:]))):
            sub.add(s[right:right+sl+1])
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for i in range(26):
    for j in d[chr(ord('a')+i)]:
        for k in range(min(K,len(s[j:]))):
            sub.add(s[j:j+k+1])
#            print(s[j:j+k+1])
#    print(len(sub), k)    
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
from itertools import accumulate, groupby, islice
 
s = input()
n = int(input())
 
gens = [accumulate(s[i:]) for i in range(len(s))]
sm = heapq.merge(*gens)
res, _ = next(islice(groupby(sm), n-1, n))
print(res)

Submission status: Accepted

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

for i in range(l):
	for j in range(1,min(6,l-i+1)):
		arr.append(s[i:i+j])

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

Submission status: Accepted

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

t = set()

for i in range(len(s)):
  tt = ""
  for j in range(i, min(i+5, len(s))):
    tt+=s[j]
    t.add(tt)

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

Submission status: Accepted

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

l =[]

for i in range(len(s)):
    tmp = ''
    for j in range(i, len(s)):
        if j > i + 4: break
        tmp += s[j]
        l.append(tmp)
l.sort()

l2 = []
for x in l:
    if len(l2) > 6:
        break
    if x not in l2:
        l2.append(x)


ans = l2[K - 1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
from itertools import groupby, islice

s = input()
n = int(input())

def substrings_starting_at(i):
  return (s[i:j+1] for j in range(i, len(s)))

gens = [substrings_starting_at(i) for i in range(len(s))]
sm = heapq.merge(*gens)
res, _ = next(islice(groupby(sm), n-1, n))
print(res)

Submission status: Accepted

Solution code:
s = input()
K = int(input())
sub = {s}
for d in range(1,K+1):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
print(sorted(sub)[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
print(sorted(sub)[K-1])

Submission status: Accepted

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

chars = sorted(set(s))
lexicon = []

def next_word(cur):
    lexicon.append(cur)
    if len(lexicon) < K:
        for next_c in chars:
            next_w = cur + next_c
            if next_w in s:
                return next_word(next_w)

for char in chars:
    next_word(char)

print(lexicon[K-1])

Submission status: Accepted

Solution code:
s = input()
l_s = list(s)
K = int(input())
if K == 1:print(min(l_s));exit()
elif K == 2:
    idx = s.index(min(l_s))
    if idx < len(s)-1:
        print(s[idx:idx+2])
    else:
        print(sorted(l_s)[1])
    exit()
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
sub = list(sub)
n = len(sub)
for i in range(K):
    for j in range(n-i):
        a, b = sub[-i-1], sub[j]
        if a > b: sub[-i-1], sub[j] = b, a
print(sub[-K])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
sub = list(sub)
n = len(sub)
for i in range(K):
    for j in range(n-i):
        a, b = sub[-i-1], sub[j]
        if a > b: sub[-i-1], sub[j] = b, a
print(sub[-K])

Submission status: Accepted

Solution code:
s=input()
K=int(input())
 
ans=[]
ans.append(s)
 
 
for i in range(len(s)):
 for j in range(len(s)-i):
  cut_s=s[i:i+j+1]
  ans.append(cut_s)
  ans=sorted(set(ans))
  if len(ans)>K:
   if cut_s==ans[K]:
     ans.pop()
     break;
   ans.pop()
 
answer=ans[K-1]
print(answer)

Submission status: Accepted

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

cand_list = []
for i in range(len(s)):
    for j in range(len(s)+1-i):
        _s = s[i:i+j+1]
        cand_list.append(_s)
        cand_list = sorted(set(cand_list))
        if len(cand_list) > k and cand_list[len(cand_list) - 1] == _s:
            cand_list.remove(_s)
            break
        elif len(cand_list) > k:
            cand_list.pop(len(cand_list) - 1)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def decompose(s):
    l = []
    N = len(s)
    i = 1
    while i <= N:
        l.append(s[:i])
        i += 1
    l = list(set(l))
    l.sort()
    return l

def answer(slist,smin,k):
    indices = [i for i, x in enumerate(slist) if x == smin]
    ans = []
    for ind in indices:
        ans.extend(decompose(s[ind:min(ind+k,len(s))]))
    ans = list(set(ans))
    ans.sort()
    if len(ans) >= k:
        return ans[k-1]
    else:
        s_temp = slist.copy()
        k -= len(ans)
        for r in range(len(indices)):
            s_temp.remove(min(slist))
        smin = min(s_temp)
        j = answer(slist,smin,k)
        return j

s=answer(list(s),min(list(s)),k)
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
arr = set()
arr.add(s)
for i in range(len(s)-1):
    if i > 5:
        break
    for j in range(0, len(s)):
        arr.add(s[j:j+i+1])

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

Submission status: Accepted

Solution code:
string =str(input())
K=int(input())
l=len(string)
substring = set()
for i in range(l):
    for j in range(i+1,i+K+1):
        substring.add(string[i:j])
#print(substring)
sublist = list(substring)
sublist.sort()
#print(sublist)
print(sublist[K-1])

Submission status: Accepted

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

l = set([])
for i in range(len(s)):
  for j in range(i, min(len(s),i+K)):
    l.add(s[i:j+1])
l2 = list(l)
l2.sort()
print(l2[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import string


lowercase = string.ascii_lowercase

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

substrings = []

stack = list(lowercase)[::-1]

while len(substrings) < K:
    # print(stack)
    v = stack.pop()
    if v in s:
        substrings.append(v)
        for c in list(lowercase)[::-1]:
            stack.append(v+c)

print(substrings[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)-i+1):
        l.append(s[j:j+i])


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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = set()
    for c in sorted(list(set(s))):
        for x in sorted([s[i:] for i, x in enumerate(s) if x == c]):
            for y in [x[:j + 1] for j in range(len(x))]:
                result.add(y)
                if len(result) == K:
                    print(sorted(list(result))[-1])
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

arr = []
sn = len(s)
for i in range(1, K+1):
  for j in range(0, sn):
    if i+j <= sn:
	    arr.append(s[j:i+j])
    else:
      break
unique_arr = sorted(list(set(arr)))

print(unique_arr[K-1])

Submission status: Accepted

Solution code:
S = input()
K = int(input())
l = len(S)
topk = []
a = []

for i in range(l):
    for j in range(i + 1, i + K + 1):
        if j > l:
            break
        ss = S[i: j]
        a.append(ss)

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

Submission status: Accepted

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

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

print(a[K-1])

Submission status: Accepted

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

words = set()

l = k+1 if len(s) > k else len(s) + 1

for i in range(1,l):
    for j in range(len(s)):

        words.add(s[j:i+j])

sort_word = sorted(words)

print(sort_word[k-1])

Submission status: Accepted

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

sub = set()

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

ans = list(sorted(sub))

print(ans[K - 1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
d = []
ele = []
for i in range(len(s)):
    for j in range(0,K):
        substr = s[i:i+j+1]
        if not substr in d and len(substr)<=K:
            d.append(substr)
d.sort()
print(d[K-1])

Submission status: Accepted

Solution code:
s =input()
k =int(input())
a =[]
if len(s)==1:
    a.append(s)
else:
    for i in range(len(s)):
        for j in range(i,i+k+1):
            if i!=j:
                a.append(s[i:j])
            else:
                a.append(s[i])
a.sort()
temp=""
cnt,i=0,0
for i in range(len(a)):
    if temp != a[i]:
        cnt += 1
        if cnt ==k:
            break
    temp = a[i]
print(a[i])

Submission status: Accepted

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

substr_set = set()

for i in range(0, len(s)):
    for slen in range(0, K):
        substring = s[i:i + slen + 1]
        substr_set.add(substring)

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

Submission status: Accepted

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


for j in range(1,K+1):
    for i in range(len(s)):
        listA.append(s[i:i+j])
listA.sort()
x=""
count=0
for i in range(len(listA)):
    if(x!=listA[i]):
        count+=1
        x=listA[i]
    if(count==K):
        print(x)
        break;

Submission status: Accepted

Solution code:
#abc097c

s=raw_input()
K=int(raw_input())
r=[]
for i in xrange(len(s)):
 for j in xrange(i+1,i+K+1):
  r.append(s[i:j])
#print r
r.sort()
l=list(set(r))
l.sort()
print l[K-1]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
result = []

for u in alphabet:
    for i in range(len(s)):
        if s[i] == u:
            for j in range(i + 1, min(i + K + 1, len(s) + 1)):
                result.append(s[i:j])
    result = list(set(result))
    if len(result) > K:
        break

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

Submission status: Accepted

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

result = list(set(result))
result.sort()
# print(result)
# print(len(result))
print(result[K - 1])

Submission status: Accepted

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


subs = list(set(subs))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

subs = set()

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

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