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: Time Limit Exceeded

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

substringList = []
for i in range(len(s)):
    for j in range(i, len(s)):
        #print(i,j)
        if(s[i:j+1] in substringList):
            pass
        else:
            substringList.append(s[i:j+1])
#substringList = list(set(substringList))
print(sorted(substringList)[K-1])

Submission status: Time Limit Exceeded

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

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

print b[K-1]

Submission status: Time Limit Exceeded

Solution code:
s = input()
K = int(input())
jisho = []
for i in range(1,len(s)+1):
    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])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

string_list = list()
for i_start in range(len(s)):
    for i_end in range(i_start+1, len(s)+1):
        string_list.append(s[i_start:i_end])

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
t = sorted(list(s))
num = []
while len(num) < k:
    a = t.pop(0)
    for i in range(len(s)):
        if s[i] == a:
            q = 1
            while i + q <= len(s):
                if s[i:i + q] not in num:
                    num.append(s[i:i + q])
                q += 1

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

Submission status: Time Limit Exceeded

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

substringList = []
for i in range(len(s)):
    for j in range(i, len(s)):
        #print(i,j)
        substringList.append(s[i:j+1])
substringList = list(set(substringList))
print(sorted(substringList)[K-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# time complexity: O(|s|^2)

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

substring_set = set()

# brute-force
for start in range(len(s)):
    for length in range(len(s) - start + 1):
        if length == 0:
            substring = s[start]
        else:
            substring = s[start:start+length]
            substring_set.add(substring)


substring_list = sorted(list(substring_set))
print(substring_list[K - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n = len(s)
a = []
for i in range(n+1):
    for j in range(n-i+1):
        if len(s[i:i+j]) >=1:
            if not s[i:i+j] in a:
                a.append(s[i:i+j])
a.sort()
print(a[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sset = set()

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

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

Submission status: Time Limit Exceeded

Solution code:
# cook your dish here
# from math import * 
#for _ in range(int(input().strip())):

s = input()
k = int(input())
var = 0
sub = set()

for var in range(97,123):
    if len(sub)>k:
        break
    for i in range(len(s)):
        if s[i]==chr(var):
            for j in range(i,len(s)):
                sub.add(s[i:(j+1)])
l = list(sub)
l.sort()
print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
dic = {}
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if s[i:j] in dic:
            continue
        dic[s[i:j]] = 1

print(sorted(dic.keys())[k-1])

Submission status: Time Limit Exceeded

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

    part(s,K)

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
k = int(raw_input())
l = len(s)
ls = []
for a in range(l):
    for b in range(a+1,l+1):
        if ls.count(s[a:b]) == 0:
            ls.append(s[a:b])
ls.sort()
print ls[k-1]

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = int(input())
dic = {}
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if s[i:j] in dic:
            continue
        dic[s[i:j]] = 1
count = 0
for i in sorted(dic.keys()):
    if count == k-1:
        print(i)
        quit()
    count += 1

Submission status: Time Limit Exceeded

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

sl = len(s)

sub = []

for l in range(1, sl):
    for i in range(sl-l+1):
        t = s[i:i+l]
        if not t in sub:
            sub.append(t)

sub.append(s)

sub = sorted(sub)

print(sub[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
#l = "abcdefghijklmnopqrstuvwxyz"
#print(ord("b")) 97
ans = []
for i in range(len(s)):
    x = 0
    for j in range(5):
        if (i+j<len(s)):
            x += (ord(s[i+j])-96)*10**(8-2*j)
            ans.append((x,s[i:i+j+1]))
ans = list(set(ans))
ans.sort()
#print(ans)
print(ans[k-1][1])

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    K = ii()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input().rstrip()
N = len(s)
K = int(input())

c = []
for i in range(N):
    for j in range(i+1, N+1):
        if len(c) < K:
            c.append(s[i:j])
            c.sort()
        else:
            if s[i:j] in c:
                continue

            if c[K-1] < s[i:j]:
                break
            else:
                c[K-1] = s[i:j]
                c.sort()

print(c[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
K=int(input())
N=len(S)
s=set()
for i in range(N):
    for j in range(i+1,min(i+K+1,N+1)):
        s|={S[i:j]}
A=list(s)
A.sort()
print(A[K-1])

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


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

    ans = []

    for i in range(1,6):
        t = 0
        while t+i <= len(s):
            ans.append(s[t:t+i])
            t += 1
    ans = list(set(ans))
    ans.sort()

    print(ans[k-1])


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
K = int(input())
ans = []
an = set()
for i in range(1,min(5,n)+1):
    for j in range(n-i+1):
        S = s[j:j+i]
        if S not in an:
            ans.append(S)
            an.add(S)
ans.sort()
print(ans[K-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def cin():  return list(map(int,input().split()))

S = input()
k = cin()[0]
s = set()
length = len(S)
for i in range(length):
    tmp = ""
    for j in range(5):
        if i + j < length:
            tmp += S[i + j]
            s.add(tmp)
        
s = sorted(s)
ans = s[k - 1]
print(ans)

Submission status: Accepted

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

alphabets = [chr(i + 97) for i in range(26)]

for char in alphabets:
    l = []
    for i in range(len(s)):
        if s[i] == char:
            l.append(s[i:])

    if l == []:
        continue

    if k == 1:
        print(l[0][0])
        exit()
    
    k -= 1

    strings = set([])
    for i in l:
        for j in range(2, min(k+2, len(i)+1)):
            strings.add(i[:j])
    strings = list(strings)
    strings.sort()
    
    if len(strings) >= k:
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

Submission status: Accepted

Solution code:
from itertools import combinations
s = input()
n = int(input())

le = len(s)
tmp = s[:5]

for i in range(le - 4):
    tmp = min(tmp, s[i:i+5])

seed = tuple(combinations(range(min(6, le+1)), 2))
res = set()
for i, j in seed:
    res.add(tmp[i:j])
ans = sorted(res)
print(ans[n - 1])

Submission status: Accepted

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

Submission status: Accepted

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

def substring(S):
    N = len(S)
    ls = []
    for i in range(1,min(6,N+1)):
        for j in range(0,N-i+1):
            ls.append(S[j:j+i])
    setls = set(ls)
    ls = list(setls)
    ls.sort()
    return ls
print(substring(s)[K-1])

Submission status: Accepted

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

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

res = sorted(set(a))
print(res[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
N = len(s)
sets = set()
for l in range(1, K+1):
    for i in range(N-l+1):
        subs = s[i:i+l]
        sets.add(subs)

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

Submission status: Accepted

Solution code:
S = input().rstrip()
N = len(S)
K = int(input())
A = []
for i in range(N):
    A.append(S[i:])
A.sort()
B = set()
flg = False
for i in range(len(A)):
    for j in range(1,len(A[i])+1):
        B.add(A[i][:j])
        if len(B)==K:
            flg = True
            break
    if flg: break
B = list(B)
B.sort()
print(B[-1])

Submission status: Accepted

Solution code:
s=list(input())
k=int(input())
n=len(s)
x=[]
for i in range(n):
    x.append(s[i])
if n>=2:
    for i in range(n-1):
        z=s[i]+s[i+1]
        x.append(z)
if n>=3:
    for i in range(n-2):
        z=s[i]+s[i+1]+s[i+2]
        x.append(z)
if n>=4:
    for i in range(n-3):
        z=s[i]+s[i+1]+s[i+2]+s[i+3]
        x.append(z)
if n>=5:
    for i in range(n-4):
        z=s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]
        x.append(z)
x=set(x)
x=sorted(x)
print(x[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
seen = set()
i = 1

while i<=k:
  for j in range(len(s)):
    seen.add(s[j:j+i])
  i += 1

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

Submission status: Accepted

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

    P=sorted(S)
    l=[]
    a=[]
    k=0
    while len(l)<=5 and k<N:
        if P[k] not in a:
            a.append(P[k])
            for n in range(N):
                if S[n]==P[k]:
                    for i in range(1,6):
                        if n+i<=N:
                            tmp="".join(S[n:n+i])
                            if tmp not in l:
                                l.append(tmp)
        k+=1
    l.sort()
    print(l[K-1])

if __name__=="__main__":
    main2()

Submission status: Accepted

Solution code:
from collections import deque

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

def index_Multi(List,liter):
    #Listはリスト本体・literは検索したい文字
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L

def substr(s, k, j):
    n = ord("a")

    while True:
        l = index_Multi(s, chr(n+j))
        word = []
        if len(l) == 0:
            n += 1
        else:
            for p in l:
                for i in range(k):
                    word.append(s[p:p+i+1])
            sword = set(word)
            if len(sword) >= k:
                tword = list(sword)
                tword.sort()
                #print(tword, sword)
                return tword[k-1]
            else:
                return substr(s, k-len(sword), j+1)
            break

print(substr(s, k, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if j-i<=6:
            li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1])

Submission status: Accepted

Solution code:

s = input()
n = len(s)
k = int(input())
substr = []
for j in range(1, k+1):
    for i in range(n-j+1):
        sub = s[i:i+j]
        if sub not in substr:
            substr.append(sub)
substr.sort()
print(substr[k-1])

Submission status: Accepted

Solution code:

s = input()
n = len(s)
k = int(input())
substr = []
for j in range(k):
    for i in range(n-j):
        sub = s[i:i+j+1]
        if sub not in substr:
            substr.append(sub)
substr.sort()
print(substr[k-1])

Submission status: Accepted

Solution code:
# Kは最大で５なので、1~５文字の部分文字列を全列挙して重複省いてソートすれば終わり
s = input()
K = int(input())

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

sub = list(sub)
sub.sort()

print(sub[K - 1])

Submission status: Accepted

Solution code:
from collections import Counter
s=list(input())
k=int(input())
n=len(s)
s_c=sorted(Counter(s).items())

ans=[]
for i in s_c:
    for j in range(n):
        if s[j]==i[0]:
            ans.append(s[j])
            if j+1<=n-1:
                ans.append("".join([s[j],s[j+1]]))
                if j+2<=n-1 :
                    ans.append("".join([s[j],s[j+1],s[j+2]]))
                    if j+3<=n-1:
                        ans.append("".join([s[j],s[j+1],s[j+2],s[j+3]]))
                        if j+4<=n-1:
                            ans.append("".join([s[j],s[j+1],s[j+2],s[j+3],s[j+4]]))

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

Submission status: Accepted

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

subst = []
for i in range(5):
  for j in range(len(s) - i):
    subst.append(s[j:j+i+1])

subst = list(set(subst))
subst.sort()

print(subst[K - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque


def search(moji):
    num = len(moji)
    setsn = set([])
    for i in range(len(s)-num+1):
        if s[i:i+num] == moji:
            str_ = s[i:i+num+1]
            if len(str_) == num+1:
                setsn.add(str_)
    sorted_setsn = sorted(setsn, reverse=True)

    return sorted_setsn


s = str(input())
k = int(input())
n = len(s)

sets1 = set([])
for i in range(0, len(s)):
    sets1.add(s[i])

sorted_sets1 = sorted(sets1)

# if k == 1:
#     print(sorted_sets1[0])
#     exit()
# else:
#     k -= 1

dq = deque(sorted_sets1)

while(len(dq)):
    # print(dq, k)
    moji = dq.popleft()
    k -= 1
    if k == 0:
        print(moji)
        exit()
    sorted_setsn = search(moji)

    # print(sorted_setsn)
    dq.extendleft(sorted_setsn)

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    K = I()
    subs = set()
    for j in range(1, 6):
        for i in range(len(s)):
            st = i
            en = min(st + j, len(s))
            subs.add(s[st:en])
    print(sorted(list(subs))[K-1])
main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())

    subs = set()

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

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

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())

    subs = set()

    S_sorted = sorted(set(S))
    for c_min in S_sorted:
        indices = [i for i, c in enumerate(S) if c == c_min]
        for i in indices:
            for j in range(i + 1, min(len(S) + 1, i + K + 1)):
                subs.add(S[i:j])

        if len(subs) >= K:
            break

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

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
r=[]
for right in range(0,n):
  for left in range(right+1, right+k+1):
    r.append(s[right:left])
print(sorted(set(r))[k-1])

Submission status: Accepted

Solution code:
s=list(input())
k1=int(input())
l1=set()
for i in range(len(s)):
    l1.add(s[i])
a1=[]
for i in range(len(l1)):
    a1.append(l1.pop())
a1.sort()
for i in range(len(a1)):
    str=a1[i]
    l2=set()
    for j in range(len(s)):
        if s[j]==str:
            l2.add(s[j])
            str2=s[j]
            for k in range(j+1,min(len(s),j+7)):
                str2+=s[k]
                l2.add(str2)
    if len(l2)>=k1:
        l3=sorted(l2)
        ans=l3[k1-1]
        break
    else:
        k1-=len(l2)
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
StringList = []
for TSt in range(0,N):
    for TEd in range(TSt+1,TSt+K+1):
        StringList.append(S[TSt:TEd])
SetString = sorted(set(StringList))
print(SetString[K-1])

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

s = LS2()
K = I()
n = len(s)

A = set()
for i in range(n):
    for j in range(i,min(n,i+5)):
        A.add(''.join(s[i:j+1]))

A = list(A)
A.sort()

print(A[K-1])

Submission status: Accepted

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

if K==1:
  print(sorted(s)[0])
  exit()
  
topK = sorted(s)[:min(K,len(s))]

indices=[]
for i in range(len(s)):
  if s[i] in topK:indices.append(i)
    
selected=[]
for j in range(len(indices)):
  i = indices[j]
  tmp=[]
  for k in range(min(K,len(s)-i)):
    tmp.append(s[i:i+k+1])
  selected.extend(tmp)
  
selected = sorted(set(selected))

print(selected[K-1])

Submission status: Accepted

Solution code:
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,min(i+6,len(s)+1)):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])

Submission status: Accepted

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

a_list = sorted(set(s))
for i in a_list:
  if K == 1:
    print(i)
    sys.exit()
  p = []
  for j, x in enumerate(s):
    if x == i:
      p.append(s[j:min(j+K,len(s))])
  p.sort()
  t = K
  for j in range(len(p)):
    if j != len(p) - 1:
      if p[j] == p[j+1][0:len(p[j])]:
        continue
    if len(p[j]) < t:
      t -= len(p[j]) - 1
    else:
      print(p[j][0:t])
      sys.exit()
  K = t - 1

Submission status: Accepted

Solution code:
s = str(input())
K = int(input())
# sがabcac の場合、a,bca,ac などは部分列(substring
# abc とabの場合、abの方が辞書順で小さいと判断する。
# abc とabaの場合、abaの方が小さい

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

Submission status: Accepted

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

heap = [(s[i], i) for i in range(len(s))]
heapq.heapify(heap)
seen = set()
while(k and heap):
	t,ii = heapq.heappop(heap)
	if t not in seen:
		seen.add(t)
		k-=1
		if k == 0:
			print t
	if ii + 1 < len(s):
		heapq.heappush(heap, (t + s[ii+1], ii+1))

Submission status: Accepted

Solution code:
import collections

s = input()
k = int(input())
b = collections.Counter(s)
c = sorted(b.items())
con = []
n = 0
while True:
    con.append(c[n][0])
    if len(con) == k:
        break
    for i in range(len(c)):
        check = c[n][0] + c[i][0]
        if check in s:
            con.append(check)
            if len(con) >= k:
                break
            for i_2 in range(len(c)):
                check_2 = check + c[i_2][0]
                if check_2 in s:
                    con.append(check_2)
                    if len(con) >= k:
                        break
                    for i_3 in range(len(c)):
                        check_3 = check_2 + c[i_3][0]
                        if check_3 in s:
                            con.append(check_3)
                            if len(con) >= k:
                                break
                            for i_4 in range(len(c)):
                                check_4 = check_3 + c[i_4][0]
                                if check_4 in s:
                                    con.append(check_4)
                                    if len(con) >= k:
                                        break
    if len(con) >= k:
        break                              
    n +=1
print(con[k-1])

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
k = int(input())
ss = []
for i in range(len(S)):
    for j in range(i+1, min(i+k+1, len(S)+1)):
        ss.append(S[i:j])

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

Submission status: Accepted

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

ls = len(s)

res =[]

for i in range(1,k+1):
    for j in range(ls-i+1):
        res.append(s[j:j+i])
        
ress = sorted(list(set(res)))
print(ress[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
K = int(input())
S_len = len(S)
ans = set()
for i in range(0, K+1):
    for j in range(0, S_len):
        if j + i <= S_len:
            t = S[j:j + i]
            if t != '':
                ans.add(t)
ans = list(ans)
ans.sort()
print(ans[K-1])

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

d = sorted(list(S))
x = set(d)
for c in d:
    left = S.index(c)
    while left < len(S):
        if S[left] != c:
            left += 1
            continue
        j = 2
        while j <= K:
            x.add(S[left:left+j])
            j += 1
        left += 1
    if len(x) >= K:
        break
x = sorted(list(x))
print(x[K - 1])

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = list(input())
    k = int(input())
    subs = set()
    lens = len(s)
    for i1 in range(k + 1):
        for i2 in range(lens - i1):
            subs.add("".join(s[i2:i2+i1+1]))
    subs_l = list(subs)
    subs_l.sort()
    print(subs_l[k-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    s = list(input())
    k = int(input())
    k -= 1

    d1 = defaultdict(list)
    for i, c in enumerate(s):
        d1[c].append(i)
    d2 = sorted(d1.items())

    lens = len(s)
    for d2e in d2:
        subs = set()
        subs.add(d2e[0])
        for d2ee in d2e[1]:
            end = min(lens + 1, d2ee + k + 2)
            for i1 in range(d2ee+1, end):
                subs.add("".join(s[d2ee:i1]))
        if len(subs) > k:
            subsl = list(subs)
            subsl.sort()
            print(subsl[k])
            sys.exit()
        else:
            k -= len(subs)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#辞書順で一番小さいとこからK個つくる

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

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


kouho = {}

for i in early:
    for j in range(len(s)):
        if s[j]==i:
            for l in range(k):
                kouho[s[j:j+l+1]]=0
    if len(kouho)>k:
        break

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

Submission status: Accepted

Solution code:
from string import ascii_lowercase
alp=ascii_lowercase
s=input()
k=int(input())
lst=set()
p=-1
while len(lst)<=k-1:
    p+=1
    for i in range(len(s)):
        if s[i]==alp[p]:
            for j in range(k):
                if i+j<len(s):
                    lst.add(s[i:i+j+1])
lst=sorted(lst)
print(lst[k-1])

Submission status: Accepted

Solution code:
import sys,collections
input = sys.stdin.readline

s = input().rstrip()
K = int(input())
ls = len(s)
cs = collections.deque()
for i in range(ls):
    for j in range(i+1,i+1+K):
        cs.append(s[i:j])
os = sorted(cs)
count = 0
lis = []
for i in os:
    if i not in lis:
        lis.append(i)
        count +=1
    else:
        continue
    if count == K:
        print(i)
        exit()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
l=len(s)
def find_substring_from_a(a):
    a_s=[]
    for i in range(l):
        if s[i]==a:
            for j in range(1,min(6,l-i+1 )):
                a_s.append(s[i:i+j])
    return sorted(set(a_s) )
moji_list = sorted(set(s))
length = 0
for a in moji_list:
    a_s=find_substring_from_a(a)
    lenas = len(a_s)
    if length+lenas >=k:
        break
    else:
        length+=lenas
print(a_s[k-length-1])

Submission status: Accepted

Solution code:
# C - K-th Substring

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

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

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