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:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
a = set()
for i in range(len(s)):
    t = s[i]
    a.add(t)
    if i < len(s) - 1:
        for j in range(i+1, min(i+k+1,len(s))):
            t += s[j]
            a.add(t)
b = sorted(list(a))
print(b[k-1])

Submission status: Accepted

Solution code:
# kが極端に少ないので、下位K個を管理してよさそうな気がする
# -> なんかダメ
# じゃ決め打ちして全探索することにしてみる どうせ長さは最大でKなので
# 時間的に間に合うか微妙な気がする
# -> はい

s = list(input())
k = int(input())
d = {}
for i in range(len(s)):
    for j in range(i, min(i + k, len(s))):
        t = "".join(s[i:j + 1])
        if t not in d:
            d[t] = True
dk = sorted(d.keys())
print(dk[k - 1])

Submission status: Accepted

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

li = []
for i in range(5):
    li.extend([s[j:j+i+1] for j in range(n-i)])
li = list(set(li))
li.sort()
print(li[k-1])

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
k = int(input())
n = len(s)
l = []
for i in range(5):
    l.extend([s[ii:(ii+i+1)] for ii in range(n-i)])
l = list(set(l))
l.sort()
ans = l[k-1]
print(ans)

Submission status: Accepted

Solution code:
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=sorted(sub)
print(sub[k-1])

Submission status: Accepted

Solution code:
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:
s=input()
k=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,ns):
  global cnt
  if ns in s:
    cnt+=1
  if cnt==k:
    print(ns)
    exit()
  if keta==k:
    return

  for i in abc:
    dfs(keta+1,ns+i)

cnt=0
for i in abc:
  if i not in s:
    continue
  dfs(1,i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)
K = int(input())
A = []
for k in range(1,min(6,N+1)):
    for i in range(N-k+1):
        x = S[i:i+k]
        if x not in A:
            A.append(x)
A = sorted(A)
print(A[K-1])

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

s = list(input())
K = int(input())
leng = len(s)
from heapq import heappush, heappop
Q = []
for i in range(leng):
    heappush(Q, (s[i], i))

se = set()
cnt = 0
while 1:
    a, idx = heappop(Q)
    if a not in se:
        se.add(a)
        cnt += 1
    if cnt==K:
        break
    if idx!=leng-1:
        heappush(Q, (a+s[idx+1], idx+1))

print(a)

Submission status: Accepted

Solution code:
S = str(input())
K = int(input())
N = len(S)
L = set([])

for i in range(N):
  temp = S[i]
  L.add(temp)
  for j in range(1,min(N-i,K)):
    temp += S[i+j]
    L.add(temp)
