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: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
s = input()
N = len(s)
K = int(input())
L = []
for i in range(N):
	for j in range(5):
		if i + j < N:
			L.append(s[i:i + j + 1])

L = sorted(L)

sub = ""
x = 0
for i in L:
	if x == K:
		print(sub)
		break

	if sub != i:
		sub = i
		x += 1

Submission status: Wrong Answer

Solution code:
s=input();print(sorted(set(s[t:t+i]for t in range(9)for i in range(1,9)))[int(input())-1])

Submission status: Wrong Answer

Solution code:
import sys

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

chars = sorted(set(s))
n = len(s)

for j in range(min(3, len(chars))):
  ans = chars[j]
  K -= 1
  if K == 0:
    print(ans)
    break
  while True:
    places = []
    index = -1
    while True:
      index = s.find(ans, index+1)
      if index == -1:
        break
      places.append(index)

    print(places, ans, K)
    if len(ans) == len(s) - places[0]:
      break

    next_char = 'z' * 6
    for k in places:
      if k >= len(s)-len(ans):
        break
      next_char = min(next_char, s[k+len(ans)])

    ans += next_char
    K -= 1
    if K == 0:
      print(ans)
      sys.exit()

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
l=[]
for t in range(1,len(s)+3):
    for r in range(len(s)-t+1):
        l.append(s[r:r+t])
print(sorted(sorted(set(l)),key=lambda x:len(x))[n-1])

Submission status: Wrong Answer

Solution code:
s=input()
K=int(input())
l=len(s)
d=[[s[i],l-i] for i in range(len(s))]
d=sorted(d)
h=dict()
ans=0
ca=d[0][0]   

for i in d:
    if(i[0]!=i[0][0]):
        break
    z=min(i[1]+1,6)
    for j in range(1,z):
        if(s[l-i[1]:l-i[1]+j] not in h):
            ans+=1
            h.update({s[l-i[1]:l-i[1]+j]:1})
        else:
            pass


h=sorted(h)

Submission status: Wrong Answer

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

ans_stack = []

for i in range(len(s)):
    str_length = 1
    while str_length <= K and i+str_length <= len(s):
        if len(ans_stack) < K:
            ans_stack.append(s[i:i+str_length])
        else:
            if not s[i:i+str_length] in ans_stack:
                ans_stack.append(s[i:i+str_length])
                ans_stack = sorted(ans_stack)[0:K]
#        print(ans_stack)
#        print(s[i:i+str_length])
#        print()
        str_length += 1
print(ans_stack[K-1])

Submission status: Wrong Answer

Solution code:
def cut_kouho(s, char):
    ret = []
    for i in range(s.count(char)):
        ind = s.find(char)
        ret.append(s[ind:])
        if ind == len(s) -1 :
            break
        s = s[ind+1:]
    #print(ret)
    return ret

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

if len(s) < 51 and False:
    tmp = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            tmp.append(s[i:j+1])
    a = list(set(tmp))
    a.sort()
    print(a[k-1])
else:
    char = list(set(list(s)))
    char.sort()
    #print(char)
    nokori = k
    for c in char:
        kouho = cut_kouho(s, c)
        # k文字まで減らしていい
        kouho = [i[:min(nokori, len(i))] for i in kouho]
        # 全探索
        # print(kouho)
        tmp = []
        for string in kouho:
            for i in range(len(string)):
                for j in range(i,len(string)):
                    tmp.append(string[i:j+1])
        a = list(set(tmp))
        a.sort()
        if len(a) >= nokori:
            print(a[nokori-1])
            exit()
        else:
            nokori -= len(a)

Submission status: Wrong Answer

Solution code:
def cut_kouho(s, char):
    ret = []
    for i in range(s.count(char)):
        ind = s.find(char)
        ret.append(s[ind:])
        if ind == len(s) -1 :
            break
        s = s[ind+1:]
    print(ret)
    return ret

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

if len(s) < 51 and False:
    tmp = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            tmp.append(s[i:j+1])
    a = list(set(tmp))
    a.sort()
    print(a[k-1])
