Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

1 ≤ |s| ≤ 5000

s consists of lowercase English letters.

1 ≤ K ≤ 5

s has at least K different substrings.

Partial Score

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

Input

Input is given from Standard Input in the following format:

s
K

Output

Print the K-th lexicographically smallest substring of K.

Sample Input 1

aba
4

Sample Output 1

b

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

Sample Input 2

atcoderandatcodeer
5

Sample Output 2

andat

Sample Input 3

z
1

Sample Output 3

z



Sample input:
aba
4


Sample output:
b

Submission status: Time Limit Exceeded

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


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


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


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


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


def read_str():
    return input()


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


# @lru_cache(size=None)
def slv(S, K):
    d = set([])
    for i in range(len(S)):
        for j in range(i + 1, len(S) + 1):
            d.add(S[i:j])
    return sorted(d)[K - 1]


def main():
    S = read_str()
    K = read_int()
    print(slv(S, K))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

subs = collections.defaultdict(set)
for i in range(n):
    for j in range(i+1,n+1):
        subs[s[i]].add(s[i:j])
for c in string.ascii_lowercase:
    l = len(subs[c])
    if k <= l:
        t = sorted(list(subs[c]))[k-1]
        print(t)
        exit()
    else:
        k -= l

Submission status: Time Limit Exceeded

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

from heapq import heappush, heappop

Q = set()
u = set()
N = len(s)
for i in range(N):
    for j in range(i+1, N+1):
        ss = s[i:j]
        if ss in u:
            continue
        u.add(ss)
        Q.add(ss)
        if len(Q) > K:
            Q.remove(max(Q))
l = sorted(Q)
print(l[K-1])

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8

def main():
	s = input()
	k = int(input())
	substr = set()
	for start in range(len(s)):
		for end in range(start, len(s)):
			substr.add(s[start:(end+1)])

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

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
s=input()
K=int(input())
l=len(s)

S=set([])

for i in range(l):
    for j in range(i,l):
#        print(s[i:j+1])
        S.add(s[i:j+1])