#print(L)
L = list(L)
L.sort()
print(L[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(ans)[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
d=['zzzzz']
for i in range(len(s)):
    for j in range(i+1,i+6):
        for k in range(len(d)):
            if s[i:j] not in d and s[i:j]<d[k]:
                d.insert(k,s[i:j])
                if len(d)>5:
                    d.pop()
                break
print(d[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
m=[ord("z")+1]*3
for i in range(len(s)):
    if ord(s[i])<m[0]:
      m=[ord(s[i]),m[0],m[1]]
    elif m[0]<ord(s[i])<m[1]:
      m=[m[0],ord(s[i]),m[1]]
    elif m[1]<ord(s[i])<m[2]:
      m=[m[0],m[1],ord(s[i])]

a=[]
for l2 in m:
  l=chr(l2)
  s2=s
  while l in s2:
    for i in range(5):
      a.append(s2[s2.find(l):min(s2.find(l)+i+1,len(s2))])
    s2=s2[s2.find(l)+1:]
print(sorted(set(a))[k-1])

Submission status: Accepted

Solution code:
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

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

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

Submission status: Accepted

Solution code:
import re
s = input()
k = int(input())
scl = sorted(list(set(s)))
ans = scl[:k]
for i in range(k-1):
  dans = []
  for j in ans[i:]:
    dans += re.findall(j+".",s)
    dans = sorted(list(set(dans)))[:k]
    if len(dans) == k:
      break
  ans = sorted(list(set(ans+dans)))[:k]
  #print(ans)

print(ans[-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
L = len(s)
se = set([])
def subs(l):
    for i in range(L-l+1):
        se.add(s[i:i+l])
for i in range(1,6):
    subs(i)
# print(se)
print(sorted(se)[k-1])

Submission status: Accepted

Solution code:
import heapq

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

h = []
l = set()

for i in range(len(s)):
  m = min(len(s),i+K)
  for j in range(i,m):
    heapq.heappush(h, s[i:j+1])
    
while h:
  p = heapq.heappop(h)
  l.add(p)
  if len(l) == K:
    print(p)
    exit()

Submission status: Accepted

Solution code:
a = input()
n = int(input())
t = 1
ar = []
while True:
    for i in range(len(a) - t + 1):
        if a[i:i+t] not in ar:
            ar.append(a[i:i+t])
    t += 1
    if t > len(a) or t > n:
        break
ar.sort()
print(ar[n-1])

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    k = int(input())
    ss = set()
    alp = "abcdefghijklmnopqrstuvwxyz"
    for ai in alp:
        for i,si in enumerate(s):
            if si != ai:
                continue
            nw = ""
            for sj in s[i::]:
                nw += sj
                if len(nw) > 5:
                    break
                ss.add(nw)
        if len(ss) >= k:
            break
    print(sorted(ss)[k-1])



    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

L=[]
for i in range(K):
    for j in range(N-i):
        if S[j:j+i+1] not in L:
            L.append(S[j:j+i+1])

L.sort()
ans=""
for l in L[K-1]:
    ans+=l
print(ans)

Submission status: Accepted

Solution code:
# 最大で5文字になりそうなので上位K個を保持しつつ全探索
s = input() + " "
k = int(input())
ans = []
for i in range(len(s)):
    for j in range(i + 1, min(len(s), i + 5 + 1)):
        t = "".join(s[i:j])
        if t not in ans:
            ans.append(t)
            ans = sorted(ans)[:6]
print(ans[k - 1])

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()

    K = int(input())

    subsrings = [s[i : i + K + 1] for i in range(len(s))]
    subsrings.sort()

    first = set()

    for s in subsrings:

        for i in range(1, len(s) + 1):
            if s[:i] not in first:
                first.add(s[:i])
                if len(first) == K:
                    print(s[:i])
                    break

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
k = int(input())
ans = set()

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

Submission status: Accepted

Solution code:
import sys
from heapq import heapify, heappop

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    k = int(input())
    n = len(S)

    SS = set()
    for i in range(n):
        ss = S[i]
        SS.add(ss)
        for j in range(i + 1, min(n, i + k)):
            ss += S[j]
            SS.add(ss)

    SS = list(SS)
    heapify(SS)
    for _ in range(k):
        res = heappop(SS)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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


def solve(s: str, K: int):
    pool = set()
    for l in range(K):
        for i in range(0, len(s)-l):
            pool.add(s[i:i+l+1])
    return sorted(pool)[K-1]


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    print(solve(s, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(input())
ans = set()
for i in range(N):
    for j in range(i + 1, i + K + 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 c in "abcdefghijklmnopqrstuvwxyz":
    for i in range(N):
        if S[i] == c:
            for j in range(i + 1, i + K + 1):
                ans.add(S[i:j])
    if len(ans) >= K:
        break
print(sorted(list(ans))[K - 1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
ans = set()
r = len(s)

if r == 1:
    print(s)
else:
    for i in range(r):
        for j in range(k):
            ans.add(s[i:i+j+1])
    print(sorted(list(ans))[k-1])

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = sr()
k = ir()
dic = {}
for l in range(5):
    for i in range(len(s)-l):
        tmp = s[i:i+l+1]
        dic[tmp] = 1
ans = []
for key in dic.keys():
    ans.append(key)
ans.sort()
print(ans[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

s = list(input())
K = int(input())
d = defaultdict(int)
L = min(len(s), 5)

for i in range(L):
  for j in range(len(s)-i):
    x = s[j]
    for k in range(i):
      x += s[j+k+1]
    d[x] += 1

D = sorted(d.keys())

print(D[K-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter

s = str(input())
k = int(input())
d = Counter(s)
L = sorted(d.keys())[:k]
ss = set()
for c in L:
    for i in range(len(s)):
        if s[i] == c:
            ss.add(s[i])
            for j in range(1, k+1):
                if i + j >= len(s):
                    break
                else:
                    ss.add(s[i:i+j+1])
print(sorted(ss)[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
buf = dict()
for i in range(len(s)):
    for j in range(1,6):
        if j > len(s):
            break
        buf[s[i:i+j]] = True
keys = buf.keys()
buf = list(buf)
buf.sort()
#print(buf)
print(buf[k-1])

Submission status: Accepted

Solution code:
s=list(input())
k=int(input())
n=len(s)
subset=[]
from bisect import bisect_left

for i in range(n):
    tmp=s[i]
    for j in range(i,min(n,i+5)):
        if j==i: pass
        else: tmp+=s[j]
        if tmp not in subset:
            l=bisect_left(subset, tmp)
            if 0<=l<5:
                subset=subset[:l]+[tmp]+subset[l:5]
                subset=subset[:5]
            else:
                break
print(subset[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
pool = set()
n = 0
slist = list(s)

for i in range(26):
  c = s.count(chr(97+ i))
  for j in range(c):
    index = slist.index(chr(97+ i))
    slist[index] = ""
    for k in range(len(s)- index):
      pool.add(s[index:index+ k+ 1])
      if(k>= K):
        break
  if(len(pool)>= K):
    newlist = list(pool)
    newlist.sort()
    print(newlist[K- 1])
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations


def main():
    s, k = input(), int(input())
    l, tmp = len(s), s[:5]
    for i in range(l - 4):
        tmp = min(tmp, s[i:i + 5])
    res = set()
    for i, j in combinations(range(min(6, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations


def main():
    s, k = input(), int(input())
    l, tmp = len(s), s[:k]
    for i in range(l - k + 1):
        tmp = min(tmp, s[i:i + k])
    res = set()
    for i, j in combinations(range(min(k + 1, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations


def main():
    s, k = open(0).read().split()
    k, l = int(k), len(s)
    tmp = s[:k]
    for i in range(l - k + 1):
        tmp = min(tmp, s[i:i + k])
    res = set()
    for i, j in combinations(range(min(k + 1, l + 1)), 2):
        res.add(tmp[i:j])
    ans = sorted(res)
    print(ans[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = len(s)
array = []

for i in range(n):
    for j in range(i + 1, i + 6):
        end = min(n, j)
        ss = s[i:end]
        array.append(ss)

array = set(array)
array = sorted(array)
print(array[k - 1])

Submission status: Accepted

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

part = set()
for i in range(n):
    for j in range(k):
        part.add("".join(s[i:i+j+1]))

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

Submission status: Accepted

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

lis=[]
for i in range(len(s)):
    lis.append(s[i:i+5])
    lis.sort()

l=[]
for i in lis[:5]:
    for j in range(5):
        l.append(i[:j+1])

l=set(l)
l=list(l)

l.sort()

print(l[k-1])

Submission status: Accepted

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

koho=set()
for i in range(n):
    for j in range(i+1, min(i+k+1, n+1)):
        c=s[i:j]
        if c not in koho:
            koho.add(c)
ans=sorted(list(koho))
print(ans[k-1])

Submission status: Accepted

Solution code:
#4問目
s = input()
K = int(input())
result = []
for i in range(1, min(len(s)+1, 6)):
    if(i == 1):
        for j in list(s):
            result.append(j)
    else:
        n = 0
        m = n + i
        while m <= len(s):
            result.append(s[n:m])
            n += 1
            m = n + i

result = set(result)
s = sorted(result)
print(s[K-1])

Submission status: Accepted

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

print(sorted(list(a))[int(input())-1])

Submission status: Accepted

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

se = set()

def string(now,num):
    if now+num == s or num == k:
        return
    se.add(s[now:now+num+1])
    num += 1
    return string(now,num)

for i in range(S):
    string(i,0)

se = list(se)
se.sort()

print(se[k-1])

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

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

se = set()
for i in range(N):
    for j in range(i+1, min(i+6, N+1)):
        T = S[i:j]
        se.add(T)
ans = sorted(se)
print(ans[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
s_dic = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, c in enumerate(s):
    s_dic[c].append(i)
substrings = set()
for indices in s_dic.values():
    for i in indices:
        for j in range(i + 1, i + K + 1):
            substrings.add(s[i:j])
print(sorted(list(substrings))[K - 1])

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    K = int(input())
    substr = set()
    N = len(s)
    for i in range(N):
        for j in range(1, min(6, N - i + 1)):
            substr |= {s[i:i+j]}
    sl = list(substr)
    sl.sort()
    print(sl[K-1])

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

s = input()
n = len(s)
k = int(input())
ans = []
used = set()
"""
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[s[i]].append(i)
""" 
for i in range(n):
    start = list(s[i])
    if s[i] not in used:
        ans.append(s[i])
        used.add(s[i])
    for j in range(i + 1, min(i + k, n)):
        start.append(s[j])
        temp = "".join(start)
        if temp not in used:
            ans.append(temp)
            used.add(temp)
ans.sort()
print(ans[k - 1])

Submission status: Accepted

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]

for i in range(97, 123):
    moji = chr(i)
    if moji not in dic:
        continue
    kouho = dic[moji]
    strings = set([])
    for idx in kouho:
        e = idx+1
        string = set([])
        while e <= n and len(string) <= k:
            string.add(s[idx:e])
            e += 1
        strings = strings | string
    if len(strings) >= k:
        strings = list(strings)
        strings.sort()
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

Submission status: Accepted

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

n = len(s)

import copy
l = copy.copy(s)
l = set(l)
l = list(l)
l.sort()
#print(l)

ans = set()
for i in range(len(l)):
    for j in range(n):
        if s[j] == l[i]:
            p = j
            temp = []
            while p < n and p-j+1 <= k:
                temp.append(s[p])
                ans.add(''.join(temp))
                p += 1
    if len(ans) >= k:
        break
#print(ans)
ans = list(ans)
ans.sort()
print(ans[k-1])

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        #print("q", queue)
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
        ans = list(set(ans))
    else:
        c = key.pop(0)
        #print("pop", c)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(min(5, len(s) - i)):
                queue.append(s[i:i+j+1])

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

Submission status: Accepted

Solution code:
s = input() + "{{{{{"
K = int(input())
L = []
t = 0
while t <= K:
    for k in range(len(s)-t):
        if "{" not in s[k:k+t+1]:
            L.append(s[k:k+t+1])
    t += 1
L = sorted(list(set(L)))
print(L[K-1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
K = int(input())
l = []

for i in range(len(S)):
    for j in range(i, min(len(S), i+5)):
        l.append(S[i:j+1])

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

Submission status: Accepted

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

A = set()
for leng in range(1, K + 1):
    for i in range(len(S) - leng + 1):
        A.add(S[i: i + leng])
A = list(A)
A.sort()

print(A[K - 1])

Submission status: Accepted

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

l=[]
st=set()
n=len(s)
for i in range(1,min(n,5)+1):
    for j in range(n+1-i):
        tmp=s[j:j+i]
        if tmp not in st:
            l.append(tmp)
            st.add(tmp)
l.sort()
print(l[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = int(input())
li = set()
def insert(x):
    if x in li:
        return
    if len(li)<k:
        li.add(x)
    elif x<max(li):
        li.remove(max(li))
        li.add(x)

for i in range(26):
    b = chr(i+ord('a'))
    for i in range(len(s)):
        if s[i]!=b:
            continue
        for j in range(k):
            if i+j<len(s):
                insert(s[i:i+j+1])
    if len(li)==k:
        break
li = list(li)
li.sort()
print(li[k-1])

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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


# ===CODE===


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

    substring = set()
    for i in range(97, 97 + 26):
        word = chr(i)

        for j in range(len(s)):
            if s[j] == word:
                tmp = s[j:j + k]

                while len(tmp) > 0:
                    substring.add(tmp)
                    tmp = tmp[:-1]

        if len(substring) >= k:
            break

    ans = list(substring)
    ans.sort()

    print(ans[k - 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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()
N = len( s )
K = int( input() )

s_set = set()
for j in range( 1, K + 1 ):
  for i in range( N - j + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
alp = "abcdefghijklmnopqrstuvwxyz"
candidate_orig = set()

def hoge(c_list, rank, candidate):
    if len(candidate) >= 5:
        return candidate

    cur_targets = {}
    for l in sorted(c_list):
        if l + rank > len(s) - 1:
            continue
        _sub = s[l: l + 1 + rank]
        if _sub not in cur_targets:
            cur_targets[_sub] = [l]
        else:
            cur_targets[_sub].append(l)

    if len(cur_targets) == 0:
        return candidate

    for _d in sorted(cur_targets.items(), key=lambda x: x[0]):
        candidate.add(_d[0])
        candidate = hoge(_d[1], rank + 1, candidate)
        return candidate

    return candidate

for a in alp:
    idx_list = []
    for i, _s in enumerate(s):
        if a == _s:
            idx_list.append(i)
            candidate_orig.add(_s)
    candidate = hoge(idx_list, 1, candidate_orig)
    if len(candidate) >= 5:
        break

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

Submission status: Accepted

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

    tank = set()
    for k in range(1, K + 1):
        for i in range(N - k + 1):
            t = S[i:i + k]
            tank.add(t)

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


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(K):
    t= s[i:i+j+1]
    #print(i,j,t)
    tmp.add(t)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])

Submission status: Accepted

Solution code:

S = input().strip()
K = int(input())
L = len(S)
substr = set()

for i in range(L):
    for j in range(5):
        s = S[i:min(i+j+1, L)]
        if s:
            substr.add(s)

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

Submission status: Accepted

Solution code:
s=input()
K=int(input())
abc=list("abcdefghijklmnopqrstuvwxyz")

N=len(s)
L=[]
flag=False
for a in abc:
    for i in range(N):
        if s[i]==a:
            L.append(s[i:])
            
    if flag:
        break
L=sorted(L)
#print(L)
ans=[]
for l in L:
    n=len(l)
    for i in range(n):
        t=l[:i+1]
        if t not in ans:
            ans.append(l[:i+1])
    if len(ans)>=K:
        break
#print(ans)
print(ans[K-1])

Submission status: Accepted

Solution code:
from string import ascii_letters

def solve(word):
    for c in ascii_letters:
        sub = word + c
        if sub in s:
            words.append(sub)
            if len(words) == k:
                print(sub)
                exit()
            solve(sub)

s = input()
k = int(input())
words = []
solve('')

Submission status: Accepted

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

    tmp = [[] for _ in range(26)]
    for i in range(N):
        tmp[ord(S[i]) - ord('a')].append(i)

    lst = []
    lst_append = lst.append
    s = set()
    s_add = s.add
    for num in tmp:
        for i in num:
            for j in range(i + 1, min(N, i + K) + 1):
                if S[i:j] in s:
                    continue
                else:
                    s_add(S[i:j])
                    lst_append(S[i:j])
        if len(s) >= K:
            lst.sort()
            print (lst[K - 1])
            # print (lst)
            return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop

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

min_s = sorted(list(set(s)))

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

ans = sorted(list(set(q)))[K-1]

print(ans)

Submission status: Accepted

Solution code:
def solve():
    S = input()
    K = int(input())
    strlist = sorted(list(S))
    lis = set()
    p = 0
    while len(list(lis))<K:
        a = strlist[p]
        if len(S)>=5:
            for i,s in enumerate(S):
                if s==a:
                    for j in range(i+1,min(len(S)+1,i+K+1)):
                        lis.add(S[i:j])
        else:
            for i in range(len(S)):
                for j in range(i+1,len(S)+1):
                    lis.add(S[i:j])
        p += 1
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())