else:
    char = list(set(list(s)))
    char.sort()
    #print(char)
    nokori = k
    for c in char:
        kouho = cut_kouho(s, c)
        # k文字まで減らしていい
        kouho = [i[:min(nokori, len(i))] for i in kouho]
        # 全探索
        # print(kouho)
        tmp = []
        for string in kouho:
            for i in range(len(string)):
                for j in range(i,len(string)):
                    tmp.append(string[i:j+1])
        a = list(set(tmp))
        a.sort()
        if len(a) >= nokori:
            print(a[nokori-1])
            exit()
        else:
            nokori -= len(a)

Submission status: Wrong Answer

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

if len(s) < 51:
    tmp = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            tmp.append(s[i:j+1])
    a = list(set(tmp))
    a.sort()
    print(a[k-1])
else:
    print("hoge")

Submission status: Wrong Answer

Solution code:
import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


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


def num():
	return map(int , input().split())


def nu():
	return int(input())


def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x


s=input()
k=nu()
n=min(5,len(s))
z=set()
for i in range(n):
	pp=""
	for j in range(i,n):
		pp+=s[j]
		z.add(pp)
fin=list(z)
fin.sort()
print(fin[k-1])

Submission status: Wrong Answer

Solution code:
import heapq

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

q = []

for i in range(len(S)):
    for j in range(i, len(S) + 1):
        heapq.heappush(q, S[i:j])

last = ''
print(q)
while K > 0:
    s = heapq.heappop(q)
    if s != last:
        K -= 1
        last = s

print(last)

Submission status: Wrong Answer

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 = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-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 S(): return input()
def pf(s): return print(s, flush=True)


s = S()
k = I()
n = len(s)
res = []

def push(res,s):
    if len(res) < k:res.append(s)
    elif s not in res:
        for i in range(k):
            if s<res[i]:
                res.insert(i,s)
                break
    return(res[0:k])

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        res = push(res,s1)

print(res[-1])

Submission status: Wrong Answer

Solution code:
import re

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

substrings = []
min_s = ''
while True:
    if min_s == '':
        temp_min_s = min(list(s))
    else:
        temp_min_s = min(list(re.sub('[%s]' % min_s, '', s)))
    min_s += temp_min_s

    word_len = 1
    while word_len < K+1:
        if re.search('%s[a-z]{%d}' % (temp_min_s, word_len-1), s) == None:
            break
        substrings.extend(list(set(re.findall('%s[a-z]{%d}' % (temp_min_s, word_len-1), s))))
        word_len += 1

    if len(substrings) >= K:
        print(sorted(substrings)[K-1])
        exit()

Submission status: Wrong Answer

Solution code:
import re

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

substrings = []
min_s = ''
while True:
    if min_s == '':
        temp_min_s = min(list(s))
    else:
        temp_min_s = min(list(re.sub('[%s]' % min_s, '', s)))
    min_s += temp_min_s

    word_len = 1
    while word_len < 6:
        if re.search('%s[a-z]{%d}' % (temp_min_s, word_len-1), s) == None:
            break
        substrings.extend(list(set(re.findall('%s[a-z]{%d}' % (temp_min_s, word_len-1), s))))
        word_len += 1

    if len(substrings) >= K:
        print(sorted(substrings)[K-1])
        exit()

Submission status: Wrong Answer

Solution code:
def sub_k(string, I, K):
    temp = []
    for i in range(len(string)):
        if i-1+I == len(string):
            continue
        temp.append(string[i:i+I])
    return sorted(set(temp))[0:K]

def main(string, K):
    for i in range(K):
        print(sub_k(string, i+1, K-i))

string = input()
K = int(input())
main(string, K)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
 
sub = set()
for i in range(1,min(K, len(S))+1):
    for j in range(len(S)-i+1):
        sub.add(S[j:j+i])
        print(S[j:j+i])
m=list(sub)
m.sort()
print(m)
print(m[K-1])

Submission status: Wrong Answer

Solution code:
str = raw_input()
index = input()-1
dic = []
for i in range(0,len(str)+1):
    for j in range(0,len(str)-i):
        if str[j:j+i+1] not in dic:
            dic.append(str[j:j+i+1])
print dic[index]

Submission status: Wrong Answer

