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

Solution (Python):


instr = input()
target = int(input())


str_list = []
for i in range(len(instr)):

	for j in range(i, len(instr)+1):
		
		
		if j-i > target:
			break

		
		if i < j:
			str_list.append(instr[i:j])

		j += 1
	i += 1


str_list = list(set(str_list))

str_list.sort()

print(str_list[target-1])

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


sublist = []
for start in range(len(s)):
    end = min(start + k, len(s))
    for end in range(start+1, end + 1):
        sublist.append(s[start:end])

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

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

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

Solution (Python):
s=input()
k=int(input())
a=[]
for i in range(len(s)):
    a.append(s[i:])
a.sort()
x=set()
for i in range(min(5,len(s))):
    for j in range(len(a[i])):
        x.add(a[i][:j+1])
print(sorted(x)[k-1])

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

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

Solution (Python):
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(min(len(ss),K)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])

Solution (Python):

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


def substring(s, K):
    substrings = []
    length = len(s)
    for i in range(length):
        for j in range(1, K+1):
            if i + j > length:
                break
            substrings.append(s[i:i + j])
    unique_substrings = list(set(substrings))
    unique_substrings.sort()
    return unique_substrings[K - 1]


print(substring(s, K))

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

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

Solution (Python):
s=input()
k=int(input())
n=len(s)
ans=[]
for i in range(n):
    for j in range(i+1,i+k+1):
        ans.append(s[i:j])
ans=list(set(ans))
ans.sort()
if "" in ans:
    ans.pop(0)
print(ans[k-1])

Solution (Python):
a = input()
k = int(input())
sstr = set()

for i in range(len(a)):
    for j in range(i+1, i+k+1):
        sstr.add(a[i:j])

sstr = sorted(sstr)

print(sstr[k-1])

Solution (Python):
def substring():
    a = input()
    K = int(input())
    atra = set()
    
    for i in range(len(a)):
        for j in range(i + K + 1):
            if i >= j:
                continue
            atra.add(a[i:j])
    atra = sorted(atra)
    print(atra[K - 1])
    
if __name__ == '__main__':
    substring()

Solution (Python):



from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,K+1):
    for j in range(len(s)):
    
    
    
    
    
    
    
        e.add(s[j:j+i])


result = sorted(e)

print(result[K-1])

Solution (Python):


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

sub = []
for i in range(1,6):
    for j in range(0,int(len(s))):
        if s[j:j+i] in sub:
            pass
        else:
            sub.append(s[j:j+i])

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

Solution (Python):
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, i + K + 1):
            if j <= len(S):
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans
 
S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

Solution (Python):
s = input()
K = int(input())
L = len(s)
cand = []

if L > 5:
    c = []
    order = sorted(list(s))
    for i in range(L):
        if order[i] in c:
            pass
        else:
            c.append(order[i])
            if len(c) == 5:
                break
else:
    c = list(s)

for i in range(L):
    if s[i] in c:
        for j in range(i+1,min(i+K+1,L+1)):
            cand.append(s[i:j])
cand.sort()

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()

i = 0
while True:
    K -= 1
    if K == 0:
        print(cand[i])
        break
    i += 1
    while(cand[i] == cand[i-1]):
        cand.pop(i)

Solution (Python):
s=input();print(sorted({s[i:i+j] for i in range(len(s)) for j in range(6)})[int(input())])

Solution (Python):
s=input()
print(sorted({s[i:i+j] for i in range(len(s)) for j in range(6)})[int(input())])

Solution (Python):
s,k=input(),int(input())
print(sorted({s[i:i+j+1] for i in range(len(s)) for j in range(5)})[k-1])

Solution (Python):
s,n=input(),int(input())
ss=[s[i:i+j+1] for i in range(len(s)) for j in range(5)]
print(sorted(set(ss), key=sorted(ss).index)[n-1])

