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())
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 <= 3000:
            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: Wrong Answer

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

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

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 <= s_length:
        for j in lis[i]:
            ans_lis.append(s[j: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: Wrong Answer

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 <= s_length:
        for j in lis[i]:
            ans_lis.append(s[j: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: Wrong Answer

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

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()
    for k in range(1, len(S)+1):
        for p in range(len(S)-k+1):
            sub = S[p:p+k]
            dic.add(sub)
    #dic = sorted(list(dic))
    #print(dic[K-1])


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

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:
        continue
    ans = sub
    k += 1
    if k == K:
        break
for c in ans:
    print(chr(c), end="")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
s = input()
k = int(input())
dd = defaultdict(lambda:0)
if len(s) == 1:
    print(s)
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)):
        dd[s[i:j+1]] = 1
li = []
for key in dd:
    li.append(key)
li.sort()
print(li[k-1])

Submission status: Wrong Answer

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 == s[cnt]:
            ans |= {s[i:i + j + 1] for j in range(k)}
    cnt += 1
print(sorted(ans)[k - 1])

Submission status: Wrong Answer

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

abc='abcdefghijklmnopqrstuvwxtz'

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

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

cnt=0
for i in abc:
  dfs(1,i)

Submission status: Wrong Answer

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

    n = len(s)

    L = set()
    t = list(set(s))
    t.sort()
    for a in t:
        b = [i for i,x in enumerate(s) if x == a]
        for j in b:
            for k in range(j+1,min(n+1,j+6)):
                L.add(s[j:k])

            if len(L) >= K:
                L2 = list(L)
                L2.sort()
                print(L2[K-1])
                exit()

main()

Submission status: Wrong Answer

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

def main():
    s = input()
    k = int(input())
    ss = set()
    pri = ["z"]*5
    for i in range(len(s)):
        nw = ""
        for sj in s[i::]:
            nw += sj
            if not nw in ss:
                if nw < pri[0]:
                    pri[1:5] = pri[0:4]
                    pri[0] = nw
                elif nw < pri[1]:
                    pri[2:5] = pri[1:4]
                    pri[1] = nw
                elif nw < pri[2]:
                    pri[3:5] = pri[2:4]
                    pri[2] = nw
                elif nw < pri[3]:
                    pri[4:5] = pri[3:4]
                    pri[3] = nw
                elif nw < pri[4]:
                    pri[4] = nw
            ss.add(nw)
    print(pri[k-1])



    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ch={}
for S in s:
    if S not in ch:
        ch[S]=1

ch=list(ch.keys())

cand=[]
CAND={}
leng=0
for c in ch:
    for i in range(len(s)):
        if s[i]==c:
            for j in range(len(s)-i):
                if s[i:i+j+1] not in CAND:
                    cand.append(s[i:i+j+1])
                    CAND[s[i:i+j+1]]=1
                    leng+=1
    if leng>=K:
        break

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

print(ans[K-1])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
substrings = set()
for lc in "abcdefghijklmnopqrstuvwxyz":
    if lc not in s:
        continue
    for i in range(len(s)):
        if s[i] != lc:
            continue
        for j in range(i + 1, len(s) + 1):
            substrings.add(s[i:j])
        if len(substrings) >= K:
            break
print(sorted(list(substrings))[K - 1])

Submission status: Wrong Answer

Solution code:
from itertools import combinations
s = input()
n = int(input())

le = len(s)

if le < 5:
    seed = tuple(combinations(range(le + 1), 2))
    res = set()
    for i, j in seed:
        res.add(s[i:j])
    ans = sorted(res)
    print(ans[n - 1])
    exit()
else:
    res = "zzzzz"
    for i in range(le - 5):
        res = min(res, s[i:i+5])
    print(res[:n])

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import deque
s = input()
n = int(input())

le = len(s)
seed = tuple(combinations(range(le + 1), 2))

res = deque()
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")

for i, j in seed:
    ch = s[i:j]
    if ch in res:
        continue
    elif ch < max(res):
        res.remove(max(res))
        res.append(ch)
        print(res)

ans = sorted(res)
print(ans[n - 1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

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

min_index = [n for n, v in enumerate(s) if v == min(s)]

ans_list = [min(s)]
queue = []
i = 2

while len(ans_list) < K:
    print("hello", i)
    # 候補の生成
    for m in min_index:
        for i in range(1, 6):
            if m + i < len(s):
                heappush(queue, s[m:m+i])
    while queue:
        c = heappop(queue)
        if c not in ans_list:
            ans_list.append(c)

print(ans_list[K-1])

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def main():
    all_s = input()
    k = int(input())
    ind = {a: [] for a in ascii_lowercase}
    if len(all_s) == 1:
        print(all_s)
    else:
        for i in range(len(all_s)):
            ind[all_s[i]].append(i)
        for s, index in ind.items():
            if not index:
                continue
            else:
                substr = {s}
                i = 1
                all_substr = (len(all_s) - 1) * len(index) - sum(index) + 1
                if all_substr < k:
                    k -= all_substr
                    continue
                before_len = 0
                while len(substr) != before_len:
                    before_len = len(substr)
                    for j in index:
                        substr.add(all_s[j:i + j + 1])
                    i += 1
                if k <= len(substr):
                    substr = list(substr)
                    substr.sort()
                    print(substr[k - 1])
                    break
                else:
                    k -= len(s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())


finish = set()
S = len(s)

for i in range(S):
    for j in range(1,6):
        finish.add(s[i:i+j])

finish = list(finish)

print(finish[k-1])

Submission status: Wrong Answer

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

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def main():
    all_s = input()
    k = int(input())
    ind = {a: [] for a in ascii_lowercase}
    if len(all_s) == 1:
        print(all_s)
    else:
        for i in range(len(all_s)):
            ind[all_s[i]].append(i)
        for s, index in ind.items():
            if not index:
                continue
            else:
                substr = {s}
                i = 1
                all_substr = len(all_s) * len(index) - sum(index)
                if all_substr < k:
                    k -= all_substr
                    continue
                before_len = 0
                while len(substr) != before_len:
                    before_len = len(substr)
                    for j in index:
                        substr.add(all_s[j:i + j + 1])
                    i += 1
                substr = list(substr)
                substr.sort()
                if k <= len(substr):
                    print(substr[k - 1])
                    break
                else:
                    k -= len(substr)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
 
mem = [chr(ord('z')+1)]*5
 
for i in range(0,len(s)):
    j_end = i+5 if i+5 <= len(s)+1 else len(s)+1
    for j in range(i+1, j_end):
        ext_s = s[i:j]
        #print(s[i:j])
        if not ext_s in mem:
            for k in range(len(mem)):
                if mem[k] > ext_s: 
                    mem.insert(k, ext_s)
                    del mem[-1]
                    break
print(mem[n-1])

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
 
mem = [chr(ord('z')+1)]*5
 
for i in range(0,len(s)):
    j_end = i+5 if i+5 < len(s)+1 else len(s)+1
    for j in range(i+1, j_end):
        ext_s = s[i:j]
        #print(s[i:j])
        if not ext_s in mem:
            for k in range(len(mem)):
                if mem[k] > ext_s: 
                    mem.insert(k, ext_s)
                    del mem[-1]
                    break
print(mem[n-1])

Submission status: Wrong Answer

Solution code:
import re
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


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

    total = 0
    for al in AL:
        mat1 = re.findall(re.compile(al + r"[a-z]{0}"), s)
        mat2 = re.findall(re.compile(al + r"[a-z]{1}"), s)
        mat3 = re.findall(re.compile(al + r"[a-z]{2}"), s)
        mat4 = re.findall(re.compile(al + r"[a-z]{3}"), s)
        mat5 = re.findall(re.compile(al + r"[a-z]{4}"), s)
        mat = set(mat1 + mat2 + mat3 + mat4 + mat5)
        mat = sorted(mat)
        if total + len(mat) >= K:
            ans = mat[K - 1 - total]
            break
        else:
            total += len(mat)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import re
import sys
from string import ascii_lowercase as AL
input = sys.stdin.readline


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

    N = len(s)
    total = 0
    ans = ""
    for al in AL:
        mat1 = re.findall(re.compile(al + r"[a-z]{0}"), s)
        mat2 = re.findall(re.compile(al + r"[a-z]{1}"), s)
        mat3 = re.findall(re.compile(al + r"[a-z]{2}"), s)
        mat4 = re.findall(re.compile(al + r"[a-z]{3}"), s)
        mat5 = re.findall(re.compile(al + r"[a-z]{4}"), s)
        mat = set(mat1 + mat2 + mat3 + mat4 + mat5)
        mat = sorted(mat)
        if total + len(mat) >= K:
            ans = mat[K-1-total]
            break
        else:
            total += len(mat)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        print(s[i:j])
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(*ans)

Submission status: Wrong Answer

Solution code:
def change(n, word):
    for i in range(k-1, n):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k-1])

Submission status: Wrong Answer

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

l = 0
r = min(len(s), 5)
li = ['zzzzzz'] * 5

def hantei(s):
    global li
    if s > li[4]:
        pass
    elif s == li[4]:
        pass
    elif s > li[3]:
        li[4] = s
    elif s == li[3]:
        pass
    elif s > li[2]:
        li[3] = s
    elif s == li[2]:
        pass
    elif s > li[1]:
        li[2] = s
    elif s == li[1]:
        pass
    elif s > li[0]:
        li[1] = s
    elif s == li[0]:
        pass
    else:
        li[0] = s

while l != r:
    s1 = s[l:r]
    for i in range(1,len(s1)+1):
        s2 = s1[:i]
        hantei(s2)

    if r < lens:
        r += 1
    l += 1

print(li[k-1])

Submission status: Wrong Answer

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

l = 0
r = min(len(s), 5)
li = ['zzzzz'] * 5

def hantei(s):
    global li
    if s > li[4]:
        pass
    elif s == li[4]:
        pass
    elif s > li[3]:
        li[4] = s
    elif s == li[3]:
        pass
    elif s > li[2]:
        li[3] = s
    elif s == li[2]:
        pass
    elif s > li[1]:
        li[2] = s
    elif s == li[1]:
        pass
    elif s > li[0]:
        li[1] = s
    elif s == li[0]:
        pass
    else:
        li[0] = s

while l != r:
    s1 = s[l:r]
    for i in range(1,len(s1)+1):
        s2 = s1[:i]
        hantei(s2)

    if r < lens:
        r += 1
    l += 1

print(li[k-1])

Submission status: Wrong Answer

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

l = 0
r = min(len(s), 5)
li = ['zzzzz'] * 5

def hantei(s):
    global li
    if s > li[4]:
        pass
    elif s == li[4]:
        pass
    elif s > li[3]:
        li[4] = s
    elif s == li[3]:
        pass
    elif s > li[2]:
        li[3] = s
    elif s == li[2]:
        pass
    elif s > li[1]:
        li[2] = s
    elif s == li[1]:
        pass
    elif s > li[0]:
        li[1] = s
    elif s == li[0]:
        pass
    else:
        li[0] = s

while l != r:
    s1 = s[l:r]
    for i in range(1,len(s1)+1):
        s2 = s1[:i]
        hantei(s2)

    if r < lens - 1:
        r += 1
    l += 1

print(li[k-1])

Submission status: Wrong Answer

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

l = 0
r = min(len(s), 5)
li = ['zzzzz'] * 5

def hantei(s):
    global li
    if s > li[4]:
        pass
    elif s > li[3]:
        li[4] = s
    elif s > li[2]:
        li[3] = s
    elif s > li[1]:
        li[2] = s
    elif s > li[0]:
        li[1] = s
    else:
        li[0] = s

while l != r:
    s1 = s[l:r]
    for i in range(1,len(s1)+1):
        s2 = s1[:i]
        hantei(s2)

    if r < lens - 1:
        r += 1
    l += 1

print(li[k-1])

Submission status: Wrong Answer

Solution code:
#s=input()
#N=int(input())
s="atcoderandatcodeer"
N=5
D={}

if(len(s)<=10):
    for i in range(1,len(s)+1):
        for j in range(len(s)):
            if D.get(s[j:j+i],None) == None:
                D[s[j:j+i]]=1
    D=sorted(D)
    print(D[N-1])
    exit()
else:
    t=sorted(s)
    i=0
    k=0
    for c in t:
        if(c!=k):
            i=0
            if(len(D)>=5):
                break
        k=c
        while(i<len(s)):
            if(s[i]==c):
                break
            i+=1
        j=i+1
        while(j<=len(s)):
            D[s[i:j]]=1
            j+=1
        i+=1
    
    D=sorted(D)
    print(D[N-1])
    exit()

Submission status: Wrong Answer

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

dp=[[[[[0]*27 for i in range(27)] for i in range(27)] for i in range(27)] for i in range(27)]

for i in range(len(s)):
    for j in range(5):
        temp=list(map(lambda x:ord(x)-96,s[i:i+j+1]))+[0,0,0,0,0]
        #print(temp)
        dp[temp[0]][temp[1]][temp[2]][temp[3]][temp[4]]=1
        
    

for a in range(len(dp)):
    for b in range(len(dp[a])):
        for c in range(len(dp[a][b])):
            for d in range(len(dp[a][b][c])):
                for e in range(len(dp[a][b][c][d])):
                    if dp[a][b][c][d][e]==1:
                        if K==1:
                            print(chr(a+96 if a!=0 else 0)+chr(b+96 if b!=0 else 0)+chr(c+96 if c!=0 else 0)+chr(d+96 if d!=0 else 0)+chr(e+96 if e!=0 else 0))
                            exit()
                        else:
                            K-=1

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
uselist=[]
count=0
checker=0
alphabet="abcdefghijklmnopqrstuvwxyz"
while  checker<=26:
    for i in alphabet:
        for j in range(len(s)):
            if s[j]==i:
                uselist.append((j,i))
                count+=1
            if count>5:
                break
        checker+=1
anslist=[]
for some in uselist:
    for j in range(some[0],len(s)):
        anslist.append(s[some[0]:j+1:])
anslist=sorted(set(anslist))
print(anslist[k-1])

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    t = str(input().rstrip('\n'))
    s = collections.Counter(t).most_common()
    k = int(input().rstrip('\n'))
    s.sort()
    d = {}
    for key, v in s:
        for i in range(len(s)):
            if t[i] == key:
                for j in range(i + 1, i + 6):
                    d[t[i:j]] = 1
        if len(d) >= k:
            print(sorted(d.items())[k-1][0])
            exit()


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

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

abc = collections.defaultdict(list)

for i in range(len(s)):
    if i > len(s) - 5:
        abc[s[i:]].append(i)
    else:
        abc[s[i:i+5]].append(i)

abc = list(abc.items())
abc.sort(key=lambda x: x[0])


print(abc[0][0])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      temp = []
      for k in range(len(s)):
        if j+k == len(s) or len(temp)>=K:
          selected+= temp
          break
        temp.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    print(index)
    for j in index:
      for k in range(len(s)):
        if j+k == len(s):
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break

Submission status: Wrong Answer

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
a = [i for i in input()]
n = ip()
minplace = [0]
minlet = a[0]
nextlet = 'z'
nextminplace = []
for i in range(1,len(a)):
    if a[i] < minlet:
        nextlet = minlet
        nextminplace = copy.copy(minplace)
        minlet = a[i]
        minplace.clear()
        minplace.append(i)
    elif a[i] == minlet:
        minplace.append(i)
    elif a[i] < nextlet:
        nextminplace.clear()
        nextlet = a[i]
        nextminplace.append(i)
    elif a[i] == nextlet:
        nextminplace.append(i)
wl = []
#print(minplace,nextminplace)
for start in minplace:
    word = [a[start]]
    wl.append(''.join(word))
    for i in range(start+1,start+5):
        if i >= len(a): break
        word.append(a[i])
        wl.append(''.join(word))
wl = list(set(wl))
#print(wl)
for start in nextminplace:
    word = [a[start]]
    wl.append(''.join(word))
    for i in range(start+1,start+5):
        if i >= len(a): break
        word.append(a[i])
        wl.append(''.join(word))
#print(wl)
wl.sort()
print(wl[n-1])

Submission status: Wrong Answer

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

for i in range(len(s)):
	for j in range(i,len(s)):
		alist.append(s[i:j])
alist.sort()
print(alist[k-1])

Submission status: Wrong Answer

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

al = [chr(ord('a') + i) for i in range(26)]

candidate_5strings = []
for i in range(len(al)):
    _al = al[i]
    for j in range(len(s)):
        if s[j] == _al:
            candidate_5strings.append(s[j: min(j + 5, len(s))])

        if len(candidate_5strings) == 5:
            break
    else:
        continue
    break

candidate_5strings.sort()
candidate_all = []
for c in candidate_5strings:
    for i in range(len(c)):
        candidate_all.append(c[:i+1])


candidate_all = list(set(candidate_all))
candidate_all.sort()

print(candidate_all[K-1])

Submission status: Wrong Answer

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

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

print('test')

Submission status: Wrong Answer

Solution code:
# a〜z
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

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

if s==['z']:
  exit()

l2=[]

a=''
for x in l:
  if x in s:
    a=x
    for i in range(len(s)):
      if s[i]==a:
        for j in range(6):
          l2.append(''.join(s[i:i+j]))
l2=list(set(l2))
l2.remove('')
l2.sort()
print(l2[K-1])