Problem:


Score : 300 points

Problem Statement

You are given a string s.
Among the different substrings of s, print the K-th lexicographically smallest one.

A substring of s is a string obtained by taking out a non-empty contiguous part in s.
For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.
Also, we say that substrings are different when they are different as strings.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 ≤ |s| ≤ 5000

s consists of lowercase English letters.

1 ≤ K ≤ 5

s has at least K different substrings.

Partial Score

200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.

Input

Input is given from Standard Input in the following format:

s
K

Output

Print the K-th lexicographically smallest substring of K.

Sample Input 1

aba
4

Sample Output 1

b

s has five substrings: a, b, ab, ba and aba.
Among them, we should print the fourth smallest one, b.
Note that we do not count a twice.

Sample Input 2

atcoderandatcodeer
5

Sample Output 2

andat

Sample Input 3

z
1

Sample Output 3

z



Sample input:
aba
4


Sample output:
b

Submission status: Accepted

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

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

se=set(li)
sli=list(se)
sli.sort()
#print(sli)
print(sli[k-1])

Submission status: Accepted

Solution code:


def read_input():
    s = input()
    k = int(input())
    return s, k


# sから、candsの間に挟まる文字列(長さl)を探す
def search_insertion(s, cands, l):
    result = []

    for i in range(len(s)):
        for c in cands:
            if s[i:i+l].startswith(c):
                result.append(s[i:i+l])

    cands.extend(result)
    cands = list(set(cands))
    return cands


def sort_s(cands):
    t = [[c for c in s] for s in cands]
    t.sort()
    return [''.join(s) for s in t]


def submit():
    s, k = read_input()

    cands = list(set([c for c in s]))
    precands = None
    for i in range(2, len(s) + 1):
        cands = search_insertion(s, cands, i)
        cands = sort_s(cands)
        cands = cands[:k]

        if precands == cands:
            break
        precands = cands[:]

    print(cands[-1])

if __name__ == '__main__':
    submit()

Submission status: Accepted

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


def solve(s: str, K: int):
    pq = []
    for i, c in enumerate(s):
        heapq.heappush(pq, (c, i))

    ret = set()
    while len(ret) < K:
        cs, i = heapq.heappop(pq)
        ret.add(cs)
        if i < (len(s) - 1):
            heapq.heappush(pq, (cs + s[i+1], i+1))
    ret = sorted(list(ret))
    print(ret[K-1])


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(s, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
k = int(input())
ans = []
for i in range(1,k+1):
  for j in range(len(s)):
    if j+i > len(s): break

    ans.append(s[j:j+i])


ans = list(sorted(set(ans))) #setはsortedではソートできる。リストでソートしてsetにすると順序は保証されない

if k != 1:
  print((ans[k-1]))
else:
  print(min(list(s)))

Submission status: Accepted

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

l = {s}
for n in range(1, K+1):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])

l = list(l)

l.sort()

print(l[K-1])

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
	S = input()
	K = int(input())
	sub = defaultdict(set)
	for i in range(len(S)):
		sub[S[i]].add(S[i:len(S)+1])

	alphabet = [chr(ord('a') + i) for i in range(26)]
	ans = set()
	for c in alphabet:
		if c in sub:
			this_list = list(sub[c])
			this_list.sort()
			for e in this_list:
				for i in range(1, len(e)+1):
					ans.add(e[:i])
					if len(ans) == K:
						print(e[:i])
						return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 最長で5文字なのでN*Kでいける

s = input().rstrip()  # python、無駄に改行コードを扱いがち
k = int(input())

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(s: str, K: int):
    N = len(s)
    for i in range(ord('a'), ord('z')+1):
        c = chr(i)
        l = -1
        subs = []
        while c in s[l+1:]:
            l = s.index(c, l+1)
            for r in range(l+1, min(N+1, l+1+K)):
                subs.append(s[l:r])
        subs = sorted(list(set(subs)))
        if len(subs) > K-1:
            break
        else:
            K -= len(subs)
            continue
    print(subs[K-1])
    return


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
    solve(s, K)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a=set([])