Solution (Python):
from sys import stdin
from string import ascii_lowercase


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = []
    for c in ascii_lowercase:
        for text in sorted([s[i:] for i, x in enumerate(s) if x == c]):
            for i in range(len(text)):
                if not text[:i + 1] in result:
                    result.append(text[:i + 1])
                    if len(result) == K:
                        print(result[-1])
                        return


if __name__ == '__main__':
    main()

Solution (Python):
s = raw_input()
k = input()
S = set()
for l in range(1,k+1):
    for i in range(len(s)-l+1):
        S.add(s[i:i+l])
print sorted(S)[k-1]

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

M=len(s)
sss=set()
for i in range(M):
    for j in range(i+1,i+k+1):
        tmp = s[i:j]
        sss.add(tmp)
l = list(sss)
l.sort()
print(l[k-1])

Solution (Python):
s=input()
K=int(input())
l=len(s)


L=[]

for i in range(l):
    L=L+[s[i]]

for i in range(l-1):
    L=L+[s[i]+s[i+1]]

for i in range(l-2):
    L=L+[s[i]+s[i+1]+s[i+2]]

for i in range(l-3):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]]
    
for i in range(l-4):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]]


M=sorted(list(set(L)))

print(M[K-1])

Solution (Python):
s=input()
K=int(input())
l=len(s)


L=[]

for i in range(l):
    L=L+[s[i]]

for i in range(l-1):
    L=L+[s[i]+s[i+1]]

for i in range(l-2):
    L=L+[s[i]+s[i+1]+s[i+2]]

for i in range(l-3):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]]
    
for i in range(l-4):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]]


M=sorted(list(set(L)))

print(M[K-1])

Solution (Python):

import math

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

init = sorted(set(list(s)))[:K]
n=0
z=[]
while(n<len(s)):
    if n > 500: break
    x=[]
    for i in range(len(s)-n):
        if s[i] in init:
            x.append(s[i:i+n+1])
    y = sorted(set(x+z))
    z = y[:K]
    n += 1
print(sorted(set(z))[K-1])

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

subs = set()

for i in range(len(s)):
  for j in range(i+1, min(5+i+1, len(s)+1)):

    subs.add(s[i:j])
subs = list(subs) 
subs.sort()
print(subs[k-1])

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

_all = []

for i in range(1, min(k+1, len(s)+1)):
	for j in range(len(s)-i+1):
		sub = s[j:j+i]
		if sub not in _all:
			_all.append(sub)

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

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

substrings = set()
for i in range(len(s)):
    for j in range(i+1,min(i+6,len(s)+1)):
        substrings.add(s[i:j])

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

Solution (Python):
s=raw_input()
K=input()
l=len(s)

a=set()
for diff in range(1,5+1):
	for i in range(l):
		a.add(s[i:i+diff])

b=list(a)
b.sort()

print b[K-1]

Solution (Python):
s=str(input())
K=int(input())
l=len(s)
a=[]
for i in range(0,l):
    for j in range(i,min(l,i+5)):
        a.append(s[i:j+1])
a=sorted(list(set(a)))
print(a[K-1])

Solution (Python):
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, i + K + 1):
            if j <= len(S)+1:
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

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

strs = set()
for i in range(len(s)):
    for j in range(i + K + 1):
        if i >= j:
            continue

        strs.add(s[i:j])

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

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

    lst = list(S)
    apnd = lst.append
    l = len(S)
    for n in range(2, 6):
        for i in range(l - n + 1):
            apnd(S[i:i+n])

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

main()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

s = ns()
k = ni()
ans = []

for i in range(len(s)):
    ans.append(s[i])
    if i < len(s)-1:
        t = i+2
        while True:
            ans.append(s[i:t])
            if t == len(s):
                break
            t += 1
            if t - i > 5:
                break

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

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

Solution (Python):
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
      if len(s[k:l+k+1])==z:
        break
print(sorted(set(d))[z-1])

Solution (Python):

