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

l=list(s)

import collections
c=collections.Counter(l)
li=c.most_common()
from operator import itemgetter
li.sort(key=itemgetter(0))

co=0
p=[]
for i in range(min(5,len(li))):
    for j in range(len(s)):
        if l[j]==li[i][0]:
            for e in range(min(len(s)-j,k)):
                co+=1
                p.append(s[j:j+e+1])

q=collections.Counter(p)
ans=q.most_common()
ans.sort(key=itemgetter(0))   

print(ans[k-1][0])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
subs = []

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

print(list_subs[k - 1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
subs = []

for i in range(len(s)):
    for j in range(k):
        subs.append(s[i:i+j+1])

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

Submission status: Accepted

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

for i in range(len(S)):
  for j in range(K):
    ans.append(S[i:i+j+1])
  
ans = list(set(ans))
ans.sort()

print(ans[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
k = int(input())
A = []

for i in range(len(S)):
    for j in range(1, k + 1):
        A.append(S[i : i + j])
        
ans = sorted(list(set(A)))
print(ans[k - 1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
arr =[]
for i in range(len(s)):
    for j in range(i,i+5):
        if s[i:j+1] != '' and s[i:j+1] not in arr:
            arr.append(s[i:j+1])
arr = sorted(arr)
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep="",end="/")
    print()   
print(arr[k-1])

Submission status: Accepted

Solution code:
s = str(input())
K = int(input())
S = set()
anslength = K
while 0 < anslength:
    for i in range(0,len(s)-anslength+1):
        S.add(s[i:i+anslength])
    anslength-=1
LS = list(S)
LS.sort()
print(LS[K-1])

Submission status: Accepted

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

sub_list=[]

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

sub_set=set(sub_list)
sub_dict=sorted(sub_set,key=str)

print(sub_dict[K-1])

Submission status: Accepted

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

sub_list=[]
i,j=0,1
while True:
    if(i+j>=len(s) and i==len(s)):
        break
    else:
        sub_list.append(s[i:i+j])
        if(j<=K):
            j+=1
        else:
            i+=1
            j=1
set_list=set(sub_list)

dict_list=list(set_list)
dict_list.sort(key=str)

print(dict_list[K-1])

Submission status: Accepted

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

c = []


for i in range(len(s)):
    for k in range(1,m+1):
        c.append(s[i:i+k])

b = sorted(list(set(c)))


print(b[m-1])

Submission status: Accepted

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

l = sorted(set(list(s)))
r = []
for first in l[:min(len(l),k)]:
    #print(first)
    for i in range(len(s)):
        if s[i]==first:
            for j in range(1,6):
                r.append(s[i:i+j])
r = sorted(set(r))
print(r[k-1])

Submission status: Accepted

Solution code:
def main():
    s = input()
    k = int(input())
    ss = set(s)
    for i in range(0, len(s)):
        ss.add(s[i:i + 2])
        ss.add(s[i:i + 3])
        ss.add(s[i:i + 4])
        ss.add(s[i:i + 5])
    print(sorted(iter(ss))[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

dic = []

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

dic = (list)(set(dic))
dic.sort()


print(dic[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
c = len(s)
d = 0
a = []
if c < 5:
  d = c
else:
  d = 5
for i in range(d):
  b = [s[j:i+j+1] for j in range(c-i)]
  b = list(set(b))
  a = a + b
a.sort()
print(a[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
st = input()
k = int(input())
ls = set()
for i in range(5):
    for j in range(len(st)-i):
        ls.add(st[j:j+i+1])
ls = list(ls)
ls.sort()
print(ls[k-1])

Submission status: Accepted

Solution code:
a = input()
b = int(input())
ar = set(list(a))
arr = sorted(ar)
br = []
for i in range(len(a)):
    if a[i] == arr[0]:
        try:
            for j in range(1,b+1):
                br.append(a[i:i+j])
        except indexError:
            break
cr = set(br)
if len(cr) < b:
    for i in range(len(a)):
        if a[i] == arr[1]:
            try:
                for j in range(1,b+1):
                    br.append(a[i:i+j])
            except indexError:
                break
dr = set(br)
er = sorted(dr)
print(er[b-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
subset = []

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# encoding: utf-8
s = input()
K = int(input())

N = len(s)
num = N * (N + 1) // 2

stat = [1] * N
for i in range(K):
    head = "z" * 5001
    j_head = -1
    # compare
    for j in range(N):
        if j + stat[j] > N: continue
        if s[j : j + stat[j]] < head:
            head = s[j : j + stat[j]]
            j_head = j
    # update status
    for j in range(N):
        if j + stat[j] > N: continue
        if s[j : j + stat[j]] == head: stat[j] += 1

print(head)

Submission status: Accepted

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

se = set([])
for i in range(N):
    for k in range(5):
        s = S[i:i+k+1]
        se.add(s)
l = sorted(list(se))
ans = l[K - 1]
print(ans)

Submission status: Accepted

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

n = len(s)

d = set()
for i in range(n):
    for j in range(i+1, min(i+k+1,n+1)):
        tmp = s[i:j]
        d.add(tmp)
a = sorted(list(d))
print(a[k-1])

Submission status: Accepted

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

arr = []

for i in range(len(s)):
    for j in range(i,i+5):
        arr += [''.join(s[i:j+1])]

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

Submission status: Accepted

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

#正解(全列挙してソートしてる)
sub_string=[]
for i in range(len(s)):
  for j in range(1,k+1):
    sub_string.append(s[i:i+j])
sub_string=list(set(sub_string))
sub_string.sort()
print(sub_string[k-1])

Submission status: Accepted

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

#正解(全列挙してソートしてる)
sub_string=[]
for i in range(len(s)):
  for j in range(1,k+1):
    string = s[i:i+j]
    if string not in sub_string:
      sub_string.append(string)
sub_string.sort()
print(sub_string[k-1])

Submission status: Accepted

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

sub_strings = []
for i in range(len(s)):
  for j in range(1, K+1):
    string = s[i:i+j]
    if string not in sub_strings:
      sub_strings.append(string)
sub_strings.sort()

print(sub_strings[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
s = input()
K = int(input())
dp = []

def substr(x):
    table = {}
    for i, j in itertools.combinations(range(len(x) + 1), 2):
        table[x[i:j]] = 1
    return sorted(table.keys())[:5]

dp = []

if len(s) < 6:
    dp = substr(s)
else:
    dp = substr(s[-5:])
    for i in range(-6, -len(s) -1, -1):
        for j in range(1, 6):
            if not s[i : i + j] in dp:
                dp = sorted(dp + [s[i : i + j]])[:5]
print(dp[K - 1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
ans = []
for i in set(s):
    ans.append(i)

if K == 1:
    print(sorted(ans)[0])
else:
    for i in range(2, 6):
        for j in range(len(s) - i + 1):
            ans.append(s[j:j+i])
    ans = list(set(ans))
    ans.sort()
    print(ans[K - 1])

Submission status: Accepted

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

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

sub_string = list(set(sub_string))
sub_string.sort()

print(sub_string[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
one = list(set(s))
check = 2
if len(s) >= 2:
    while check <= len(s) and check <= 5:
        for i in range(len(s) - check + 1):
            one.append(s[i:i+check])
        check += 1
    one = sorted(set(one))
    print(one[K-1])
    
     
else:
    one = sorted(one)
    print(one[K-1])

Submission status: Accepted

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

t = len(s)
u = []
u2 = []
"""for i in range(t):
    u.append([])"""
for i in range(5):
    u.append([])

for j in range(5):
    for i in range(t):
        u[j].append([])

for i in range(t):
    u2.append([])


for j in range(5):
    for i in range(t):
        if j == 0:
            if s[i] not in u2[j]:
                u[j][i].append(s[i])
                u2[j].append(s[i])
                u[j][i].append(i)
        elif j == 1:
            if i + 1 < t:
                if s[i] + s[i + 1] not in u2[j] and s[i] + s[i + 1] not in u2[j - 1]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1])
                            u2[j].append(s[i] + s[i + 1])
                            u[r][i].append(i)
                            break
        elif j == 2:
            if i + 2 < t:
                if s[i] + s[i + 1] + s[i + 2] not in u2[j] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 1] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 2]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2])
                            u[r][i].append(i)
                            break
        elif j == 3:
            if i + 3 < t:
                if s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 1] \
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 2] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 3]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
                            u[r][i].append(i)
                            break
        elif j == 4:
            if i + 4 < t:
                if s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 1]\
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 2]and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 3]\
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 4]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])
                            u[r][i].append(i)
                            break
    """for i in range(t):
    for j in range(k):
        if j == 0:
            u[i].append(s[i])
        elif j == 1:
            u[i].append(s[i] + s[i + 1])
        elif j == 2:
            u[i].append(s[i] + s[i + 1] + s[i + 2])
        elif j == 3:
            u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
        elif j == 4:
            u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])"""
p = [0] * t
n = "z" * 10000
m = -1
l = -1
for i in range(5):
    for j in range(t + 5):
        if j < len(u[0]):
            if u[0][j] != []:
                if u[0][j][0] <= n:
                    n = u[0][j][0]
                    m = u[0][j][1]
                    l = j
    #sorted(u[0])
    if i + 1 == k:
        print(n)
        #print(u[0][0].pop(0))
        exit()
    else:
        u[0].append(u[1 + p[m]][m])
        p[m] += 1
        u[0][l].pop(0)
        u[0][l].pop(0)
        n = "z" * 10000
        m = -1
        l = -1

Submission status: Accepted

Solution code:
def 解():
    sS = input().rstrip()
#   dsS = set()
#   for s in sS:
#       if s not in dsS:
#           dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
#   for s in sorted(list(dsS)):
    for s in sorted(set(sS)):
        d = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        d.add(sS[i:i+j])
            aS = sorted(d)
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    d.add(sS[i:i+j])
            aS = sorted(d)
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()

Submission status: Accepted

Solution code:
def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()

Submission status: Accepted

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

st = [s[i:i+j+1] for i in range(len(s)) for j in range(k+1)]
se = set(st)
a = list(se)
a.sort()
print(a[k-1])

Submission status: Accepted

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

for i in range(len(S)) :
    for k in range(K+1) :
        sub = S[i:k+i]
        P.add(sub)
P = sorted(list(P))
print(P[K])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
k = ni()

lens = len(s)

subset = set()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
mydict=set()
while(1):
    tmp=[]
    for i in range(0,len(s)):
        if(s[i] in mydict):
            continue
        if(len(tmp)==0):
            tmp.append(i)
            continue
        if(s[i] < s[tmp[0]]):
            tmp=[i]
        elif(s[i] == s[tmp[0]]):
            tmp.append(i)
    for i in tmp:
        for j in range(k):
            try:
                mydict.add(s[i:i+j+1])
            except:
                pass
    if(len(mydict)>=k):
        break

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
l=[]
for v in range(len(s)):
  if s[v] not in l:
    l.append(s[v])
if k>1:
  for w in range(len(s)-1):
    if s[w:w+2] not in l:
      l.append(s[w:w+2])
if k>2:
  for x in range(len(s)-2):
    if s[x:x+3] not in l:
      l.append(s[x:x+3])
if k>3:
  for y in range(len(s)-3):
    if s[y:y+4] not in l:
      l.append(s[y:y+4])
if k>4:
  for z in range(len(s)-4):
    if s[z:z+5] not in l:
      l.append(s[z:z+5])
l.sort()
print(l[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(min(len(s), i + 5), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))

Submission status: Accepted

Solution code:
s = raw_input()
K, = map(int, raw_input().split())
L = len(s)
a = ["zzzzzz"]*5
b = {}
for i in range(L):
  for j in range(i+1,L+1):
    sij = s[i:j]
    if sij < a[4]:
      if sij not in b:
        a.append(sij)
        a.sort()
        a = a[:5]
        b[sij] = 1
    else:
      break
print a[K-1]

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#ABC097C
s=str(input())
K=int(input())
s_all=[]
s_ans=[]
for i in range(K):
    for j in range(len(s)-i):
        s_all.append(s[j:j+i+1])
sorted_s_all=sorted(s_all)
for i in range(len(sorted_s_all)):
    if i==0:
        s_ans.append(sorted_s_all[i])
    elif sorted_s_all[i]!=sorted_s_all[i-1]:
        now=sorted_s_all[i]
        before=sorted_s_all[i-1]
        s_ans.append(sorted_s_all[i])
print(str(s_ans[K-1]))

Submission status: Accepted

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

D = []
if len(s) >= 5:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
    for i in range(len(s)-2):
        if s[i]+s[i+1]+s[i+2] not in D:
            D.append(s[i]+s[i+1]+s[i+2])
    for i in range(len(s)-3):
        if s[i]+s[i+1]+s[i+2]+s[i+3] not in D:
            D.append(s[i]+s[i+1]+s[i+2]+s[i+3])
    for i in range(len(s)-4):
        if s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4] not in D:
            D.append(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
elif len(s) == 4:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
    for i in range(len(s)-2):
        if s[i]+s[i+1]+s[i+2] not in D:
            D.append(s[i]+s[i+1]+s[i+2])
    for i in range(len(s)-3):
        if s[i]+s[i+1]+s[i+2]+s[i+3] not in D:
            D.append(s[i]+s[i+1]+s[i+2]+s[i+3])
elif len(s) == 3:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
    for i in range(len(s)-2):
        if s[i]+s[i+1]+s[i+2] not in D:
            D.append(s[i]+s[i+1]+s[i+2])
elif len(s) == 2:
    for i in range(len(s)):
        if s[i] not in D:
            D.append(s[i])
    for i in range(len(s)-1):
        if s[i]+s[i+1] not in D:
            D.append(s[i]+s[i+1])
else:
    for i in range(len(s)):
        D.append(s[i])
D.sort()
print(D[K-1])

Submission status: Accepted

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

que = []
heapq.heapify(que)
subs = set([])
for char in range(97, 97+26):
    char = chr(char)
    for i, ss in enumerate(s):
        if ss == char:
            heapq.heappush(que, (ss, i))
    while len(que) > 0:
        sub, i = heapq.heappop(que)
        if not sub in subs:
            subs.add(sub)
            k -= 1
            # print(sub)
            if k == 0:
                print(sub)
                exit()
        
        i_end = i+len(sub)+1
        if i_end > len(s):
            continue
        else:
            heapq.heappush(que, (s[i:i+len(sub)+1], i))

Submission status: Accepted

Solution code:
def run(s, K):
    sub_list = []
    for i in range(len(s)):
        for j in range(i, i+K):
            if j+1 > len(s):
                break
            sub_list.append(s[i:j+1])
    sub_list = sorted(set(sub_list))
    return sub_list[K-1]


def main():
    s = input()
    K = int(input())
    print(run(s, K))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
K = int(input())
L = []
for i in range(len(s)):
    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()
n = len(s)
s = s + ' '
k = int(input())
l = []
for i in range(1, k+1):
    for j in range(n - i + 1):
        l.append(s[j:j + i])
ans = sorted(list(set(l)))[k - 1]
print(ans)

Submission status: Accepted

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

dict_set = set([])


for strlen in range(1,K+1):
    for j in range(len(s)-strlen+1):
        # print(s[j:j+strlen])
        dict_set.add(s[j:j+strlen])

dict_list = sorted(list(dict_set))

print(dict_list[K-1])

Submission status: Accepted

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

for i in range(len(s)):
    for k in range(6):
        if s[i:min(i+k,len(s))] not in dict:
            dict.append(s[i:min(i+k,len(s))])
dict.sort()
print(dict[K])

Submission status: Accepted

Solution code:
s = input()
n = len(s)
k = int(input())
l = set()
for t in range(1,k+1):
  for i in range(max(n-t+1,0)):
    l.add(s[i:i+t])
a = list(l)
a.sort()
print(a[k-1])

Submission status: Accepted

Solution code:
s = input()
l = []
L = len(s)
for i in range(len(s)):
    l.append(s[i])
    l.append(s[i:min(i+2,L)])
    l.append(s[i:min(i+3,L)])
    l.append(s[i:min(i+4,L)])
    l.append(s[i:min(i+5,L)])
l = sorted(set(l))

print(l[int(input())-1])

Submission status: Accepted

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

Submission status: Accepted

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

t = sorted(set(s))[0:K]

l = sorted(set(s))[0:K]

for i in range(min(K,len(t))):
    w = t[i]
    for j in range(len(s)):
        if s[j]==w:
            for k in range(2,6):
                l.append(s[j:j+k])

l = sorted(set(l))

print(l[K-1])

Submission status: Accepted

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

c = []
c += list(s)
for j in range(2,6):
    for i in range(len(s)-j+1):
        c.append(s[i:i+j])

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

Submission status: Accepted

Solution code:
s = list(input())
K = int(input())
j = 0
candidate = []
while True:
    if j > 26:
        break
    for i in range(len(s)):
        if s[i] == chr(ord("a") + j):
            for k in range(1, min(6, len(s) - i + 1)):
                candidate.append(s[i:i + k])
    j += 1
i = 1
candidate.sort()
while i < len(candidate):
    if candidate[i] == candidate[i - 1]:
        del candidate[i]
        i -= 1
    i += 1

for i in candidate[K - 1]:
    print(i, end = "")
print()

Submission status: Accepted

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

n = len(s)
substring = []
for i in range(n):
    for j in range(i+1, min(n+1, i+k+1)):
        substring.append(s[i:j])

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

Submission status: Accepted

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

dic={}
for i in range(len(s)):
    dic[s[i:]]=1
arr=sorted(dic)
dic={}

for x in arr:
    for i in range(0,len(x)):
        tmp = x[:i+1]
        if dic.get(tmp,0)==0:
            K-=1
            dic[tmp]=1
        else:
            continue
        if K==0:
            print(x[:i+1])
            break
    if K<0:
        break

Submission status: Accepted

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

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+1+K,len(s)+1)):
        arr.add(s[i:j])
print(sorted(arr)[K-1])

Submission status: Accepted

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

x = [[s[j:j+i+1] for j in range(len(s)-i)] for i in range(5 if len(s)>=5 else len(s))]

s_set = []
for i in x:
	s_set.extend(i)

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
t = set()
for i in range(len(s)):
    for j in range(1, k + 1):
        if i + j <= len(s):
            t.add(s[i:i + j])

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
t = set()
for i in range(len(s)):
    for j in range(k + 1):
        if i + j <= len(s):
            t.add(s[i:i + j])

t = sorted(list(t))
print(t[k])

Submission status: Accepted

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


def compare(a, b):
    ll = [a, b]
    ll = sorted(ll)
    return ll[0] == a


db = []
for length in range(1, k + 1):
    for start in range(l + 1 - length):
        candidate = s[start:start+length]
        if len(db) >= 5:
            if compare(candidate, db[-1]):
                if candidate not in db:
                    db.append(candidate)
                    db = sorted(db)
                    db = db[:5]
        else:
            if candidate not in db:
                db.append(candidate)
                db = sorted(db)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

S = input()
k = int(input())
T = set()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sub = []

for i in range(len(s)):
    for j in range(1,6):
        if s[i:i+j] not in sub:
            sub.append(s[i:i+j])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
sub = []
for i in range(0,5):
    for j in range(0,len(s)-i):
        sub.append(s[j:j+i+1])
        
subset = set(sub)
sub2 = list(subset)

sub2.sort()

print(sub2[K-1])

Submission status: Accepted

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

alphabet = ["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"]

count = 0

for alp in alphabet:
    ss = []
    # print(alp)
    if alp in s:
        pos = [i for i, x in enumerate(s) if x == alp]
        # print(pos)
        for i in pos:
            for j in range(1,6):
                if i+j == len(s) + 1:
                    break
                else:
                    ss.append(s[i:i+j])
        ss = list(set(ss))
        ss.sort()
        # print(ss)
        if K - count <= len(ss):
            print(ss[K - count -1])
            break
        else:
            count += len(ss)