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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/
Solved on 2019/3/
@author: shinjisu
"""


# ABC 076 C Explanation
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def register(db, word):
    global K
    #d = Debug()
    #d.dmp((db, word),'db, word')
    if word >= db[-1]:
        return -1
    else:
        for i in range(K):
            if word == db[i]:
                return 0
            elif word < db[i]:
                db[i+1:] = db[i:-1]
                db[i] = word
                break
    #d.dmp(db)
    return 0
    
    
def prob():
    global K
    d = Debug()
    d.off()
    S = input()
    d.dmp(S)
    K = getInt()
    d.dmp(K)
    db = ['~' for i in range(K)]  # 'z'より大きい
    for i in range(len(S)):
        for j in range(i, len(S)):
            if register(db, S[i:j+1]):
                break
    return db[-1]


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Accepted

Solution code:
s = input()
k = int(input())
n = len(s)
dic = []
for i in range(n):
    for j in range(1, k + 1):
        if i + j > n:
            break
        if s[i:i+j] not in dic:
            dic.append(s[i:i+j])
dic.sort()
print(dic[k-1])

Submission status: Accepted

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

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

Submission status: Accepted

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


def main():
    st = set()

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

    l = sorted(st)

    print(l[K - 1])
    return


main()

Submission status: Accepted

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

diff = k - len(s)
if len(s) < k:
    k -= diff
else:
    diff = 0

l = []
for a in range(len(s) - k + 1):
    subsByK = s[a:a + k]
    # print(subsByK)
    for b in range(k):
        for c in range(b + 1, k + 1):
            # print(b,c)
            subs = subsByK[b:c]
            l.append(subs)

print(sorted(set(l))[k - 1 + diff])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
ab = 'abcdefghijklmnopqrstuvwxyz'
N = len(s)
substrings = set()
for i in ab:
    for l in range(N):
        if s[l] != i:
            continue
        for r in range(l,N):
            if r-l+1 > K:
                break
            substrings.add(s[l:r+1])
    if len(substrings) >= K:
        break
substrings = list(substrings)
substrings.sort()
print(substrings[K-1])

Submission status: Accepted

Solution code:
import bisect

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

alpha_list = [chr(i) for i in range(97, 97+26)] #["a","b",...."c"]
dic = []
for i in range(len(s)):
    dic = sorted(dic)
    if k < bisect.bisect_left(dic,s[i]):
        continue
    for j in range(i+1, min(i+6, len(s)+1)):
        s0 = s[i:j]
        
        if s0 not in dic:
            dic.append(s0)

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

Submission status: Accepted

Solution code:
def solve():
    s=input()
    K=int(input())
    words = set()
    ls = len(s)
    for i in range(ls):
        for j in range(i+1,min(i+6,ls+1)):
            words.add(s[i:j])
    words = sorted(list(words))
    return words[K-1]

print(solve())

Submission status: Accepted

Solution code:
s = input()
K = int(input())
lst = []
# substringの長さ候補
ssize = min(5,len(s))
# substringの長さ候補だけ繰り返し部分文字列を取得
for i in range(1 , ssize + 1):
    # j番目の文字から部分文字列を取得
    for j in range(len(s)-i+1):
        #print("j:",j)
        lst.append(s[j:i+j])

#集合にして重複を削除
sset = set(lst)
#リストに戻す
llst = list(sset)
#ソートする
llst.sort()
#print(llst)
print(llst[K-1])

Submission status: Accepted

Solution code:
def kth_substring(s: str, K: int) -> str:
    kth_word = ''     # K 番目の文字列
    kth_word_len = 0  # K 番目の文字列の長さ
    n = len(s)        # s の文字列の長さ

    # 最初の文字から順番に決定していく。
    while K > 0:
        # 探索した文字列を格納する。
        d = set()
        # 例えば 'c' で始まる文字列に対して、'a'、 'b'で
        # 始まる文字列の総数
        prev_count = 0
        # 探索に使う用の文字列
        temp = ''
        for c in 'abcdefghijklmnopqrstuvwxyz':
            temp = kth_word + c
            # s の頭から temp で始まる文字列を探し、
            # それが見つかれば、それをそのまま伸ばして
            # 全て d に入れる
            for i in range(n):
                if s[i:].startswith(temp):
                    for j in range(i, n):
                        d.add(s[i:j+kth_word_len+1])
                        if len(d) >= K:
                            break
                if len(d) >= K:
                    break
            if len(d) >= K:
                break
            # 次の文字に探索対象が変わるとき、現在保持している
            # 文字列の数を保持しておく
            prev_count = len(d)

        # temp から始まる文字列は prev_count 番目以降なので
        # 目標を temp から始まる文字列の K - prev_count 番目
        # の文字列に変更する
        K -= prev_count + 1
        kth_word = temp
    return kth_word


if __name__ == "__main__":
    s = input()
    K = int(input())
    ans = kth_substring(s, K)
    print(ans)

Submission status: Accepted

Solution code:
s = input()
K = int(input())
n = len(s)
A = []
for i in range(n):
    if n < K:
       for j in range(n-i): 
           A.append(s[i:j+i+1])
    else:
       for j in range(K):
           A.append(s[i:i+j+1])
B = set(A)
C = []
for i in B:
    C.append(i)
C.sort()
print(C[K-1])

Submission status: Accepted

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

sub = set()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

k_sub = []
for l in range(1,k+1):
  for i in range(len(s)):
    if i+l<=len(s):
      k_sub.append(s[i:i+l])
    else:
      break
k_sub = sorted(list(set(k_sub)))
print(k_sub[k-1])

Submission status: Accepted

Solution code:
A = list(input())
K = int(input())
L = []
for i in range(len(A)):
    for j in range(i+1, i+K+1):
        L.append(''.join(A[i:j]))
L = list(set(L))
L.sort()
print(L[K-1])

Submission status: Accepted

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

l = []

for i in range(len(s)):
    l.append(s[i:])

l.sort()
m={l[0][0]}

for x in l:
    for i in range(len(x)):
        m.add(x[:i+1])
        if len(m)>=5:
            break
    if len(m)>=5:
        break

m=list(m)
m.sort()

print(m[K-1])

Submission status: Accepted

Solution code:
s=input()
K=int(input())
 
def rec(s):
    length=len(s)
    ret=set()
    for depth in range(length):
        string=s[depth]
        ret.add(string)
        for i in range(depth+1,depth+K):
            if i<length:
                string+=s[i]
                ret.add(string)
    return ret
  
ret=rec(s)
print(sorted(ret)[K-1])

Submission status: Accepted

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

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

Ans.sort()

L = []
for i in Ans:
  if i not in L:
    K -= 1
    if K == 0:
      print(i)
      exit()
    L.append(i)

Submission status: Accepted

Solution code:
s=input()
k=int(input())
n=len(s)
koho=[]
for i in range(n):
    for j in range(k):
        if len(s[i:i+j+1])<=k:
            koho.append(s[i:i+j+1])

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

Submission status: Accepted

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

res = set()
for i in range(len(S)):
  for j in range(5):
    res.add(S[i:i+j+1])
print(sorted(res)[N-1])

Submission status: Accepted

Solution code:
str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    for t in range(f + 1, f + 1 + int_k):
        pattern.add(str_s[f:t])
        result = sorted(set(result + list(pattern)))[:int_k]

print(result[-1])

Submission status: Accepted

Solution code:
from collections import deque
q = deque()
s = input()
k = int(input())
alpha = set(s)
alpha = sorted(alpha)
for i in range(len(s)):
    for a in alpha[:3]:
        if s[i] == a:
            for j in range(k+1):
                q.append(s[i:i+j])
setq = set(q)
setq = sorted(setq)
print(setq[k])

Submission status: Accepted

Solution code:
s=input()
k=int(input())
list=[]
if len(s)>=5:
    for i in range(1,6):
        for j in range(len(s)-i+1):
            list.append(s[j:j+i])
else:
    for i in range(1,len(s)+1):
        for j in range(len(s)-i+1):
            list.append(s[j:j+i])
list_set_sorted=sorted(set(list))
print(list_set_sorted[k-1])

Submission status: Accepted

Solution code:
s = input()
k = int(input())
s_list = []
for i in range(len(s)):
    for j in range(i,i+6):
        if not s[i:j] in s_list:
            s_list.append(s[i:j])
s_list.sort()
print(s_list[k])

Submission status: Accepted

Solution code:
def main():
    s = input()
    K = int(input())
    ranks = ["~"] * K
    for l in range(len(s)):
        for r in range(l+1, min(len(s)+1, l+6)):
            target = s[l:r]
            if target in ranks:
                continue
            if target < ranks[K-1]:
                ranks[K-1] = target
            for i in range(K-1, 0, -1):
                if ranks[i] < ranks[i-1]:
                    tmp = ranks[i]
                    ranks[i] = ranks[i-1]
                    ranks[i-1] = tmp
    print(ranks[K-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

alphabet = [chr(i) for i in range(97,97+26)]
n1,n2,n3,n4,n5 = 0,0,0,0,0

while len(List) < K:
    for a in range(n1,26):
        if alphabet[a] in s:
            break
    if not alphabet[a] in List:
        List.append(alphabet[a])
    
    if len(List) >= K:
        continue

    num = s.index(alphabet[a])
    if num == len(s)-1:
        n1 = a+1
        continue

    for b in range(n2,26):
        sumple1 = alphabet[a] + alphabet[b]
        if sumple1 in s:
            break
    if not sumple1 in List:
        List.append(sumple1)

    if len(List) >= K:
        continue

    if not sumple1 in s:
        n1 += 1
        n2,n3,n4,n5 = 0,0,0,0
        continue
        
    num = s.index(sumple1)
    if num == len(s)-2:
        n2 = b+1
        continue

    for c in range(n3,26):
        sumple2 = sumple1 + alphabet[c]
        if sumple2 in s:
            List.append(sumple2)
            break

    if len(List) >= K:
        continue
    
    if not sumple2 in s:
        n1 += 1
        n2,n3,n4,n5 = 0,0,0,0
        continue
    
    num = s.index(sumple2)
    if num == len(s)-3:
        n3 = c+1
        continue

    for d in range(n4,26):
        sumple3 = sumple2 + alphabet[d]
        if sumple3 in s:
            List.append(sumple3)
            break

    if len(List) >= K:
        continue
        
    num = s.index(sumple3)
    if num == len(s)-4:
        n4 = d+1
        continue

    for e in range(n5,26):
        sumple4 = sumple3 + alphabet[e]
        if sumple4 in s:
            List.append(sumple4)
            break

    if len(List) >= K:
        continue
        
answer = List[K-1]

print(answer)

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])
l = sorted(set(l))
print(l[K-1])

Submission status: Accepted

Solution code:
import sys
 
 
def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(list(set(sub)))
  print(sub[K-1])
 
 
if __name__ == '__main__':
  main()

Submission status: Accepted

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

ss = []
m = min(len(s), k)
for i in range(len(s)):
    for j in range(1, m+1):
        if i+j > len(s):
            continue
        ss.append(s[i: i+j])
ss = sorted(list(set(ss)))
print(ss[k-1])

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

ss = []
for i in range(len(s)):
    for j in range(i+1, i+k+1):
        if s[i:j] not in ss:
            ss.append(s[i:j])
ss = sorted(ss)
print(ss[k-1])

Submission status: Accepted

Solution code:
import sys


def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(list(set(sub)))
  print(sub[K-1])


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
#encoding utf-8

import copy
import numpy as np
import random


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

substrings = []
for length in range(1,len(s)+1):
    if length > 5:
        break
    for i in range(len(s)-length+1):
        word = "".join(s[i:i+length])
        # print(word)
        if word in substrings:
            pass
        else:
            substrings.append(str(word))

substrings.sort()
# print(substrings)
print(substrings[k-1])

Submission status: Accepted

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

check = []
for i in range(len(s)):
    for j in range(k):
        check.append(s[i:i+j+1])
        
print(sorted(list(set(check)))[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(k):
        if i + j < n:
            koho.add(s[i:(i+j+1)])
so = sorted(list(koho))
print(so[k-1])

Submission status: Accepted

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

check = []
a = min(len(s),k)
for i in range(len(s)):
    for j in range(a):
        if i <= i+j <=len(s)+1:
            check.append(s[i:i+j+1])
            
print(sorted(set(check))[k-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    S = lines.pop(0)
    K = int(lines.pop(0))
    n = 0
    skip = []
    res = []
    while K > 0:
        min_idx = 0
        min_str = "z"
        for i,x in enumerate(S):
            if i in skip:
                continue
            if min_str > x:
                min_str = x
                min_idx = i
            elif min_str == x:
                l = len(S[i:])
                if S[min_idx:min_idx+l] > S[i:]:
                    min_str = x
                    min_idx = i
                elif S[min_idx:min_idx+l] == S[i:]:
                    skip.append(i)
        skip.append(min_idx)
        res = S[min_idx:]
        if len(res) >= K:
            print(res[:K])
            sys.exit(0)
        else:
            K -= len(res)
    sys.exit(1)



#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
K = int(input())
a = list(set(S))
a.sort()

k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1,6):
                if i+j <= len(S):
                    k.append(S[i:i+j])
                else:
                    break
    l += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sorted(set(l))[k-1])

Submission status: Accepted

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

sub = set()
for k in range(1, 6):
    for i in range(len(s)):
        sub.add(s[i:i+k])

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

Submission status: Accepted

Solution code:
s = str(input())
k = int(input())
l = []
for i in range(len(s)):
    for j in range(1,k+1):
        l.append(s[i:i+j])

print(sorted(set(l))[k-1])

Submission status: Accepted

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

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

print(sorted(set(sub_str))[k-1])

Submission status: Accepted

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

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

print(sorted(set(check))[k-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
k=int(input())
s_list=[]
for p in range(len(s)):
    for q in range(min(5,len(s[p:]))):
        if(not(s_list.__contains__(s[p:p+q+1]))):
                s_list.append(s[p:p+q+1])
s_list_sort=sorted(s_list)
print(s_list_sort[k-1])

Submission status: Accepted

Solution code:
strn=input()
K = int(input())
wordindex=[]
minindex=list(set(strn))
minindex.sort()
def IndexPoint(index,word):
    return [i for i,x in enumerate(index) if x == word]
while len(wordindex) < K:
    for m in minindex:
        point = IndexPoint(strn,m)
        for p in point:
            tmp = ""
            for i in range(p,min(len(strn),p+K+1)):
                tmp += strn[i]
                wordindex.append(tmp)
wordindex = list(set(wordindex))
wordindex.sort()
print(wordindex[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(s, K):
    import heapq
    import re

    seen = set(s)
    pq = list(seen)
    heapq.heapify(pq)

    while True:
        t = heapq.heappop(pq)
        K -= 1
        if K==0:
            return t
        pattern = t + "."

        matched = re.findall(pattern, s)
        for sub in matched:
            if sub not in seen:
                seen.add(sub)
                heapq.heappush(pq, sub)


def main():
    s = input()
    k = int(input())
    print(solve(s, k))


main()

Submission status: Accepted

Solution code:
# ABC 097 C
S = input()
K = int(input())

cand = []
for l in range(1, K+1):
    for i in range(len(S) - l + 1):
        cand.append(S[i:i+l])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 097 C

from collections import defaultdict

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

alphabet = defaultdict(list)
for i, s in enumerate(S):
    alphabet[s].append(i)

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        if len(S)-j+1 >= K:
            for l in range(1, K+1):
                cand.append(S[j:j+l])
        else:
            for l in range(1, len(S)-j+1):
                cand.append(S[j:j+l])
    cand = list(set(cand))
    if len(cand) >= K:
        break
    i += 1
cand = sorted(cand)
print(cand[K-1])

Submission status: Accepted

Solution code:
a0 = list(input())
k = int(input())
a = a0+['O', 'O', 'O', 'O']
b = sorted(set(a0))[:3]
A = set()

for w in b:
    for i, x in enumerate(a0):
        if x == w:
            for m in range(1, 6):
                A.add(tuple([a[i+k] for k in range(m)]+['O']*(6-m)))

A = sorted(A)
j = A[k-1].index('O')
ans = list(A[k-1])[:j]
print(''.join(ans))

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

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

dic = set()

for i in range(len(s)):
  for j in range(1, 6):
    if len(s[i:i+j])>0:
      dic.add(s[i:i+j])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = input()
    K = int(input())
    sk = []
    for i in range(len(s)):
        for j in range(1, K + 1):
            ss = s[i:i + j]
            if ss not in sk:
                sk.append(ss)
    print(sorted(sk)[K - 1])


main()

Submission status: Accepted

Solution code:
S = list(raw_input())

K = input()

data = []
for i in range(len(S)):
    for j in range(1,K+1):
        if i+j <= len(S):
            sample = ''
            counter = 1
            while counter <= j:
                sample += S[i+counter-1]
                counter += 1
            if sample not in data:
                data.append(sample)
        else:
            break

data.sort()

print data[K-1]

Submission status: Accepted

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

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 #length = n
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    
chars=chars|subset(s[max(l-10,0):],0)
for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)

#print(min_c,chars)

'''
for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])
'''

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

Submission status: Accepted

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

d = {}
for i in range(len(S)):
    for j in range(i+1,i+K+1):
        s = S[i:j]
        if s in d.keys():
            pass
        else:
            d[s] = 0

d = sorted(d.keys())
print(d[K-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
k = int(input())
l = [[i] for i in range(len(s))]
a = [''.join([s[i] for i in x]) for x in l]
for _ in range(k):
    m = min(a)
    for i,x in enumerate(a):
        if x==m and l[i][-1]+1<len(s):
            l[i].append(l[i][-1]+1)
        elif x==m:
            l.pop(i)
    a = [''.join([s[i] for i in x]) for x in l]
print(m)

Submission status: Accepted

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

Ans = []
for k in range(5):
    for i in range(len(S)-k):
        s = S[i:i+k+1]
        if s not in Ans:
            Ans.append(s)

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

Submission status: Accepted

Solution code:
s = input()
K = int(input())
substring = set()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for alp in alphabet:
    st = s[:]
    if len(substring) >= 5:
        break
    i = st.find(alp)
    while i > -1:
        for j in range(5):
            substring.add(st[i:i+j+1])
        st = st[i+1:]
        i = st.find(alp)
print(sorted(substring)[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import string, heapq

def solve():
    s = input()
    s_len = len(s)
    k = int(input())
    alpha = string.ascii_lowercase
    subs = []
    for a in alpha:
        a_indexs = [i for i, x in enumerate(s) if x == a]
        for index in a_indexs:
            for i in range(index, min(index+5, s_len)):
                sub = s[index:i+1]
                if sub in subs:
                    continue
                else: 
                    heapq.heappush(subs, s[index:i+1])                
        if len(subs) >= k:
            break
    for i in range(k-1):
        heapq.heappop(subs)
    print(heapq.heappop(subs))

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
s=input()
K=int(input())
substring=set()
for start in range(len(s)):
    for end in range(start+1,min(len(s)+1,start+K+1)):
        substring.add(s[start:end])
print(sorted(list(substring))[K-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
# if K > 50:
#     print(0)
#     exit()
sub = {s[i:j] for i in range(len(s)) for j in range(i+1,i+K+1)}
sub = sorted(sub)
print(sub[K-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

def ngram(text, n):
    return [text[i:i+n] for i in range(len(text) - n + 1)]

text = input()
k = int(input())
candidates = set()
for n in range(1,6):
    #_ = filter(lambda x:x[1] == 1,Counter(ngram(text,n)).items())
    candidates |= set(ngram(text,n))

print(sorted(list(candidates))[k-1])

Submission status: Accepted

Solution code:
def n_gram(seq, n):
    return {seq[i: i+n] for i in range(len(seq) - n + 1)}

def main(s, k):
    tmp = set()
    for i in range(1, 6):
        tmp = tmp | n_gram(s, i)
    substr = sorted(list(tmp))
    print(substr[k-1])

if __name__ == '__main__':
    main(input(), int(input()))

Submission status: Accepted

Solution code:
s = input().strip()
k = int(input())
subs = set()
for i in range(1, 6):
  for j in range(0, len(s)-i+1):
    subs |= set([s[j:j+i]])
print(list(sorted(subs))[k-1])

Submission status: Accepted

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

for i in range(len(s)+1):
    for j in range(i+1,i+K+1):
        if j >len(s):
                break
        else:
                substring.append(s[i:j])

setsubstring = list(set(substring))
setsubstring.sort()

print(setsubstring[K-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1, min(N+1, 6)):
    for j in range(N - i + 1):
        ans.append(s[j:j+i])

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

Submission status: Accepted

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

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

Submission status: Accepted

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