"""
C - K-th Substring
https://beta.atcoder.jp/contests/abc097/tasks/arc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, K):
    l = len(s)
    substrings = set()
    for i in range(l):
        for j in range(i+K+1):
            t = s[i:j]
            if len(t):
                substrings.add(t)
    ans = list(substrings)
    ans.sort()
    return ans[K - 1]


def main(args):
    s = input().strip()
    K = int(input())
    ans = solve(s, K)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
s, k = input(), int(input())

sub_str = set()
for i in range(len(s)):
    for j in range(1, k+1):
        if i + j <= len(s):
            sub_str.add(s[i:i+j])

sub_lst = sorted(list(sub_str))
print(sub_lst[k-1])

Solution (Python):
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min(6,k-i+1)):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Solution (Python):
if __name__ == '__main__':
    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])

Solution (Python):
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min({6,k-i+1})):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

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

u = [s[i:i+j+1] for i in range(len(s)) for j in range(k+1)]

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

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


list_pair = []
i = 0
while i <= len(s):
    for j in range(1,min(len(s)-i+1,k+1)):

        list_pair.append(s[i:i+j])
    i = i + 1

list_pair = list(set(list_pair))

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

Solution (Python):
s=input()
k=int(input())
str=[]
p=1
for i in range(k):
    for j in range(0,len(s)-i):
        str.append(s[j:j+i+1])
str=list(set(str))
str.sort()
print(str[k-1])

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

l = []
for i in range(1, min(len(s)+1,k+1)):
    for j in range(0,len(s)):
        t = s[j:j+i]
        if len(t) != i:break
        if t in l: continue
        l.append(t)
l = sorted(l)
print(l[k-1])

Solution (Python):


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

n = len(s)


pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

strset = set()
for c in range(ord('a'), ord('z')+1):
    for i in pos[c]:
        for j in range(K):
            strset.add(s[i:i+j+1])

    
    if len(strset) > K:
        break


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

Solution (Python):

s=input()
k=int(input())
l=list(s)
ans=[]
i=0
j=1
while(j<=k):
    while(i+j<=len(l)):
        ans.append(s[i:i+j])
        i+=1
    j+=1
    i=0
ans=sorted(ans)
n=0
while(n+1<=len(ans)-1):
    if(ans[n]==ans[n+1]):
        ans.pop(n)
    else:
        n+=1
print(ans[k-1])

Solution (Python):
s = raw_input()
K = int(raw_input())
subs = set()
for i in range(len(s)):
  for j in range(i, i+K+1):
    subs.add(s[i:j+1])
subs = list(subs)
subs.sort()
print subs[K-1]

Solution (Python):
s = input()
k = int(input())
t = sorted(list(s))
num = []
while len(num) < k:
    a = t.pop(0)
    indexes = [i for i, x in enumerate(s) if x == a]
    z = 0
    while z < len(indexes):
        i = indexes[z]
        q = 1
        while q <= 5:
            if s[i:i + q] not in num:
                num.append(s[i:i + q])
            q += 1
        z += 1

num = sorted(num)
print(num[k - 1])

Solution (Python):
s = input()
K = int(input())
jisho = []
for i in range(1,min(len(s)+1,6)):
    for j in range(0,len(s)-i+1):
        jisho.append(s[j:j+i])
jisho = list(set(jisho))
jisho.sort()

print(jisho[K-1])

Solution (Python):


import math
import sys
import itertools
import numpy as np

e = input()
num =int(input())

a = []

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

b = list(set(a))
b.sort()
print(b[num-1])

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


e=len(s)
l=[]
for i in range(e):
	for j in range(i+1, e+1):
		a = s[i:j]
		if len(a)>k: break
		
		l.append(a)


l=list(set(l))
l.sort()


print(l[k-1])

Solution (Python):
s = str(input())
k = int(input())
kouho = [s]

for i in range(len(s)):
    for plus in range(k+1):
        st = s[i:i + plus]
        kouho.append(st)
so = list(sorted(set(kouho)))
so.remove('')
print(so[k-1])

Solution (Python):


s = raw_input()
K = int(raw_input())

s_lists = []

for i in range(K):
    for j in range(len(s) - i):
        sub_s = s[j : j + i + 1]
        
        if not (sub_s in s_lists):
            s_lists.append(s[j : j + i + 1])

s_lists.sort()



print s_lists[K - 1]

Solution (Python):

s = str(input())
k = int(input())
kouho = [s]

for i in range(len(s)):
    for plus in range(k+1):
        st = s[i:i + plus]
        kouho.append(st)
so = list(sorted(set(kouho)))
if '' in so:
    so.remove('')
    
print(so[k-1])

Solution (Python):
s = list(input().rstrip())
k = int(input())
ans_list = []

for i in range(len(s)):
    for j in range(i,len(s)+1):
        a = s[i:j]
        if len(a) > k:
            break
        a = "".join(a)
        ans_list.append(a)
        
ans_list = list(set(ans_list))
ans_list.sort()

print(ans_list[k])

Solution (Python):
s = input()
K = int(input())
A =[]
b = len(s)
for i in range(b+1):
      if i+1 < b+1:
        A.append(s[i:i+1])
      if i+2 < b+1:
        A.append(s[i:i+2])
      if i+3 < b+1:
        A.append(s[i:i+3])
      if i+4 < b+1:
        A.append(s[i:i+4])
      if i+5 < b+1:
        A.append(s[i:i+5])
B = set(A)
B = list(B)
B = sorted(B)
print(B[K-1])

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

substr_set = set()

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

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

Solution (Python):
s=input()
sub=set()
for i in range(len(s)):
    for j in range(i,min(i+6,len(s)+1)):
        f=s[i:j]
        if f!='':
            sub.add(f)
S=list(sub)
k=int(input())
print(sorted(S)[k-1])

Solution (Python):



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

os = sorted(list(set(s).union()))

nth = 0
found = []
for o in os:
  samehead = []
  for i in range(len(s)):
    if s[i] == o:
      for j in range(i+1, len(s)+1):
        if j-i>K: break
        if s[i:j] in samehead: continue
        samehead.append(s[i:j])
  cands = sorted(samehead)
  if nth + len(cands) < K:
    found += samehead
    nth += len(cands)
    continue
  print(cands[K-nth-1])
  break

Solution (Python):

s = input()
k = int(input())
sb_str = []
for i in range(len(s)+1):
    for j in range(1+i,len(s)+1):
        if len(s[i:j]) > 5:
            break
        if i < j:
            sb_str.append(s[i:j])

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

Solution (Python):
s = input()
k = int(input())
lis = list()
for i in range(len(s)):
    for j in range(i+1, i+6):
        if s[i:j] not in lis:
            lis.append(s[i:j])
lis = list(set(lis))
lis.sort()
print(lis[k-1])

Solution (Python):
import pdb

def arrins(arr, s):
    for j in range(x):
        if s == arr[j]:
            break
        elif arr[j] == "" or s < arr[j]:
            for k in range(j, x - 1):
                arr[k + 1] = arr[k]
            arr[j] = s
            break

s = raw_input()
x = int(raw_input())

ic = [0 for i in range(30)]
length = len(s)
for j in range(length):
    c = ord(s[j:(j + 1)]) - ord('a')
    ic[c] += length - j

subs = ["" for i in range(5)]
for j in range(30):
    if ic[j] == 0:
         continue

    for k in range(length):
        if ord(s[k:(k + 1)]) == (j + ord('a')) :
            for l in range(1, length - k + 1):
                t = s[k:(k + l)]
                if subs[x - 1] != "" and t > subs[x - 1]:
                    break
                else:
                    arrins(subs, t)

                
            
    if subs[x - 1] != "":
        break

print subs[x - 1]

Solution (Python):
s = raw_input()
K = int(raw_input())

arr = []
length = min(5, len(s))
for i in range(len(s)):
    for j in  range(length + 1):
        arr.append(s[i:i+j])
arr = list(set(arr))
arr.remove('')
arr = sorted(arr)
print(arr[K - 1])

Solution (Python):


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

alphabets = 'abcdefghijklmnopqrstuvwxyz'

dic = []

for char in alphabets:
    
    index = 0
    ss = []
    while index != -1:
        index = s.find(char, index)

        if index != -1:
            tmp = s[index:index + 5]
            isSubstring = False
            for sss in ss:
                if sss.find(tmp) == 0:
                    isSubstring = True
                    break
            if isSubstring == False:
                ss.append(tmp)

            index += 1

    if  len(ss) > 0:
        ss.sort()
        for x in ss:
            for i in range(len(x)):
                if x[0:i+1] not in dic:
                    dic.append(x[0:i+1])
                    if len(dic) >= k:
                        break
        if len(dic) >= k:
            break

print(dic[k-1])

Solution (Python):
s=input()
n=int(input())
ss=[]
for i in range(len(s)):
  for j in range(5):
    ss.append(s[i:i+j+1])
ss.sort()

kk=1
for i in range(len(ss)):
  if kk==n:
    print(ss[i])
    break
  if ss[i]!=ss[i+1]:
    kk+=1

Solution (Python):
s = input()
k = int(input())
substrings = []

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

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

Solution (Python):
def main():
    
    s = input()
    K = int(input())
    
    
    subset = set()
    for k in range(1, min(len(s)+1, K+1)):
        start = 0
        while start <= len(s)-k:
            subset.add(s[start:start+k])
            start += 1
    
    subset_list = sorted(list(subset))
    print(subset_list[K-1])

if __name__ == "__main__":
    main()

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

sset = set()

for i in range(1, 6):
    sset |= set([s[j:j+i] for j in range(0, len(s))])

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

Solution (Python):
s = input()
k = int(input())
ans_list = []

for i in range(5):
    s_list = [s[j:j+i+1] for j in range(len(s)-i)]
    s_set_list = list(set(s_list))
    for m in range(len(s_set_list)):
        ans_list.append(s_set_list[m])

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

Solution (Python):
s_list = list(input())
k = int(input())
s_sort = sorted(s_list)
a_list = []
for s in s_sort:
    idx = s_list.index(s)
    for i in range(1, 6):
        a_list.append("".join(s_list[idx:idx+i]))
    s_list[idx] = "@"
a = list(set(a_list))
for i, s in enumerate(a):
    if "@" in s:
        a[i] = s.replace("@", s_sort[0])
a = sorted(a)
print(a[k - 1])

Solution (Python):
s=input()
k=int(input())
l=len(s)
a={s[i:i+j+1] for i in range(l) for j in range(k+1)}
a=list(a)
a.sort()
print(a[k-1])

Solution (Python):
strs = input()
N = int(input())

Len = len(strs)

allstr = [] 
flag = 0

for i in range(Len):
    tmp = list(range(i+1))
    tmp.reverse()
    for j in tmp:

        allstr.append(strs[Len-i-1:Len-j])
        allstr2 = list(set(allstr))
        if len(allstr2) > 5:
            if allstr[5:6] > allstr[4:5] and flag == 1:

                allstr = allstr[0:5]
                break
            allstr2.sort()
            allstr = allstr2[0:5]
            flag = 1

        

allstr2 = list(set(allstr))        
allstr2.sort()

print(allstr2[N-1])

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

substring = {}

for i in range(len(s)):
    for j in range(i+1, i+1+k):
        
        substring[s[i:j]] = True


words = [item[0] for item in substring.items()]
sorted_words = sorted(words)

print(sorted_words[k-1])

Solution (Python):
s = input()
x = int(input())
n = len(s)

pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

f = set()
for c in range(97, 123):
    for i in pos[c]:
        for j in range(x):
            f.add(s[i:i+j+1])
    if len(f) >= x:
        break

p = [u for u in f]
p.sort()
print(p[x - 1])

Solution (Python):
import sys
import math

results = set()


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


chars = set(list(s))

for c in sorted(list(chars)):
    t = s

    ss = set()
    while True:
        i = t.find(c)
    
        if i == -1:
            break

        ss.add(t[i:])

        t = t[i+1:]

    for sa in sorted(list(ss)):
        for j in range(1, len(sa)+1):
            results.add(sa[:j])
            if len(results)==K:
                print(sa[:j])
                quit()

Solution (Python):
def f(myC, s, chrs, lst, k):
    if len(lst) == k:
        print(lst[k - 1])
        exit()
    else:
        for c in chrs:
            buf = myC + c
            if buf in s:
                lst += [buf]
                
                f(buf, s, chrs, lst, k)

if __name__ == '__main__':
    s = input()
    k = int(input())

    chrs = sorted(list(set(s)))
    lst = f('', s, chrs, list(), k)

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

kouho = [s]

for atama in range(len(s)):
    for offset in range(K):
        tes = s[atama:atama+offset+1]
        if tes in kouho:
            continue
        kouho.append(tes)
        kouho = sorted(kouho)
        if len(kouho) > K:
            kouho.pop()

print(kouho[K-1])

Solution (Python):
s=input()
k=int(input())
moji=sorted(list(set(s)))
ans=[moji[0]]
mojinum=0
if k==1:
    print(ans[0])
    import sys
    sys.exit()
while(True):
    for r in range(len(moji)):
        if ans[-1]+moji[r] in s:
            ans.append(ans[-1]+moji[r])
            break
        elif r==len(moji)-1:
            mojinum+=1
            ans.append(moji[mojinum])
    if len(ans)>=k:
        break
print(ans[k-1])

Solution (Python):


str = raw_input()
K = int(raw_input())






dic = set()

i = 1


while i <= K:
    idx = 0
    while True:
        head = idx
        tail = i + idx
        if tail > len(str):
            break
        else:

            dic.add(str[head:tail])
            idx = idx + 1

    i = i + 1






dic_set = list(dic)
dic_set.sort()


print dic_set[K-1]

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


l = list(s)
alphabet = sorted(list(set(l)))

num = 0
for a in alphabet:
    cand = []
    n = s.count(a)
    l = list(s)
    for i in range(n):
        ind = l.index(a)
        for j in range(k):
            cand.append(s[ind+i: ind+j+1+i])
        l.remove(a)
    cand = list(set(cand))
    if len(cand) >= k:
        break
    else:
        num += len(cand)
print(sorted(cand)[k-num-1])

Solution (Python):
ss = input()
k = int(input())
save = []
num = ord("a")

while True:
  lst = []
  c = chr(num)
  for i in range(len(ss)):
    if ss[i] == c:
      lst.append(i)
  for ind in lst:
    for j in range(1,k + 1):
      if ind + j <= len(ss):
        save.append(ss[ind:ind + j])


  if(len(list(set(save)))) >= k:
    flag = True
    break
  num += 1

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

Solution (Python):

import math

s = input()
K = int(input())
dic = []

for i in range(len(s)):
    for j in range(i+1, i+6):
        if s[i:j] not in dic:
            dic.append(s[i:j])
dic.sort()
print(dic[K-1])

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

li = sorted(list(set(s)))
hitList = []

def oneMoreChar(moji):
    hitList.append(moji)
    if len(hitList) < K:
        for i in range(len(li)):
            if moji+li[i] in s:
                return oneMoreChar(moji+li[i])
    else:
        pass

for char in li:
    oneMoreChar(char)

print(hitList[K-1])

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

	subs = set()
	if len(s) <= 50:
		for f in range(len(s)):
			for t in range(f, len(s)+1):
				subs.add(s[f:t])
	else:
		for f in range(len(s)):
			for t in range(f, f+6):
				subs.add(s[f:t])

	l = list(subs)
	l.sort()
	print(l[K])

Solution (Python):
def main():
    """
    1<=|s|<=5,000
    1<=K<=5
    """
    s = input()
    K = int(input())

    part(s, K)


def f(s, K):
    """
    K=1, sorted(s)[0]
    K=2, s[min_idx:min_idx+2]
        aabbaac

        min:a, next: aa
        aab<aac
    1-5文字: すべて異なる文字列なら1文字でよい

    minから5種類存在するなら不要
        K個以上存在する
    a: min
    aaaaa: 5th(aa,aaa,aaaaがあれば)

    abced: 完了
    babcd: 途中にaがあるから未完
     abcde: 完了,ただしaaaaaとかあったらNG
    """
    pass


def part(s, K):
    
    n = len(s)
    ss = set()
    for i in range(n):
        
        for j in range(i, i+K):
            subs = s[i:j+1]
            
            ss.add(subs)

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


if __name__ == '__main__':
    main()

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

index = []

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

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

substringList = []
if(len(s) < 50):
    for i in range(len(s)):
            for j in range(i, len(s)):
                
                if(s[i:j+1] in substringList):
                    pass
                else:
                    substringList.append(s[i:j+1])
else:
    for i in range(len(s)):
            for j in range(i, i+5):
                substringList.append(s[i:j+1])

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

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

chars = ['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']

current = ""

for i in range(K):
    if current == "":
        current = min(s)
        continue

    startIndexes = [m.start() for m in re.finditer(current, s)]
    candidates = [s[index:index+len(current)+1] for index in startIndexes]
    for candidate in candidates:
        if candidate == current:
            candidates.remove(candidate)
    if not candidates:
        current = min(s.replace(current[0], ""))
    else:
        current = min(candidates)

print(current)

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

subset_list = list(s)
subset_list += [s[i:i+2] for i in range(len(s)-1)]
subset_list += [s[i:i+3] for i in range(len(s)-2)]
subset_list += [s[i:i+4] for i in range(len(s)-3)]
subset_list += [s[i:i+5] for i in range(len(s)-4)]
subset_list = list(set(subset_list))
subset_list.sort()

print(subset_list[K-1])

Solution (Python):
s= str(input().strip())
K= int(input().strip())
parts = []
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        flg = 0
        if j-i > K:
            break
        parts.append(s[i:j])
v = sorted(parts)
vv = [v[0]]
tmp = v[0]
for k in range(1,len(v)):
    if v[k]!=tmp:
        vv.append(v[k])
        tmp = v[k]
    if len(vv)==K:
        break
        
print(vv[K-1])

Solution (Python):
s = input()
n = input()
ans = set([])
test = list(s)

for i in range(len(test)):
    s = test[i]
    ans.add(s)
    for j in range(i+1, min(i+5, len(test))):
        s = s + test[j]
        ans.add(s)
    
ans = list(ans)

ans.sort()
print(ans[int(n)-1])

Solution (Python):
s = input()
K =input()

list1=[]
for i in range(len(s)):
    if s[0:i].count(s[i])==0:
        list1.append(s[i])
        i +=1
    else:
        i+=1

i=0
for i in range(len(s)):
    if s[i:i+2] not in list1:
        list1.append(s[i:i+2])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+3] not in list1:
        list1.append(s[i:i+3])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+4] not in list1:
        list1.append(s[i:i+4])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+5] not in list1:
        list1.append(s[i:i+5])
    else:
        i+=1

list1=sorted(list1)
print(list1[int(K)-1])

Solution (Python):
from bisect import insort
s = input().strip()
k = int(input())

sublist = []
for i in range(len(s)):
    if len(sublist)>k:
        sublist = sublist[:k]
    for j in range(i+1,len(s)+1):
        if len(sublist)>=k and sublist[k-1]<s[i:j]:
            break
        if s[i:j] not in sublist and (len(sublist)<k or sublist[k-1]>s[i:j]):
            insort(sublist,s[i:j])

print(sublist[k-1])