Solution code:
s = input("string:")
K = int(input("K:"))
# substrings = {}
substrings = []
for i in range(1,len(s)+1):
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            # substrings[s[j:j+1]] = True
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])

Submission status: Wrong Answer

Solution code:
original = str(input('string'))
num = int(input('num'))
string = list(original)
row = len(string)
ans = []
for i in range(1,row):
    for j in range(0,row-i+1):
        buf = ''
        for k in range(0,i):
            buf += string[j+k]
        ans.append(buf)
ans.append(original)
ans = sorted(set(ans), key=ans.index)
ans = sorted(ans)
print(ans[num-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest C問題
Author     : KitauraHiromi
LastUpdate : 20180517
Since      : 20180517
"""

def duplicate(substr, strs):
    ans = False
    for str in strs:
        ans = ans or substr in str
        # print(str, substr)
    return ans

def head_char(substrs, k):
    dict = {}
    for i in range(len(substrs)):
        dict[substrs[i][0]] = 0
    for i in range(len(substrs)):
        if not duplicate(substrs[i], substrs[:i]):
            dict[substrs[i][0]] += len(substrs[i])
    sum = 0
    pre_sum = 0
    pre_alph = ""
    for alph in sorted(dict.keys()):
        if sum > k:
            return (pre_alph, pre_sum)
        pre_sum = sum
        pre_alph = alph
        sum += dict[alph]
    return (pre_alph, pre_sum)

def find_substring(substrs, K, ret):
    # print("K", K, "ret", ret)
    if K <= 0:
        return ret
    head, k = head_char(substrs, K-1)
    # print("head:", head)
    idxes = [pos for pos, substr in enumerate(substrs) if substr[0] == head]
    new_substrs = [substrs[idx][1:] for idx in idxes if substrs[idx][1:] != ""]
    # print("new_substrs", new_substrs)
    # print(new_substrs, K-k)
    return find_substring(new_substrs, K-k-1, ret+head)

s = input()
K = int(input())
substrs = [s[i:] for i in range(len(s))]
print(find_substring(substrs, K, ""))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest C問題
Author     : KitauraHiromi
LastUpdate : 20180517
Since      : 20180517
"""
def head_char(substrs, k):
    dict = {}
    for i in range(len(substrs)):
        dict[substrs[i][0]] = 0
    for i in range(len(substrs)):
        # if substrs[i] not in dict.keys():
        dict[substrs[i][0]] += len(substrs[i])
    sum = 0
    pre_sum = 0
    pre_alph = ""
    for alph in sorted(dict.keys()):
        if sum > k:
            return (pre_alph, pre_sum)
        pre_sum = sum
        pre_alph = alph
        sum += dict[alph]
    return (pre_alph, pre_sum)

def find_substring(substrs, K, ret):
    # print("K", K, "ret", ret)
    if K <= 0:
        return ret
    head, k = head_char(substrs, K-1)
    # print("head:", head)
    idxes = [pos for pos, substr in enumerate(substrs) if substr[0] == head]
    new_substrs = [substrs[idx][1:] for idx in idxes if substrs[idx][1:] != ""]
    # print("new_substrs", new_substrs)
    # print(new_substrs, K-k)
    return find_substring(new_substrs, K-k-1, ret+head)

s = input()
K = int(input())
substrs = [s[i:] for i in range(len(s))]
print(find_substring(substrs, K, ""))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest C問題
Author     : KitauraHiromi
LastUpdate : 20180517
Since      : 20180517
"""
def head_char(substrs, k):
    dict = {}
    for i in range(len(substrs)):
        dict[substrs[i][0]] = 0
    for i in range(len(substrs)):
        if substrs[i] not in dict.keys():
            dict[substrs[i][0]] += len(substrs[i])
    sum = 0
    pre_sum = 0
    pre_alph = ""
    for alph in sorted(dict.keys()):
        if sum > k:
            return (pre_alph, pre_sum)
        pre_sum = sum
        pre_alph = alph
        sum += dict[alph]
    return (pre_alph, pre_sum)

def find_substring(substrs, K, ret):
    # print("K", K, "ret", ret)
    if K <= 0:
        return ret
    head, k = head_char(substrs, K-1)
    # print("head:", head)
    idxes = [pos for pos, substr in enumerate(substrs) if substr[0] == head]
    new_substrs = [substrs[idx][1:] for idx in idxes if substrs[idx][1:] != ""]
    # print("new_substrs", new_substrs)
    # print(new_substrs, K-k)
    return find_substring(new_substrs, K-k-1, ret+head)

s = input()
K = int(input())
substrs = [s[i:] for i in range(len(s))]
print(find_substring(substrs, K, ""))

Submission status: Wrong Answer

Solution code:
word = list(input())
order = int(input())
substrings = set()

for n in range(len(word)):
    for j in range(len(word)-n):
        substrings.add(''.join(word[n:j+n+1]))
        if len(substrings) >= 5:
            break

an = sorted(set(substrings))
print(an[order-1])

Submission status: Wrong Answer

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

list = {}

for i in range(len(s)):
    for j in range(i + 1,6):
        if(s[i:j] not in list):
            list[s[i:j]] = 0

keys = sorted(list.keys())

print(keys[k - 1])

Submission status: Wrong Answer

Solution code:
def main():
    string = input().strip()
    k = int(input())
    s = set()
    for char in sorted(set(string)):
        s.add(char)
        if len(s) == k:
            print(char)
            return
        for stlide in range(2, 6):
            for i in range(len(string)):
                if string[i] == char:
                    sub = string[i:i+stlide]
                    s.add(sub)
            if len(s) >= k:
                print(sorted(s)[k - 1])
                return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cand = [str(s[0])]
for i in range(len(s)):
    if s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        #cand = sorted(cand)
        cand.sort()
        if len(cand) > n:
            cand.pop()


print(cand.pop())

Submission status: Wrong Answer

Solution code:


def main():
    string = input().strip()
    k = int(input())
    chars = list(sorted(set(string)))
    s = set()
    for char in chars:
        s.add(char)
        if len(s) == k:
            print(char)
            return
        for stlide in range(2, 6):
            for i in range(len(string)):
                if string[i] == char:
                    sub = string[i:i+stlide]
                    s.add(sub)
            if len(s) >= k:
                print(sorted(s)[k - 1])
                return 


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(len(s)):
    print(i, s[i])

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = str(s[i:j+1])
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        cand = sorted(cand)
        if len(cand) > n:
            cand.pop()


print(cand.pop())

Submission status: Wrong Answer

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

tmp=[s[0]]

for i in range(len(s)):
    for j in range(i,len(s)):
        cur_s=s[i:j+1]
        if cur_s not in tmp:
            if len(tmp)==k:
                if tmp[-1]<cur_s:
                    break
            idx=[ele<cur_s for ele in tmp].count(True)
            tmp=tmp[:idx]+[cur_s]+tmp[idx:-1]
print(tmp[-1])

Submission status: Wrong Answer

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

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[len(cand)-1]:
        continue
    for j in range(i, len(s)):
        tmp = str(s[i:j+1])
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        if len(cand) > n:
            cand = sorted(cand)
            cand.pop()


print(cand.pop())

Submission status: Wrong Answer

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

cand = [s[0]]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[len(cand)-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        if len(cand) > n:
            cand = sorted(cand)
            cand.pop()


print(cand.pop())

Submission status: Wrong Answer

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

cand = [s[0]]
for i in range(len(s)):
    if s[i] > cand[len(cand)-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        if len(cand) > n:
            cand = sorted(cand)
            cand.pop()


print(cand.pop())

Submission status: Wrong Answer

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

cand = [s[0]]
for i in range(len(s)):
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        if len(cand) > n:
            cand = sorted(cand)
            cand.pop()


print(cand.pop())

Submission status: Wrong Answer

Solution code:
s = str(raw_input())
cont = int(raw_input())
result = []
for i in range(len(s)):
    for k in range(len(s)):
        for j in range(len(s) - i):
            a = s[j:k+j+1]
            #print('a:'+str(a)+' j:'+str(j)+' k:'+str(k))
            if a in result:
                continue
            else:
                result.append(a)
result.sort()
print(result)
print(result[cont-1])

Submission status: Wrong Answer

Solution code:
# n = int(input())
# a, b = map(int, input().split())
# c = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]

alphabet = "abcdefghijklnmopqrstuvwxyz"
s = input()
k = int(input())
s_set = set(s)
ans = set()

if k == 1:
    s_set_list = list(s_set)
    s_set_list.sort()
    print(s_set_list[0])

elif k >= 2:
    for c in alphabet:
        for i in range(len(s)):
            if c == s[i]:
                ans.add(c)
                if i == len(s[i]):
                    break
                for j in range(i+1, i+k+2):
                    if j > len(s):
                        break
                    ans.add(s[i:j])
        if len(ans) > k:
            break


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

Submission status: Wrong Answer

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):

    if len(S) <= 50:
        d = set([])
        for i in range(len(S)):
            for j in range(i + 1, len(S) + 1):
                d.add(S[i:j])

    # print('-----')

    import bisect
    S_ = [c for c in S]
    # S_.sort()
    idxs = []

    for k in sorted(set(S_)):
        # print('k', k)
        for i in range(len(S)):
            if S[i] == k:
                idxs.append(i)
        d = []

        for i in idxs:
            # print(i)
            for j in range(i + 1, len(S) + 1):
                t = "".join(S[i:j])
                if len(d) > K and d[-1] < t:
                    break
                if t not in d:
                    bisect.insort(d, t)
                    d = d[:K]
        if len(d) >= K:
            break
    print(d)
    return sorted(d)[K - 1]


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# n = int(input())
# a, b = map(int, input().split())
# c = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]

alphabet = "abcdefghijklnmopqrstuvwxyz"
s = input()
k = int(input())
s_set = set(s)
ans = set()

if k == 1:
    s_set_list = list(s_set)
    s_set_list.sort()
    print(s_set_list[0])

elif k >= 2:
    for c in alphabet:
        for i in range(len(s)):
            if c == s[i]:
                ans.add(c)
                if i == len(s[i]):
                    break
                for j in range(i+1, i+k+1):
                    if j > len(s):
                        break
                    ans.add(s[i:j])
        if len(ans) > k:
            break


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# n = int(input())
# a, b = map(int, input().split())
# c = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]

alphabet = "abcdefghijklnmopqrstuvwxyz"
s = input()
k = int(input())
s_set = set(s)
ans = set()

if k == 1:
    s_set_list = list(s_set)
    s_set_list.sort()
    print(s_set_list[0])

elif k >= 2:
    for c in alphabet:
        for i in range(len(s)):
            if c == s[i]:
                ans.add(c)
                if i == len(s[i]):
                    break
                for j in range(i+1, i+k+1):
                    if j > len(s):
                        break
                    ans.add(s[i:j])
        if len(ans) >= k:
            break


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

Submission status: Wrong Answer

Solution code:
# n = int(input())
# a, b = map(int, input().split())
# c = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]

alphabet = "abcdefghijklnmopqrstuvwxyz"
s = input()
k = int(input())
s_set = set(s)
ans = []

if k == 1:
    s_set_list = list(s_set)
    s_set_list.sort()
    print(s_set_list[0])

elif k >= 2:
    for c in alphabet:
        for i in range(len(s)):
            if c == s[i]:
                ans.append(c)
                if i == len(s[i]):
                    break
                for j in range(i+1,i+k+1):
                    if j > len(s):
                        break
                    ans.append(s[i:j])

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

Submission status: Wrong Answer

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


def solve(tc):
    s = stdin.readline().strip()
    k = int(stdin.readline().strip())

    n = len(s)
    li = [list() for i in range(26)]
    for i in range(n):
        li[ord(s[i])-ord('a')].append(i)
    
    p = 0
    while len(li[p])==0:
        p += 1
    
    ans = set()
    while len(ans)<k and p<26:
        for i in range(n):
            for j in range(len(li[p])):
                b = li[p][j]
                e = min(n, li[p][j] + i + 1)
                ans.add(s[b:e])
                if len(ans)==k:
                    break
            if len(ans)==k:
                break
        if len(ans)==k:
            break
        p += 1
    lans = list(ans)
    lans.sort()
    print(lans[k-1])
    pass


LOCAL_TEST = not __debug__
if LOCAL_TEST:
    infile = __file__.split('.')[0] + "-test.in"
    stdin = open(infile, 'r')

tcs = (int(stdin.readline().strip()) if LOCAL_TEST else 1)
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

Solution code:
ALPHABETS = 26

ORD_A = ord('a')

# fast io
import sys
S,K = sys.stdin.readlines()[:2]

S = [ord(c)-ORD_A for c in S]
while S[-1] < 0:
  S.pop()


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

dp = [None]*(N+1)
dp[N] = 0
indices = [N]*ALPHABETS
s = 1

import sys

old = 1

for i,c in enumerate(reversed(S)):
  dp[i] = s
  if s > K:
    break
  s = 2*s
  s -= dp[indices[c]]
  indices[c] = i


dp.pop()
dp.reverse()
dp.append(0)

indices = [[] for _ in range(ALPHABETS)]
for i,c in enumerate(S):
  indices[c].append(i)
for l in indices:
  l.append(N)

del S

from bisect import bisect_left
def find(k):

  s = []
  i = 0
  while k > 0:
    f = False
    for c,L in enumerate(indices):
      j = L[bisect_left(L, i)]
      t = dp[j]
      if t is None or t >= k:
        s.append(c)
        k -= 1
        i = j+1
        f = True
        break
      else:
        k -= t
    if not f:
      break
  if not s:
    return 'Eel'
  return ''.join(chr(c+ORD_A) for c in s)

print(find(K))

Submission status: Wrong Answer

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

ls = len(s)
m = []
for i in range(ls):
    for j in range(5):
        ss = s[i:i+j+1]
        if ss in m:
            continue
        for k in range(len(m)+1):
            if k == len(m) or m[k] > ss:
                m.insert(k, ss)
                break
        m = m[0:5]
print(m[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
N=len(s)
K=int(input())
L=[]
for i in range(1,K+1):
    for j in range(N-i+1):
        L.append(s[j:j+i])
L.sort()
M=len(L)
k=0
if K==1:
    print(L[0])
    exit()
for j in range(M-1):
    if L[j]!=L[j+1]:
        k+=1
    if k==K:
        print(L[j])
        break

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
ans = []
for i in s:
    if not (i in ans):
        ans.append(i)
ans = ans[:5]
j = len(s)
if j >= 2:
    for i in range(j-1):
        if (s[i] in ans) and not (s[i:i+2] in ans):
            ans.append(s[i:i+2])
ans.sort()
ans = ans[:5]
if j >= 3:
    for i in range(j-2):
        if (s[i:i+2] in ans) and not (s[i:i+3] in ans):
            ans.append(s[i:i+3])
ans.sort()
ans = ans[:5]
if j >= 4:
    for i in range(j-3):
        if (s[i:i+3] in ans) and not (s[i:i+4] in ans):
            ans.append(s[i:i+4])
ans.sort()
ans = ans[:5]
if j >= 5:
    for i in range(j-4):
        if (s[i:i+4] in ans) and not (s[i:i+5] in ans):
            ans.append(s[i:i+5])
ans.sort()
ans = ans[:5]
print(ans[K-1])

Submission status: Wrong Answer

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)):
        print(i)
        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: Wrong Answer

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])
            if k <= len(slist):
                break
slist.sort()
print(slist[k-1])

Submission status: Time Limit Exceeded

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

len_s =  len(s)
L = []

for i in range(1, len_s+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: Time Limit Exceeded

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

len_s =  len(s)
L = []

for i in range(1, len_s+1):
    for j in range(len_s-i+1):
        L.append(s[j:j+i])
L = list(set(L))
L.sort()
print(L[k-1])

Submission status: Time Limit Exceeded

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):
    for j in lis[i]:
        k = j
        while k <= K + 10000:
            ans_lis.append(s[j:k + 1])
            k += 1
    ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()

Submission status: Time Limit Exceeded

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):
    for j in lis[i]:
        k = j
        while k <= s_length:
            ans_lis.append(s[j:k + 1])
            k += 1
    ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()