for x in range(len(s)):
	for y in range(x, x+5):
		a.add(s[x:y+1])

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

Submission status: Accepted

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

n = len(s)

ex = [s[:min(K, n)]]
for i in range(n):
    if i + K - 1 < n:
        if ex[0] > s[i:i+K]:
            ex[0] = s[i:i+K]
    else:
        if ex[0][:n-i] > s[i:]:
            ex.insert(0, s[i:])


for n in range(len(ex)):
    for i in range(len(ex[n])):
        for j in range(i+1, len(ex[n])+1):
            ex.append(ex[n][i:j])

ex = set(ex)
ex = sorted(list(ex))

print(ex[K-1])

Submission status: Accepted

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

a=set()
for x in sorted(list(set(s))):
    for i in range(len(s)):
        if s[i]==x:
            for j in range(K):
                if i+j+1>len(s): break
                a.add(s[i:i+j+1])
         

    if len(a)>=K: break

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

Submission status: Accepted

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

a=set()
for x in "abcdefghijklmnopqrstuvwxyz":
    for i in range(len(s)):
        if s[i]==x:
            for j in range(K):
                if i+j+1>len(s): break
                a.add(s[i:i+j+1])
         

    if len(a)>=K: break

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

Submission status: Accepted

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

subs = set()
L = len(s)
for l in range(1,min(L,5)+1):
    for i in range(L-l+1):
        subs.add(s[i:i+l])