print(list(sorted(S))[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = []
st = set()

for i in range(n):
    for j in range(i + 1, n + 1):
        sub = S[i:j]
        # print(sub)
        if sub in st:
            continue
        st.add(sub)
        ans.append(sub)
        ans.sort()
        # print(ans)
        if len(ans) > K:
            ans = ans[:K]

print(ans[-1])

Submission status: Time Limit Exceeded

Solution code:


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)
K = int(input()) - 1

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    K = int(input())
    Sset = set()
    for i in range(len(S)):
        for j in range(1, K+1):
            Sset.add(S[i:i+j])
    Slist = list(Sset)
    Slist.sort()
    # print(Slist)
    print(Slist[K-1])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


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


# In[9]:


mylist = []
length = len(s)
for i in range(length):
    for j in range(i,min(length, i+K)):
        mylist += [s[i:j+1]]
mylist_s = sorted(list(set(mylist)))
print(mylist_s[K-1])


# In[ ]:

Submission status: Accepted

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

len_s =  len(s)
L = []
m = 0
for i in range(1, k+1):
    for j in range(len_s-i+1):
        if s[j:j+i] not in L:
            L.append(s[j:j+i])


L.sort()
print(L[k-1])

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline().rstrip()

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

vec=set()

for i in range(len(S)):
  for j in range(i+1,min(len(S)+1,K+i+1)):
    tmp=S[i:j]
    vec.add(tmp)
vec=list(vec)
vec.sort()

print(vec[K-1])

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline().rstrip()

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

vec=[]
for i in range(len(S)):
  for j in range(i+1,K+i+1):
    tmp=S[i:j]
    if not tmp in vec:
      vec.append(tmp)
vec.sort()

print(vec[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, min(5+1, N-i+1)):
        A.add(s[i:i+j])

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

Submission status: Accepted

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

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

ans_set = set(ans_list)
ans_list_min = sorted(list(ans_set))
#print(ans_list_min)
print(ans_list_min[K-1])

Submission status: Accepted

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

cand = set()
for i in range(len(s)):
  for j in range(i+1, i+k+1):
    if j >len(s):
      continue
    cand.add(s[i:j])
listcand = list(cand)
listcand.sort()
print(listcand[k-1])

Submission status: Accepted

Solution code:
s = input()
K = int(input())
ans_lis = []
s_length = len(s)
lis = [[] for i in range(26)]

for i in range(s_length):
    lis[ord(s[i]) - ord('a')].append(i)


for i in range(26):
    k = 1
    while k <= K:
        for j in lis[i]:
            ans_lis.append(s[j:j + k])
        k += 1
        ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()

Submission status: Accepted

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

N = len(s)

d = dict()
for i in range(N):
    for j in range(i, min(N, i+K)):
        sub = s[i:j+1]
        if d.get(sub) == None:
            d[sub] = 1

d2 = sorted(d.items())
print(d2[K-1][0])

Submission status: Accepted

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

N = len(s)

d = dict()
for i in range(N):
    for j in range(i, min(N,i+K)):
        sub = s[i:j+1]
        if d.get(sub) == None:
            d[sub] = 1

d2 = sorted(d.items())
print(d2[K-1][0])

Submission status: Accepted

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

n = len(S)

ans = set()

for i in range(n):
    for j in range(i, min(i+5, n)):
        ans.add(S[i:j+1])

ans = list(ans)
ans.sort()

print(ans[K-1])

Submission status: Accepted

Solution code:
S=input()
N=len(S)
K=int(input())
A=[]
for i in range(1,K+1):
    j=0
    while j+i<=N:
        A.append(S[j:j+i])
        j+=1
A=list(set(A))
A.sort()
print(A[K-1])

Submission status: Accepted

Solution code:
def suuji(a):
  ans=0
  for i in range(len(a)):
    ans+=(ord(a[i])-96)*(27**(5-i))
  return ans
def alpha(a):
  ans=''
  while a>0:
    b = chr((a%27)+96)
    if b!='`':
      ans+=chr((a%27)+96)
    a//=27
  return ans[::-1]
g = []
s=input()
k=int(input())
for i in range(len(s)):
  for j in range(1,min(6,len(s)+1)):
    if i+j>len(s):
      break
    g.append(suuji(s[i:j+i]))
g = sorted(set(g))
print(alpha(g[k-1]))

Submission status: Accepted

Solution code:

def resolve():
    S = input()
    K = int(input())
    N = len(S)

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

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

S=input()
N=len(S)
K=intput()
L=[list()]*26
ans=[]
for i in range(N):
    L[ston(S[i])].append(i)
for l in L:
    for i in l:
        for j in range(i+1,min(i+K+1,N+1)):
            s=S[i:j]
            if bisect_left(ans,s)==bisect_right(ans,s):
                insort_left(ans,s)
    if len(ans)>=K:
        print(ans[K-1])
        exit()

Submission status: Accepted

Solution code:
s = str(input())
K = int(input())
L = []
M = []
con = 0
for i in s:
  L.append(i)
L = list(set(L))
L.sort()
for j in range(len(s)):
    if s[j] == L[0]:
      for k in range(1,6):
        if j + k >=len(s):
          M.append(s[j:])
          break
        else:
          M.append(s[j:j+k])
if len(L) != 1:
  for l in range(len(s)):
    if s[l] == L[1]:
      for m in range(1,6):
        if l + m >= len(s):
          M.append(s[l:])
          break
        else:
          M.append(s[l:l+m]) 
if len(M) < K:
  for n in range(len(s)):
    if s[n] == L[2]:
      for o in range(1,6):
        if n + o >=len(s):
          M.append(s[n:])
          break
        else:
          M.append(s[n:n+o])
M = list(set(M))
M.sort()
print(M[K - 1])

Submission status: Accepted

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

for i in range(n):
    for j in range(1,k+1):
        if i+j > n: break
        qq.add(s[i:i+j])

qq=sorted(qq)
# print(qq)
print(qq[k-1])

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        heappush(pos[s], S[i:])
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        while pos[l]:
            sub = heappop(pos[l])
            for i in range(1, len(sub)+1):
                dic.add(sub[:i])

            if len(dic) >= K:
                dic = sorted(list(dic))
                print(dic[K - 1])
                return



if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
S = input()
K = int(input())
S_list = []

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = list(input())
K = int(input())
s = list(map(lambda x: ord(x), s))
sub_s = []
for length in range(1, 6):
    for i in range(len(s) - (length - 1)):
        sub_s.append(s[i:i+length])
sub_s.sort()
k = 1
ans = sub_s[0]
for sub in sub_s:
    if ans == sub:
        if k == K:
            break
        continue
    ans = sub
    k += 1
    if k == K:
        break
for c in ans:
    print(chr(c), end="")

Submission status: Accepted

Solution code:
def main():
    S = input()
    K = int(input())
    ans = []
    def dfs(s):
        if len(s) > K:
            return
        for i in range(97,123):
            tmp = s + chr(i)
            if tmp in S:
                ans.append(tmp)
                dfs(tmp)

    
    dfs('')
    ans.sort()
    print(ans[K-1])



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    K = int(input())
    ans = []
    def dfs(s,cnt):
        res = cnt 
        if len(s) > K:
            return
        for i in range(97,123):
            tmp = s + chr(i)
            if tmp in S:
                res += 1
                ans.append(tmp)
                if res == K:
                    return
                dfs(tmp,res)

    
    dfs('',0)
    ans.sort()
    print(ans[K-1])



if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(len(s)):
    for j in range(k):
        lis.append("".join(s[i:i + j + 1]))
lis = sorted(list(set(lis)))

print(lis[k - 1])

Submission status: Accepted

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

dic = {}
for i in range(1,6):
    for j in range(len(s)+1-i):
        dic.setdefault(s[j:j+i],0)
        dic[s[j:j+i]] += 1
sort_dic = sorted(dic)
print(sort_dic[k-1])

Submission status: Accepted

Solution code:
'''
Created on 2020/08/26

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  s=pin()[:-1]
  K=int(pin())
  d=[]
  for i in range(1,K+1):
    for j in range(len(s)-i+1):
      d.append(s[j:j+i])
  ans=sorted(list(set(d)))
  print(ans[K-1])
  return
main()

#解説AC

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    s = input()
    n = len(s)
    k = int(input())
    candidates = set()

    for j in range(min(n, k)):
        for i in range(n - j):
            candidates.add(s[i:i + j + 1])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


a = set()

for i in range(len(S)):
    for j in range(1, 6):
        if i + j > len(S):
            break
        a.add(S[i:i + j])

ans = sorted(list(a))

print(ans[K - 1])

Submission status: Accepted

Solution code:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    s = getS()
    k = getN()

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

    ss = list(ss)
    ss.sort()
    # ss.sort(key=lambda x:len(x))
    # print(ss)
    print(ss[k-1])


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(s, k):
    z = set()
    for i in range(1, k+1):
        for j in range(len(s)-i+1):
            z.add(s[j:j+i])
    return sorted(list(z))[k-1]


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import insort

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

T=[]
N=len(S)
for  i in range(N):
    V=""
    for j in range(i,min(i+K,N)):
        V+=S[j]
        if V not in T:
            insort(T,S[i:j+1])
            T=T[:K]
print(T[-1])

Submission status: Accepted

Solution code:
from collections import defaultdict
s = input()
k = int(input())
dd = {}
if len(s) == 1:
    print(s)
    exit()
for i in range(len(s)):
    dd[s[i]] = 1
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        if j-i+1 <= k:
            dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Submission status: Accepted

Solution code:


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    s = input()
    K = read_int()
    min5 = []
    for i in range(len(s)):
        for j in range(i+1, min(len(s), i+K)+1):
            min5.append(s[i:j])
        min5 = sorted(set(min5))
        while len(min5) > K:
            min5.pop()
    return min5[-1]


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

#k個の候補を持つ
kouho=["zzzzzzz"]*k

for i in range(len(s)):
    tmp=""
    if s[i]<kouho[-1]:
        for j in range(min(k,len(s)-i)):
            tmp+=s[i+j]
            kouho.append(tmp)

        kouho=list(set(kouho))
        kouho.sort()
        kouho=kouho[:k]

print(kouho[-1])

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    s =input()
    k = int(input())
    cnt = 0
    mci = 0
    while cnt < k:
        mci = min([ord(i) for i in s if ord(i) > mci])
        a = set()
        for i in range(len(s)):
            if ord(s[i]) != mci:
                continue
            for j in range(1, 6):
                a.add(s[i:i+j])
        if len(a) + cnt < k:
            cnt += len(a)
        else:
            print(sorted(a)[k-cnt-1])
            return


main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    A = set()
    L = len(S)
    for i in range(L):
        for k in range(K):
            if i+k<=L:
                A.add(S[i:i+k+1])
    A = list(A)
    A.sort()
    print(A[K-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
s = input()
k = ni()
n = len(s)
l = set()
for i in range(k):
    for j in range(0,n-i):
        l.add(s[j:j+i+1])
ls = sorted(list(l))
print(ls[k-1])

Submission status: Accepted

Solution code:
import sys
import heapq

s = sys.stdin.readline().strip()
K = int(sys.stdin.readline())

ls = len(s)
q = []
exists = set()
for i in range(26):
    ini = chr(ord("a") + i)
    for j in range(ls):
        if s[j] == ini:
            k = 0
            while k < K and j + k < ls:
                tmp = s[j:j+1+k]
                if tmp not in exists:
                    heapq.heappush(q, s[j:j+1+k])
                    exists.add(tmp)
                k += 1

    if K <= len(q):
        break

# print(q)
for i in range(K-1):
    heapq.heappop(q)
print(q[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    K = int(input())
    n = len(S)
    ALL = set()
    
    cnt = 0
    for i in range(n):
        for j in range(1,K+1):
            if i+j<=n:
                ALL.add(S[i:i+j])

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

main()

Submission status: Accepted

Solution code:
from collections import deque
s=input()
s_list=list(s)
length=len(s)
K=int(input())
o=[]
x=deque(sorted(set(s)))

while len(o) < K:
    letter=x.popleft()
    X=[i for i , x in enumerate(s_list) if x==letter]
    for i in X:
        for j in range(i+1,length+1):
            if not s[i:j] in o:
                o.append(s[i:j])
            if j-1-i == 5:
                break

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

Submission status: Accepted

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

orders = set()

for i in range(n):
    for j in range(1, 6):
        if i + j < n + 1:
            orders.add(S[i:i + j])

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

Submission status: Accepted

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

ss = set()
for i in range(n):
    for j in range(5):
        if i+j < n:
            ss.add(s[i:i+j+1])

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
alps = 'abcdefghijklmnopqrstuvwxyz'
for alp in alps:
    inds = []
    for i,si in enumerate(s):
        if si == alp:
            inds.append(i)
    if inds:
        s_set = set()
        for ind in inds:
            for i in range(1,6):
                if ind+i <= len(s):
                    s_set.add(s[ind:ind+i])
        sl = list(s_set)
        if cnt + len(sl) >= k:
            sl.sort()
            print(sl[k-cnt-1])
            exit()
        else:
            cnt += len(sl)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

n = len(s)
S = set()
import heapq

for i in range(n):
    for j in range(i+1, n+1):
        if j-i > k:
            continue
        t = s[i:j]
        S.add(t)
S = list(S)
#print(S)
S.sort()
print(S[k-1])

Submission status: Accepted

Solution code:
def solve():
  S = input()
  K = int(input())
  lis = set()
  for i in range(len(S)):
    for p in range(1,K+1):
      j = i+p
      if j>len(S):
        continue
      lis.add(S[i:j])
  ans = sorted(list(lis))[K-1]
  return ans
print(solve())

Submission status: Accepted

Solution code:
import collections
s = input()
k = int(input())
dd = collections.defaultdict(int)

for i in range(len(s)):
    tmp = ""
    for j in range(5):
        if(j+i < len(s)):
            tmp += s[j+i]
            dd[tmp]+=1
print(sorted(dd)[k-1])

Submission status: Accepted

Solution code:
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    s = input()
    n = len(s)
    k = ii()
    a = set()
    for i in range(1, k+1):
        for j in range(n):
            a.add(s[j:j+i])
    print(sorted(a)[k-1])
    
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
k = int(input())
lis = ['z'*(5001+i) for i in range(k)]
for i in range(len(s)):
  c = s[i]
  if lis[-1] > c:
    lis.append(c)
    lis = set(lis)
    lis = sorted(lis)[:k]
  else:
    continue
  for j in range(i+1,len(s)):
    if lis[-1] > c:
      c += s[j]
      lis.append(c)
      lis = set(lis)
      lis = sorted(lis)[:k]
    else:
      break
print(lis[-1])

Submission status: Accepted

Solution code:
s=list(input())
k=int(input())
S=sorted(set(s))
t=0
l=[]
can=[]
while len(can)==0:
    for i in range(len(s)):
        if s[i]==S[t]:
            l.append(i)
    for i in l:
        for j in range(1,k+1):
            if i+j<=len(s) and s[i:i+j] not in can:
                can.append(s[i:i+j])
    if len(can)<k:
        k -= len(can)
        t += 1
        can=[]
        l=[]
can.sort()
ans=can[k-1]
print(''.join(ans))

Submission status: Accepted

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



Q=set()


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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()
    K = I()

    l = [[] for _ in range(26)]
    for i in range(len(s)):
        l[ord(s[i])-ord('a')].append(i)

    for i in l:
        tmp = set()
        for j in i:
            for k in range(5):
                if j + k <= len(s) - 1:
                    tmp.add(s[j:j+k+1])
        tmp = list(tmp)
        tmp.sort()
        if len(tmp) >= K:
            print(tmp[K-1])
            break
        else:
            K -= len(tmp)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

ssort = sorted(set(s))
cnt, ans = 0, set()
while len(ans) < k:
    for i, si in enumerate(s):
        if si == ssort[cnt]:
            ans |= {s[i:i + j + 1] for j in range(k)}
    cnt += 1
print(sorted(ans)[k - 1])

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    S = getS()
    k = getN()


    li = []
    for i in range(len(S)):
        for j in range(1, k + 1):
            if i + j > len(S):
                continue
            li.append(S[i:i+j])

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


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
s=input()
k=int(input())
found=[]
now="zzzzzzzzz"

while len(found)<k:
    now="zzzzzzzzzz"
    for i in range(len(s)):
        c=s[i]
        f=1
        while c in found and i+f<len(s):
            c+=s[i+f]
            f+=1
        if not c in found:
            now=min(c,now)
        
    found.append(now)
print(found[-1])