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:
def main():
    all_s = input()
    k = int(input())
    substr = set()
    for i in range(len(all_s)):
        for j in range(1, k + 1):
            substr.add(all_s[i:i + j])
    substr = list(substr)
    substr.sort()
    print(substr[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

T = []
#for i in range(1,min(K,len(s))):
#  T.append(s[:i+1])
#print(T)

for i in range(len(s)): #i文字目スタート
  for j in range(i+1,min(len(s)+1,i+K+1)): #j文字
    temp = s[i:j]
    if temp in T:
      continue
    if len(T) < K:
      T.append(temp)
      T.sort()
    else:
      Flag = False
      for t in range(K):
        if temp < T[t]:
          #print(temp,T[t],T)
          T.insert(t,temp)
          Flag = True
          break
      if Flag:
        T.pop()
print(T[K-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

ans_lis = []
for i in range(min(5, len(lis))):
    i = lis[i]
    s2 = s
    while 1:
        idx = s2.find(i)
        if idx==-1:
            break
        ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx))]
        s2 = s2[idx+1:]
ans_lis = list(set(ans_lis))
ans_lis.sort()
print(ans_lis[K-1])

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())


finish = set()
S = len(s)

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

finish = list(finish)
finish.sort()

print(finish[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
se = (s)
k = int(input())
n = len(s)

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










#TLE 
'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
'''

Submission status: Accepted

Solution code:
# AtCoder Regular Contest 097
# C - K-th Substring
# https://atcoder.jp/contests/arc097/tasks/arc097_a
from itertools import zip_longest
from collections import Counter

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

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

subs = list(subs)
subs.sort()

print(subs[K-1])

Submission status: Accepted

Solution code:
def main():
    s = input()
    k = int(input())
    c = set()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N=len(s)
ln=0
siki_sub=''
result={}

for i in range(N):
    for j in range(min(N-i,K+1)):
        if ln<K:
            if s[i:i+j+1] not in result:
                result[s[i:i+j+1]]=1
                siki_sub=max(result)
                ln+=1
        else:
            if siki_sub>s[i:i+j+1] and s[i:i+j+1] not in result:
                del result[siki_sub]
                result[s[i:i+j+1]]=1
                siki_sub=max(result)

print(siki_sub)

Submission status: Accepted

Solution code:
letter=input()
K=int(input())
import re
ans=[]
X=[chr(i) for i in range(97, 97+26)]
for i in X:
   if i in letter:
      c=[m.end() for m in re.finditer(i, letter)]
      for j in c:
         for i in range(K):
            if j-1+i==len(letter):
               break
            ans.append(letter[j-1:j+i])
   ans=list(set(ans))
   if len(ans)>=5:
      break
ans.sort()
print(ans[K-1])

Submission status: Accepted

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

for i in range(n):
    end = min(n, i+K)
    for j in range(i+1, end+1):
        ans.add(s[i:j])

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

Submission status: Accepted

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

for i in range(n):
    end = min(n, i+10)
    for j in range(i+1, end+1):
        ans.add(s[i:j])

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
k = inn()
n = len(s)
cnt = 0
u = set([])
for i in range(26):
    c = chr(ord('a')+i)
    t = s
    while len(t)>0:
        j = t.find(c)
        if j<0:
            break
        for m in range(j+1,min(j+6,n+1)):
            #ddprint(f"j {j} m {m} tjm {t[j:m]}")
            u.add(t[j:m])
            cnt += 1
        t = t[j+1:]
    #if cnt>=k:
    if len(u)>=k:
        break
#print(u)
u = list(u)
u.sort()
print(u[k-1])

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    N = len(S)
    sub = set()
    for i in range(N):
        for j in range(1, K + 1):
            sub.add(S[i:i + j])

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


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

    N = len(S)
    sub = set()
    for al in AL:
        for i in range(N):
            if S[i] == al:
                for j in range(1, 6):
                    sub.add(S[i:i + j])
        if len(sub) >= K:
            break

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = list(input().rstrip())
    K = int(input().strip())
    q = ["zzzzzz"] * K
    for i in range(len(S)):
        s = S[i]
        if s < q[-1] and s not in q:
            q[-1] = s
            q.sort()
        for j in range(1, K):
            if i+j < len(S):
                s += S[i+j]
                if s < q[-1] and s not in q:
                    q[-1] = s
                    q.sort()
    print(q[-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:



S = input()
N = len(S)
K = int(input())

ans = []

for k in range(1, K+1):
    for i in range(0, N-k+1):

        ans.append(S[i:i+k])

ans = list(set(ans))
ans.sort()

print(ans[K-1])

Submission status: Accepted

Solution code:
import heapq
s=input()
k=int(input())
n=len(s)
ls=[[si,i] for i,si in enumerate(list(s))]
heapq.heapify(ls)
seen=set()
c=0
while c<k:
  a=heapq.heappop(ls)
  if a[0] not in seen:
    seen.add(a[0])
    c+=1
    #print(c,a[0])
    if c==k:
      print(a[0])
      exit()
  if len(a[0])+a[1]<n:
    a[0]+=s[len(a[0])+a[1]]
    heapq.heappush(ls,a)

Submission status: Accepted

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

lis=[]

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    S = input()
    k = int(input())
    n = len(S)
    candidate = set()
    for l in range(1, k + 1):
        for i in range(n - l + 1):
            candidate.add(S[i : i + l])
    print(sorted(candidate)[k - 1])
resolve()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    N = len(s)
    sub = []
    for i in range(N):
        for j in range(K):
            sub.append(s[i:i+j+1])
    sub = set(sub)
    sub = sorted(sub)
    ans = sub[K-1]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


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

    N = len(s)
    total = 0
    for al in AL:
        induces = []
        for i in range(N):
            if al == s[i]:
                induces.append(i)
        if not induces:
            continue
        match = [al]
        for i in range(1, 5):
            for idx in induces:
                if idx + i < N:
                    match.append(s[idx:idx + i + 1])
        match = set(match)
        match = sorted(match)
        if total + len(match) >= K:
            ans = match[K - 1 - total]
            break
        else:
            total += len(match)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

st = set()
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if j-i<=k: st.add(s[i:j])
print(sorted(list(st))[k-1])

Submission status: Accepted

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

a = []
for i in range(n):
    for j in range(i+1,n+1):
        if j - i > k:break
        a.append(s[i:j])
b = sorted(set(a))
print(b[k-1])

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    N = len(S)
    substring = set()
    for i in range(N):
        for j in range(1, 6):
            substring.add(S[i:i + j])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
k = int(input())
n = len(s)
bb = Counter(s)
b = list(bb)
b.sort()
a = set([])

for l in range(k):
    for i in range(n):
        if s[i] == b[l]:
            for j in range(5):
                if i + j > n:
                    break
                a.add(s[i:i+1+j])
    if len(a) >= k:
        break
        
b = list(a)
b.sort()
print(b[k-1])

Submission status: Accepted

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

ss = sorted(s)
uego = list(set([ss[i] for i in range(len(ss))][:5]))

la = []
for i in range(len(s)):
  if s[i] in uego:
    for j in range(5):
      if i+j >= len(s):
        break
      la.append(s[i:i+j+1])
la = list(set(la))
la.sort()
print(la[K-1])

Submission status: Accepted

Solution code:
s = str(input())
k = int(input())
lis = []
for u in range(6):
	for i in range(len(s)):
		try:
			if s[i:i+u] == "":
				continue
			if s[i:i+u] not in lis:
				lis.append(s[i:i+u])
		except:
			continue
lis.sort()
print(lis[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1]
print(a)

Submission status: Accepted

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

a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1]
print(a)

Submission status: Accepted

Solution code:
s = input()
k = int(input())
n = len(s)
rank = ["zzzzzz"]*k
for i in range(n):
  for j in range(i+1, min([i+k+1, n+1])):
    key = s[i:j]
    for r in range(k):
      if key == rank[r]:
        break
      if key < rank[r]:
        for r2 in range(r, k):
          key2 = rank[r2]
          rank[r2] = key
          key = key2
        break
print(rank[k-1])

Submission status: Accepted

Solution code:
s=input();k=int(input());print(sorted({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());q=[]
for i in range(len(s)):
 for j in range(k):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k]
print(q[-1])

Submission status: Accepted

Solution code:
s,k=open(0);k=int(k);q=[];N=len(s)
for i in range(N):
 for j in range(min(k,N-1-i)):x=s[i:i+j+1];q=q if x in q else sorted(q+[x])[:k]
print(q[-1])

Submission status: Accepted

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


def ins(x):
    if len(smallests) == k and x > smallests[-1]:
        return
    if x in smallests:
        return
    smallests.append(x)
    smallests.sort()
    while len(smallests) > k:
        smallests.pop()


def solve():
    for i in range(len(s)):
        for size in range(1, k + 1):
            if i + size > len(s):
                break
            ins(s[i : i + size])
    return smallests[-1]


print(solve())

Submission status: Accepted

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

lst = []
for i in range(n):
	for j in range(1, 6):
		tmp = s[i:i+j]
		lst.append(tmp)

lst = list(set(lst))
lst.sort()

print(lst[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# aba
# 最も小さい一文字はa
# a
# それに続く文字はb, （空文字）なので、ab
# それに続くのはaba
# ここで空文字しか続かなくなるため、
# 次はb
# たかだか5なので強引にいけんじゃね？

S=input()
K=int(input())
ans = []

from collections import defaultdict
dic = defaultdict(list)
for i in range(len(S)):
  dic[S[i]].append(i)

sortedS = sorted(dic.items(),key = lambda x:x[0])

# print(sortedS)

ans = set()
for candi in sortedS:
  ch,inds = candi[0],candi[1]
#  print(ch,inds)
  for i in inds:
    for j in range(K):
      ans.add(S[i:i+j+1])
  if len(ans) >= K:
    break
      
print(sorted(list(ans))[K-1])

Submission status: Accepted

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

N = len(S)
Q = set()
for i in range(N):
    Q.add(S[i])
    if i<N-1:Q.add(S[i:i+2])
    if i<N-2:Q.add(S[i:i+3])
    if i<N-3:Q.add(S[i:i+4])
    if i<N-4:Q.add(S[i:i+5])
Q = sorted(list(Q))
print(Q[K-1])

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
ls = len(s)
aset = set()

for i in range(ls):
    for k in range(1, K+1):
        if i+k <= ls:
            aset.add(s[i:i+k])

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

Submission status: Accepted

Solution code:
#!python3

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


def main():
    n = len(s)
    alpha = [chr(i) for i in range(97, 97+26)]
    d = {x: [] for x in alpha}
    for i in range(n):
        d[s[i]].append(i)

    st = set()
    for i in range(n):
        for j in range(1, 6):
            if i + j > n:
                break
            st.add(s[i:(i + j)])
    
    ans = sorted(st)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt = 0
tmp = 0
lst = []
tmp_s = "zzz"

if(len(s)>= 5):
    for i in range(len(s)-4):
        if(tmp_s >= s[i:(i+5)]):
            tmp_s = s[i:(i+5)]

    for j in range(len(tmp_s)):
        for k in range(j+1, len(tmp_s)+1):
            if(tmp_s[j:k] not in lst):
                lst.append(tmp_s[j:k])
        
    lst.sort()
    print(lst[K-1])
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            if(s[i:j] not in lst):
                lst.append(s[i:j])
    lst.sort()
    print(lst[K-1])

Submission status: Accepted

Solution code:
s = input()
li = list(s)
k = int(input())
tmp = []
for i,l in enumerate(li):
    for kk in range(k):
        #print(i,l,kk)
        if i+kk <= len(li):
            tmp.append(''.join(li[i:i+1+kk]))
#print(tmp)
print(sorted(set(tmp))[k-1])

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():

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

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

    print(sorted(set(ls))[K-1])


resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = Scanner.string()
    k = Scanner.int()
    N = len(S)
    M = set()
    for i in range(N):
        for j in range(k):
            M.add(S[i: i + j + 1])
    M = sorted(list(M))
    print(M[k - 1])


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

n = len(s)
sub = set()

for i in range(n):
    for j in range(k):
        sub.add(s[i:i+j+1])

sub = sorted(list(sub))

print(sub[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
D = {}
n = len(s)
for i in range(K):
  for j in range(n-i):
    D[s[j:j+i+1]] = 1
L = [i for i in D]
L.sort()
print(L[K-1])

Submission status: Accepted

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()

s=list(input())
K=int(input())
N=len(s)
lst=[]
lstset=set()
for i in range(N):
    for m in range(i+1,min(N+1,i+6)):
        c="".join(s[i:m])
        if not c in lstset:
            lst.append(c)
            lstset.add(c)
lst.sort()
print(lst[K-1])

Submission status: Accepted

Solution code:
# 解説

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

st = set()
for start in range(len(s)):
    for len_ in range(1, k + 1):
        st.add(s[start:start + len_])
*a, = sorted(st)
print(a[k - 1])

# 高々k文字
# kが小さいので
# 全列挙してソート

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  k = int(input())
  ls = set()
  for i in range(1, k+1):
    for j in range(len(s)-i+1):
      ls.add(s[j:j+i])
  ls = sorted(list(ls))
  print(ls[k-1])

if __name__=='__main__':
  main()

Submission status: Accepted

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

substring_list = []
for i in range(1, 5+1):
    for start in range(len(s) - i + 1):
        substring_list.append(s[start:start+i])

# print(substring_list)
substring_list = sorted(set(substring_list))
print(substring_list[k-1])

Submission status: Accepted

Solution code:
# 最小かつ最長はzzzzzなので各文字+4まで調べてみるか（27^5-1で全探索もできると思うがやり方がわからん
s = input()
k = int(input())
d = set()
for i in range(len(s)):
    for j in range(1, 6):
        if i + j <= len(s):
            d.add(s[i : i + j])
print(sorted(list(d))[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

st=set()
s_len=len(s)

length=1
while length<=min(s_len,k):
  for i in range(s_len-length+1):
    sub_s=s[i:i+length]
    st.add(sub_s)
  length+=1

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

Submission status: Accepted

Solution code:
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k-1])

Submission status: Accepted

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

sublst=[sorted(list(set([s[i] for i in range(n)])))]
ret=[]

def dfs(l,i):
    if len(sublst)<l+1 and n-l>0:
        sublst.append(sorted(list(set([s[i:i+l+1] for i in range(n-l)]))))
    
    ret.append(sublst[l-1][i])

    if len(ret)>=k:
        return
    
    if l<=n-1:
        for j in range(len(sublst[l])):
            if sublst[l][j][:-1]==sublst[l-1][i]:
                dfs(l+1,j)
    
    if l==1 and len(sublst[0])>i+1:
        dfs(1,i+1)

dfs(1,0)

print(ret[k-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
import sys

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()
K = int(sys.stdin.buffer.readline())

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

Submission status: Accepted

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

subs = []

for i in range(0,K + 1):
  for j in range(0,len(s) - i):
    sub = s[j:j + i + 1]
    subs.append(sub)
    
subs = sorted(list(set(subs)))

print(subs[K - 1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
li = []
l = 0
r = min(len(s), 5)

while l != r:
    s1 = s[l:r]
    for i in range(1,len(s1)+1):
        s2 = s1[:i]
        li.append(s2)

    if r < len(s):
        r += 1
    l += 1

li = list(set(li))
li.sort()

print(li[k-1])

Submission status: Accepted

Solution code:
from collections import Counter
s = str(input())
K = int(input())
st = set()
for l in range(1,K+1):
    for i in range(len(s)-l+1):
        st.add(s[i:i+l])
print(sorted(list(st))[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
s = input()
K = int(input())
st = set()
for i in range(5):
    for j in range(len(s)-i):
        st.add(s[j:j+i+1])
ls = list(st)
print (sorted(ls)[K-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    K = Scanner.int()
    m = []
    N = len(S)
    for i in range(N):
        for j in range(i, min(i+K, N)):
            m.append(S[i: j + 1])
    m = sorted(set(m))
    print(m[K-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def slv(S, K):
    d = set([])
    for i in range(len(S)):
        for j in range(i + 1, i + 1 + K):
            d.add(S[i:j])

    return sorted(d)[K - 1]


def main():
    S = read_str()
    K = read_int()
    # K = 3
    # S = ''.join([random.choice('abcdefghijklmnopqrstu') for _ in range(5000)])
    print(slv(S, K))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
ans=dict()
for i in range(n):
  t=str()
  for j in range(min(5,n-i)):
    t+=s[i+j]
    ans[t]=0
ans=sorted(list(ans.keys()))
print(ans[k-1])