print(sorted(list(subs))[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

n = len(s)

sub = []
alp = [chr(i) for i in range(ord('a'), ord('z')+1)]

for a in alp:
    if a in s:
        start = -1
        while True:
            start = s.find(a, start+1)
            if start==-1:
                break
            for j in range(start+1, min(start+K+1,n+1)):
                if s[start:j] not in sub:
                    sub.append(s[start:j])
    if len(sub) > K:
        break

sub.sort()
print(sub[K-1])

Submission status: Accepted

Solution code:
def strcmp(x, y):
    short = min(len(x), len(y))
    for i in range(short):
        if ord(x[i]) < ord(y[i]): #xの方が辞書順で小さい
            return 0
        elif ord(x[i]) > ord(y[i]):
            return 1
    if short == len(x):
        return 0
    else:
        return 1

s = input()
lens = len(s)
K = int(input())
jisho = [] #辞書順に文字列を格納
#列挙するパターン: 25000通り以下
#K文字以下の文字列を全て格納する
for i in range(1, K+1):
    for j in range(lens-i+1):
        temp = s[j:j+i]
        if temp not in jisho:
            jisho.append(temp)

size = len(jisho)-1
for i in range(K):
    for j in range(size, 0, -1):
        if strcmp(jisho[j], jisho[j-1]) == 0:
            temp = jisho[j-1]
            jisho[j-1] = jisho[j]
            jisho[j] = temp
print(jisho[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
sub = []
for i in range(len(s)):
    for j in range(i, min(i+K, len(s))):
        sub.append(s[i:j+1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
N = len(s)
K = int(input())
l = []
for n in range(1, K + 1):
    for i in range(N - n + 1):
        l.append(s[i:i + n])
l = list(set(l))
l.sort()
print(l[K - 1])

Submission status: Accepted

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

part = [[]]

for i in range(len(s)):
    for j in range(1,k+1):
        if i + j > len(s):
            break
        part.append(s[i:i+j])
del part[0]

part.sort()

delete = []

for i in range(1,len(part)):
    if part[i-1] == part[i]:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del part[delete[i] - diff]
    diff += 1

print("".join(part[k-1]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import queue

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

char2index= dict([(x, i) for i, x in enumerate('abcdefghijklmnopqrstuvwxyz')])
index2char= dict([(i, x) for i, x in enumerate('abcdefghijklmnopqrstuvwxyz')])
indices = [[] for _ in range(len(char2index))]


substrings = set()
K_substring = []
count = -1
def recursive(char, indices):
    global count
    count += 1
    if count == K:
        K_substring.append(char)
        return
    
    new_indices = [[] for _ in range(len(char2index))]
    
    for i in indices:
        if i + 1 < len(S):
            new_indices[char2index[S[i + 1]]].append(i + 1)
         
    for i, index in enumerate(new_indices):
        if len(index) > 0:
            recursive(index2char[i], index)
            if count == K:
                K_substring.append(char)
                break
            
    return

indices = list(range(-1, len(S)-1))
recursive('', indices)
    
print(''.join(K_substring[::-1]))

Submission status: Accepted

Solution code:
s=input()
k=int(input())
X=[]
for i in range(len(s)):
    for j in range(k):
        X.append(s[i:i+j+1])
X=list(set(X))

X.sort()

print(X[k-1])

Submission status: Accepted

Solution code:
s=input()
K=int(input())
li=[]
for i in range(len(s)):
  m=min(K,len(s)-i)
  for j in range(m):
    li.append(s[i:i+j+1])
li.sort(reverse=True)
st=[]
while len(st)<K:
  t=li.pop()
  if t not in st:
    st.append(t)
print(st[-1])

Submission status: Accepted

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

memo=set()
for i in range(len(s)):
  for j in range(1,min(len(s)-i+1,K+1)):
    memo.add(s[i:i+j])
    
memo=list(memo)
memo.sort()
#print(memo)
print(memo[K-1])

Submission status: Accepted

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

ans_list = []
N = len(s)
for k in range(K):
    for i in range(N-k):
        ans_list.append(s[i:i+k+1])


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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
S = ""
K = 0


def set_inputs():
    global S, K
    S = get_str()
    K = get_int()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    substrings = set()
    for i in range(1, K + 1):
        for j in range(len(S) + 1 - i):
            substrings.add(S[j:j+i])
    print(list(sorted(substrings))[K-1])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
S = ""
K = 0


def set_inputs():
    global S, K
    S = get_str()
    K = get_int()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    d = defaultdict(list)
    for i, s in enumerate(S):
        d[s].append(i)
    cnt = 0
    for s in sorted(d.keys()):
        substrings = set(s)
        for i in d[s]:
            for ss in [S[i:i+k] for k in range(2, K + 1)]:
                substrings.add(ss)
        if cnt + len(substrings) >= K:
            print(list(sorted(substrings))[K-1-cnt])
            return
        cnt += len(substrings)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
ans=[]
for i in range(len(s)):
  for j in range(max(0,len(s)-5),len(s)):
    ans.append(s[j:])
  s=list(s)
  s.pop()
  s=''.join(s)
ans=list(set(ans))
ans.sort()
print(ans[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
substrings = {s[i:j]:0 for i in range(len(s)) for j in range(i+1, min(i+1+K, len(s)+1))}
print(sorted(substrings)[K-1])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

result=[]

def substring(l):
    result.append(l)
    if len(result) < k:
        for m in list:
            if l+m in s:
                return substring(l+m)
            else:
                pass
for l in list:
    substring(l)
print(result[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
 
li = sorted(list(set(s)))
result = []

def substring(l):
    result.append(l)
    if len(result) < K:
        for m in li:
            if l+m in s:
                return substring(l+m)
    else:
        pass

for l in li:
    substring(l)

print(result[K-1])

Submission status: Accepted

Solution code:
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(input())])

Submission status: Accepted

Solution code:
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(len(s)*6)})[int(input())])

Submission status: Accepted

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

length = len(s)
sub = []
for item in "abcdefghijklmnopqrstuvwxyz":
  if item in s:
    for i, c in enumerate(s):
      if c == item:
        for j in range(0,length - i + 1):
          if j > 5:
            break
          if j==0:
            if s[i] not in sub:
              sub.append(s[i])
          else: 
            if s[i:i+j] not in sub:
              sub.append(s[i:i+j])
    if len(sub) >= k:
      break
print(sorted(sub)[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
k = int(input())
A = set()
for l in range(k+1):
	for i in range(len(S)-l):
			A.add(S[i:i+l+1])
A = sorted(list(A))
print(A[k-1])

Submission status: Accepted

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

l = set()

for i in range(1, 6):
    l |= set([s[n:n+i] for n in range(len(s))])

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

Submission status: Accepted

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

b = set()

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

b = sorted(list(b))

print(b[k - 1])

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)

s = input()
K = I()
#  s = ''.join(['a' if i % 2 == 0 else 'b' for i in range(5000)])
#  K = 1

combis = []
for i in range(1, K+1):
    start = 0
    while start+i <= len(s):
        combi = s[start:start+i]
        combis.append(combi)
        start += 1
#  print(combis)
combis = list(set(combis))
combis = sorted(combis)
print(combis[K-1])

Submission status: Accepted

Solution code:
S=input()
K=int(input())
chars=sorted(list(set(list(S))))
strings=set()

for c in chars:
  if len(strings)>=5:
    break
  for i in range(len(S)):
    if S[i]==c:
      for j in range(5):
        if i+j<=len(S):
          strings.add(S[i:i+j+1]) 
          
print(sorted(list(strings))[K-1])

Submission status: Accepted

Solution code:
s=input()
K=int(input())
l=[]
for i in range(5):
    for j in range(len(s)):
        if j+i>=len(s):
            break
        l.append(s[j:j+i+1])
#print(l)
#print("A")
l=sorted(set(l))
#print(l)
print(l[K-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
lst = []
start = 0
end = 1
while start < len(s):
    while end - start <= 5:
        lst.append(s[start:end])
        end += 1
    start += 1
    end = start +1
lst.append(s[-1])

print(sorted(list(set(lst)))[k-1])

Submission status: Accepted

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

substringList = []
for i in range(1,K+1) :
    for j in range(length-i+1) :
        substringList.append(s[j:j+i])


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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#A
def A():
    return

#B
def B():
    return

#C
def C():
    s = stdin.readline().rstrip()
    K = II() - 1
    ans = []
    for i in range(len(s)):
        for k in range(K+1):
            b = s[i:i + k + 1]
            ans.append(b)
    ans = list(set(ans))
    ans.sort()
    print(ans[K])
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字列
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字列
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの文字列
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def unqlst(lst):
    return list(set(lst))

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    N = LI()
    reds = sorted(MLIS(N), key=lambda x:x[0])
    blues = sorted(MLIS(N), key=lambda x:x[0])

    blueF = [False for x in range(N)]

    count = 0

    for i in range(N):
        for j in range(N):
            if blueF[j] == False and reds[i] < blues[j]:
                blueF[j] = True
                count += 1
                break
    print(count)

def D():
    pass

def E():
    s = LC()
    k = LI()
    words = []
    for b in range(len(s)):
        for e in range(1, 6):
            if s[b:b+e] != '':
                words.append(s[b:b+e])
    words = sorted(unqlst(words))
    print(words[k-1])
def F():
    pass

def G():
    pass

def H():
    pass

E()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    s = input()
    k = I()
    l = []
    n = len(s)
    alp = list("abcdefghijklmnopqrstuvwxyz")
    for i in alp:
        for j in range(n):
            if s[j] == i:
                l.append(s[j])
                for m in range(j+1,min(j+k,n)):
                    l.append(s[j:m+1])
        l = sorted(list(set(l)))
        if len(l) >= k:break
    print(l[k-1])
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars[:3]:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
from collections import Counter


def solve(string):
    s, k = string.split()
    k = int(k)
    count = Counter(s)
    chars = sorted(set(s))
    for t in range(min(3, len(chars))):
        tmp = []
        i = s.index(chars[t])
        tmp.append(s[i:i + k])
        if count[chars[t]] > 1:
            for _ in range(count[chars[t]] - 1):
                i = s.index(chars[t], i + 1)
                tmp.append(s[i:i + k])
        g = []
        for p in tmp:
            for j in range(1, len(p) + 1):
                g.append(p[:j])
        g = sorted(set(g))
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
from collections import Counter


def solve(string):
    s, k = string.split()
    k = int(k)
    count = Counter(s)
    chars = sorted(set(s))
    for t in range(min(3, len(chars))):
        tmp = []
        i = s.index(chars[t])
        tmp.append(s[i:i + 5])
        if count[chars[t]] > 1:
            for _ in range(count[chars[t]] - 1):
                i = s.index(chars[t], i + 1)
                tmp.append(s[i:i + 5])
        g = []
        for p in tmp:
            for j in range(1, len(p) + 1):
                g.append(p[:j])
        g = sorted(set(g))
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
from collections import Counter


def solve(string):
    s, k = string.split()
    """
    g = []
    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            g.append(s[i:j])
    g = sorted(set(g))
    return g[int(k)-1]
    """
    k = int(k)
    count = Counter(s)
    chars = sorted(set(s))
    for t in range(min(3, len(chars))):
        tmp = []
        i = s.index(chars[t])
        tmp.append(s[i:i + 5])
        if count[chars[t]] > 1:
            for _ in range(count[chars[t]] - 1):
                i = s.index(chars[t], i + 1)
                tmp.append(s[i:i + 5])
        g = []
        for p in tmp:
            for j in range(1, len(p) + 1):
                g.append(p[:j])
        g = sorted(set(g))
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

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

d = dict()
SET = set()
for i in range(len(s)):
    if not d.__contains__(s[i]):
        d[s[i]] = []
    d[s[i]].append(i)


alphabet = 'abcdefjhijklmnopqrstuvwxyz'

for c in alphabet:
    if not d.__contains__(c):
        continue
    l = d[c].copy()
    SET.add(c)
    if(len(SET) >= K):
        break
    tmp = []
    for idx in l:
        if idx+1>=len(s):
            continue
        tmp.append((idx,s[idx+1:len(s)]))
    tmp.sort(key = lambda x:x[1])
    for idx,nxt in tmp:
        for step in range(2,len(s)+1):
            if idx+step>len(s):
                break
            if s[idx:idx+step] not in SET:
                SET.add(s[idx:idx+step])
                if len(SET) >= K:
                    break
        if len(SET) >= K:
            break
    if len(SET) >= K:
         break

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

Submission status: Accepted

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

result = set()
for i in range(sLen):
    for j in range(1, K + 1):
        if i + j > sLen:
            break
        ss = s[i:i+j]
        result.add(ss)
print(sorted(result)[K - 1])

Submission status: Accepted

Solution code:
# /user/bin/python
# -*- coding: utf-8 -*-
import sys

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

i_r = 0
k_str = []
nm = 0
for i_l in range(len(s)):
  i_r = i_l+1
  while i_r <= len(s):
    nm += 1
    if len(k_str) < k:
      k_str.append(s[i_l:i_r])
      k_str = sorted(k_str)
    elif (s[i_l:i_r] not in k_str) and (k_str[-1] >= s[i_l:i_r]):
      k_str[-1] = s[i_l:i_r]
      k_str = sorted(k_str)

    if k_str[-1] < s[i_l:i_r]:
      i_r = len(s)
    i_r += 1

print(k_str[-1])

Submission status: Accepted

Solution code:
#5番目までに大きな数値を探すということは、5文字以内の文字列だけを検索すれば良い
s = str(input())
k = int(input())
substring = []

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

		
sub = list(set(substring))
sub.remove('')
sub.sort()

print(sub[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# K<=5ということから6文字以上のsubstringには5個以上、辞書順で早いprefixを5個以上もつので
# 長さが5以下の文字列のみをみればいい

S = input()
K = int(input())
substrings = []
for i in range(1, min(len(S)+1, 6)):  # 文字数
    for n in range(len(S) - i + 1):
        sub = S[n:n + i]
        if sub not in substrings:
            substrings.append(sub)
# print(substrings)
substrings.sort()
print(substrings[K-1])