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:
list_S = list(input())
k = int(input())
set_ANS = set()
list_Alph = list(set(list_S))
list_Alph.sort()
cnt = 0

for c in list_Alph:
    q = [i for i, x in enumerate(list_S) if x == c]
    for j in range(1, len(list_S)+1):
        for i in q:
            if i + j <= len(list_S):
                l = "".join(list_S[i:i+j])
                if l not in set_ANS:
                    set_ANS.add(l)
                    cnt += 1
        if cnt >= k:
            list_ANS = list(set_ANS)
            list_ANS.sort()
            print(list_ANS[k-1])
            exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if len(S) >= K:
    ans = S[:K]
    for i in range(len(S) - K + 1):
        tmp = S[i:i+K]
        if tmp < ans:
            ans = tmp
    print(ans)
elif len(S) == 2:
    if S[0] > S[1]:
        print(S)
    else: print(S[1])
elif len(S) == 3:
    sl = list(set([S[0],S[1],S[2], S[:2],S[1:], S]))
    sl.sort()
    print(sl[K-1])
else:
    sl = list(set([S[0],S[1],S[2],S[3], S[:2],S[1:3],S[2:], S[:3],S[1:], S]))
    sl.sort()
    print(sl[K-1])

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if len(S) >= K:
    ans = S[:K]
    for i in range(len(S) - K + 1):
        tmp = S[i:i+K]
        if tmp < ans:
            ans = tmp
    print(ans)
elif len(S) == 2:
    if S[0] > S[1]:
        print(S)
    else: print(S[1])
elif len(S) == 3:
    sl = list(set([S[0],S[1],S[2], S[:2],S[1:], S]))
    sl.sort()
    print(sl[K-1])
else:
    sl = list(set([S[0],S[1],S[2],S[3], S[:2],S[1:3],S[2:], S[:3],S[1:], S]))
    sl.sort()
    print(sl[4])

Submission status: Wrong Answer

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

se = set()
for i in range(len(s)+1):
    for j in range(i,i+k+1):
        se.add(s[i:j])
se.remove('')
l = sorted(list(se))
l.sort(key=len)
print(l[-k])

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
se=set()
for i in range(len(s)+1):
  for j in range(i,len(s)+1):
    se.add(''.join(s[i:j]))
se.remove('')
l=sorted(list(se))
l.sort(key=len)
#print(l)
print(l[-k])

Submission status: Wrong Answer

Solution code:
s=input()
K=int(input())
answers=[]
S=[a for a in s]
N=len(S)
for a in range(N):
    number = 0
    while a + number <= N and number<=K:
        z = S[a:a + number]
        moji = ''
        for y in z:
            moji += y
            answers.append(moji)
        number += 1
kotae = []
for a in answers:
    if a in kotae:
        pass
    else:
        kotae.append(a)
kotae = sorted(kotae)
print(kotae)
print(kotae[K - 1])

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
t = sorted(s)
u = []
v = []
for i in range(min(len(s), 5)):
    u.append(t[i])
for i in range(len(s)):
    if s[i] in u:
        if not [s[i]] in v:
            v.append([s[i]])
        l = [s[i]]
        for j in range(1, 5):
            if i + j == len(s):
                break
            l = l + [s[i + j]]
            if not l in v:
                v.append(l)
for i in range(len(v)):
    v[i] = "".join(v[i])
v.sort()
print(v[k - 1])
print(v)

Submission status: Wrong Answer

Solution code:
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    s = input().rstrip()
    K = int(input())
    a = sorted(set(s))
    res = set()
    n = len(s)
    for i in a:
        res.add(i)
        if len(res)>K:
            res = sorted(res)
            print(res[K-1])
            exit()
        for j in range(n):
            if s[j] == i:
                for k in range(1, 5):
                    res.add(s[j:j+k+1])




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

substring = []

for i in range(min(n, k)):
    for j in range(n-i):
        substring.append(s[j:j+i+1])
        print(s[j:j+i+1], j, j+i+1)

substring = list(set(substring))
substring.sort()
print(substring)
#substring.pop(0)

print(substring[k-1])

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
L=[""]
for s in range(len(S)):
    for e in range(s,len(S)):
        #print(S[s:e+1])
        if S[s:e+1] in L:
            continue
        if len(L)>K:
            if S[s:e+1]>L[K]:
                break
        if S[s:e+1] not in L:
            if len(L)<=K:
                L.append(S[s:e+1])
            else:
                L.append(S[s:e+1])
                L.sort()
                L=L[:K+1]
                #print(L)
print(L[-1])

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
L=[""]
for s in range(len(S)):
    for e in range(s,len(S)):
        #print(S[s:e+1])
        if len(L)>K:
            if S[s:e+1]>L[K]:
                break
        if S[s:e+1] not in L:
            if len(L)<=K:
                L.append(S[s:e+1])
            else:
                L.append(S[s:e+1])
                L.sort()
                L=L[:K+1]
                #print(L)
print(L[-1])

Submission status: Wrong Answer

Solution code:
cha = input()
num = int(input())
list = []
for i in range(len(cha)):
  for j in range(len(cha)-i):
    if list.count(cha[i:i+j+1])==0:
      list.append(cha[i:i+j+1])
list.sort()

print(list)
print(list[num-1])

Submission status: Wrong Answer

Solution code:
from itertools import product
s = input()
k = int(input())
anss = []
for bit in product(list(range(len(s)+1)), repeat=2):
    if bit[0] < bit[1] and s[bit[0]:bit[1]]:
        anss.append(s[bit[0]:bit[1]])

anss.sort()
tmp = 'test'
c = 1
for i in range(1, len(anss)):
    if c == k:
        print(anss[i])
        exit()
    else:
        if tmp != anss[i]:
            c += 1
        tmp = anss[i]
print(s)

Submission status: Wrong Answer

Solution code:
s = list(input())
l = int(input())
s1 = sorted(set(s))
ans = set()

for i in range(len(s1)):
    sta = s1[i]
    for j in range(len(s)):
        if s[j] == sta:
            ans.add(s[j])
            check = s[j]
            for k in range(j+1,min(len(s),j+5)):
                check = check+s[k]
                ans.add(check)
        if len(ans) >= l:
            ans1 = sorted(ans)
            print(ans1[l-1])
            exit()
ans1 = sorted(ans)
print(ans1[l-1])

Submission status: Wrong Answer

Solution code:
s = list(input())
l = int(input())
s1 = sorted(set(s))
ans = set()

for i in range(len(s)):
    sta = s1[i]
    for j in range(len(s)):
        if s[j] == sta:
            ans.add(s[j])
            check = s[j]
            for k in range(j+1,min(len(s),j+5)):
                check = check+s[k]
                ans.add(check)
        if len(ans) >= l:
            ans1 = sorted(ans)
            print(ans1[l-1])
            exit()
ans1 = sorted(ans)
print(ans1[l-1])

Submission status: Wrong Answer

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

dct = []
for i in range(len(s)):
    for j in range(k+1):
        word = s[i:i+j]
        if word not in dct:
            dct.append(word)
dct.sort()

for d in dct:
    print(d)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
candidate = []
for i in range(len(s)):
    for j in range(k+1):
        candidate.append(s[i:i+j])
for i in range(len(candidate)):
    candidate[i] = "".join(candidate[i])
candidate = list(set(candidate))
def sort_key(x):
    while len(x) < 5:
        x += "a"
    return x
candidate.sort(key = sort_key)
print(candidate[k])

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 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 main():
    s = S()
    k = I()
    seen = set()
    h = []
    for i in range(len(s)):
        curS = s[i]
        if curS not in seen:
            heapq.heappush(h, curS)
            seen.add(curS)
        for j in range(i+1, len(s)):
            curS += s[j]
            if curS not in seen:
                heapq.heappush(h, curS)
                seen.add(curS)
    print(heapq.nsmallest(5, h)[-1])

main()

Submission status: Wrong Answer

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

n = len(s)
strs = set([])
strs_add = strs.add
for i in range(n):
    for j in range(i+1, n+1):
        strs_add(s[i:j])
strs = list(strs)
#strs.sort()
print(strs[k-1])

Submission status: Wrong Answer

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

n = len(s)
strs = set([])

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

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)
k = int(input())
substring_list = []
sappend = substring_list.append
if len_s < 5:
    for i in range(len_s):
        for j in range(i,len_s):
            sappend(s[i:j+1])
else:
    s_sorted_id = [(v,i) for i,v in enumerate(s)]
    s_sorted_id.sort()
    for i in range(5):
        start_idx = s_sorted_id[i][1]
        for j in range(5):
            sappend(s[start_idx:min(start_idx+1+j,len_s)])
substring_set = set(substring_list)
print(sorted(substring_set)[k-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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



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

print(rank[-1])

Submission status: Wrong Answer

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

if len(s) == 1:
    print(s)
    import sys
    sys.exit()

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

print(rank[-1])

Submission status: Wrong Answer

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

if len(s) == 1:
    print(s)
    import sys
    sys.exit()

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

print(rank[-1])

Submission status: Wrong Answer

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

if len(s) == 1:
    print(s)
    import sys
    sys.exit()

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

print(rank[-1])

Submission status: Wrong Answer

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

if len(s) == 1:
    print(s)
    import sys
    sys.exit()

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

print(rank[-1])

Submission status: Wrong Answer

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

if len(s) == 1:
    print(s)
    import sys
    sys.exit()
    
rank = []
for i in range(len(s)):
    for j in range(i+1, len(s)):
        ss = s[i:j]
        if ss not in rank:
            if len(rank) < k:
                rank.append(ss)
                break
            else:
                if ss < rank[-1]:
                    rank.pop()
                    rank.append(ss)
                    rank = sorted(rank)

print(rank[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
keys = sorted(list(set(list(S))))
c = 0
l = 2
ans = []
for key in keys:
  ans.append(key)
  while l <= len(S):
    for i, s in enumerate(S):
      if i + l >= len(S):
        l += 1
        break
      elif s[0] == key:
        ans.append(S[i:i+l])
    ans = sorted(list(set(ans)))
  else:
    l = 2
  if len(ans) > K:
    print(ans[K-1])
    exit()

Submission status: Wrong Answer

Solution code:
s=input()
K=int(input())
L=list(s)
S=sorted(set(L))
A=[]

for _ in range(min(3,len(S))):
    H=S[_]
    A.append(H)
    HN=[]
    for i in range(len(L)):
        if L[i]==H:
            HN.append(i)
    for i in HN:
        t=2
        while i+t<len(s)+1 and t<6:
            A.append(''.join(L[i:i+t]))
            t+=1

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

Submission status: Wrong Answer

Solution code:
s=input()
K=int(input())
L=list(s)
S=sorted(set(L))
A=[]

for _ in range(min(3,len(S))):
    H=S[_]
    A.append(H)
    HN=[]
    for i in range(len(L)):
        if L[i]==H:
            HN.append(i)
    for i in HN:
        t=2
        while i+t<len(s)+1 and t<6:
            A.append(''.join(L[i:i+t]))
            t+=1

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
l=[]
for i in range(n):
    curr=''
    for j in range(i,min(i+10,n)):
        curr+=s[j]
        l.append(curr)
l.sort()
#print(l)
print(l[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
l=[]
for i in range(n):
    curr=''
    for j in range(i,n):
        curr+=s[j]
        l.append(curr)
l.sort()
#print(l)
print(l[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
import heapq 
h=[]
heapq.heapify(h)
l=[]
from bisect import bisect_left as bl 
for i in range(n):
    curr=''
    for j in range(i,n): 
        curr+=s[j]
        if not l or len(l)<=k or (curr<l[-1] and curr not in l):
            ind=bl(l,curr)
            l.insert(ind,curr) 
            if len(l)>k:
                l.pop()
#print(l)
print(l[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
import heapq 
h=[]
heapq.heapify(h)
l=[]
from bisect import bisect_left as bl 
for i in range(n):
    curr=''
    for j in range(i,n): 
        curr+=s[j]
        if not l or len(l)<=k or (curr<l[-1] and curr not in l):
            ind=bl(l,curr)
            l.insert(ind,curr) 
            if len(l)>k+1:
                l.pop()
#print(l)
print(l[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
k=int(input())
lst=list(s)
lst.sort()
ans=[]
for i in range(min(k,n)):
    a=lst[i]
    count=0
    for j in range(n):
        if s[j]==a:
            count+=1
            for l in range(min(5,n-j)):
                ans.append(s[j:j+l+1])
        if count>=5:
            break
    else:
        continue
    break
ans.sort()
t=1
while t<len(ans):
    if ans[t]==ans[t-1]:
        ans.pop(t)
    else:
        t+=1
print(ans[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
k=int(input())
lst=list(s)
lst.sort()
ans=[]
for i in range(min(k,n)):
    a=lst[i]
    for j in range(n):
        if s[j]==a:
            for l in range(min(5,n-j)):
                ans.append(s[j:j+l+1])
            if n-j>5:
                break
    else:
        continue
    break
ans.sort()
t=1
while t<len(ans):
    if ans[t]==ans[t-1]:
        ans.pop(t)
    else:
        t+=1
print(ans[k-1])

Submission status: Wrong Answer

Solution code:
#ABC097  C
s = input()
k = int(input())

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dic={}
for i in range(len(s)):
    dic[s[i]]=1
    
dic=sorted(dic,key=lambda x:x[0])
check=0
se=set()
for i in dic:
    for j in range(len(s)):
        if s[j]!=i:
            continue
        k=j+1
        se.add(i)
        sss=i
        while k<len(s):
            sss+=s[k]
            if sss in se:
                break
            se.add(sss)
            k+=1
    if len(se)>=kk:
        break
se=sorted(list(se))
print(se[kk-1])

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
substring = []

for i in range(n):
    if len(substring) == k:
        substring.sort()
    if len(substring) > k  and substring[k - 1][0] > s[i]:
        break
    tmp = ""
    for l in s[i::]:
        tmp += l
        if tmp in substring:
            continue

        else:
            substring.append(tmp)

substring.sort()

print(substring[k - 1])

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
substring = []

for i in range(n):
    if len(substring) > k - 1 and substring[k - 1][0] > s[i]:
        break
    tmp = ""
    for l in s[i::]:
        tmp += l
        if tmp in substring:
            continue

        else:
            substring.append(tmp)

substring.sort()

print(substring[k - 1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
word=[]
for i in range(len(s)):word.append(s[i:])
word=sorted(word)
for i in word:
    if len(i)>=k:
        print(i[:k])
        exit()
    else:
        k -=len(i)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
ans = "zzzzz"
anslist = set()
for i in range(0,5):
    for j in range(0,5):
        if i < j <= len(s):
            if i != 0:
                anslist.add(s[-j:-i])
            else:
                anslist.add(s[-j:])
for i in range(len(s)-5):
    if s[i:i+5] < ans:
        ans = s[i:i+5]
for i in range(1, 6):
    anslist.add(ans[0:i])
anslist = list(anslist)
anslist.sort()
print(anslist[n-1])
print(anslist)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
ans = "zzzzz"
anslist = set()
for i in range(0,5):
    for j in range(0,5):
        if i < j <= len(s):
            anslist.add(s[-j:-i])
for i in range(len(s)-5):
    if s[i:i+5] < ans:
        ans = s[i:i+5]
for i in range(1, 6):
    anslist.add(ans[0:i])
anslist = list(anslist)
anslist.sort()
if "" in anslist:
    anslist.remove("")
print(anslist[n-1])

Submission status: Wrong Answer

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

s_sub = list([''])
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])

s_sub.sort()

sum = 0
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
            
    sum += len(current) - z
    if sum >= K:
        print(current[:K-sum+z])
        break

Submission status: Wrong Answer

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

s_sub = list()
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])
    
s_sub.sort()
s_sub.append('')

pre_sum = 0
sum = len(s_sub[0])
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    z = 0
    if sum >= K:
        print(before[:K-pre_sum+z])
        break

    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
    pre_sum =  sum 
    sum += len(current) - z

Submission status: Wrong Answer

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

s_sub = list()
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])
    
s_sub.sort()
s_sub.append('')

pre_sum = 0
sum = len(s_sub[0])
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    if sum >= K:
        print(before[:K-pre_sum])
        break

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
    pre_sum =  sum 
    sum += len(current) - z

Submission status: Wrong Answer

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

    s_l = sorted(set(s))
    ans = set()
    for i in s_l:
        ans.add(i)
        if len(ans) == K:
            print(i)
            break
        cur = ""
        for j in range(len(s)):
            if s[j] == i:
                tmp = s[j:min(j+5,len(s))]
                if not cur or cur in tmp or (not cur in tmp and tmp < cur):
                    cur = tmp
        for j in range(len(cur)):
            ans.add(cur[:j+1])
            if len(ans) == K:
                print(cur[:j+1])
                break
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    K = int(inputs[1])

    sets = set()
    print(K)
    for i in range(len(S)):
        j = i
        while j < len(S) and j - i <= K:
            j += 1
        sets.add(S[i:j])
    new_sets = set()

    for k in sets:
        for i in range(len(k)):
            j = i
            while j < len(k) and j - i <= K:
                j += 1
                new_sets.add(k[i:j])
    l = list(new_sets)
    l.sort()
    return l[K-1]


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
lst=[]
cnt=0
r=sorted(s)
for idx in range(min(5,len(s))):
  for i in range(1,len(s)-(s.index(r[idx]))+1):
    lst.append(''.join(s[s.index(r[idx]):(s.index(r[idx]))+i]))
    cnt+=1
    if cnt==5:
      break
  if cnt==5:
    break
lst.sort()
print(lst[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
lst=[]
cnt=0
r=sorted(s)
for idx in range(min(5,len(s))):
  for i in range(len(s)-(s.index(r[idx]))+1):
    lst.append(''.join(s[s.index(r[idx]):(s.index(r[idx]))+i]))
    cnt+=1
    if cnt==5:
      break
  if cnt==5:
    break
lst.sort()
print(lst[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
def getChar(n,t):
  CharGram=[''.join(t[i:i+n]) for i in range(len(t)-n+1)]
  return CharGram
lst=[]
cnt=0
for i in range(1,len(s)+1):
  Lst=getChar(i,s)
  for j in range(len(Lst)):
    lst.append(Lst[j])
    cnt+=1
    if cnt==5:
      break
  if cnt==5:
    break
lst.sort()
print(lst[k-1])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
def getChar(n,t):
  CharGram=[''.join(t[i:i+n]) for i in range(len(t)-n+1)]
  return CharGram
lst=[]
for i in range(1,len(s)+1):
  Lst=getChar(i,s)
  for j in range(len(Lst)):
    lst.append(Lst[j])
lst.sort()
print(lst[k-1])

Submission status: Wrong Answer

Solution code:

# https://atcoder.jp/contests/abc097/tasks/arc097_a
# C - K-th Substring

s = input().split()[0]
K = int(input().split()[0])

sub_s_list = []
N = len(s)
sorted_char_list = sorted(list(set(s)))
char_N = len(sorted_char_list)

# Kは最大で5であることに着目する
# 全部列挙する必要はなく、5番目まで見つかればよい
# 最初の1文字目
start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
pattern = sorted_char_list[0]
sorted_char_list.remove(pattern)
char_i = 0
j = 1

waiting_list = []

while len(sub_s_list) < 5:
    sub_s_len = len(pattern)
    sub_s_list.append(pattern)
    next_list = [s[i:i+sub_s_len+2] for i in start_index_list
                if (i <= N - sub_s_len - 1) and (s[i:sub_s_len+1] == pattern)]

    if not next_list:
        if min(start_index_list) + sub_s_len > N:
            # 末尾まで伸びた
            if waiting_list:
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
        else:
            # 末尾まで伸ばす
            next_waiting_list =  [s[i:i+sub_s_len+1] for i in start_index_list
                                    if (i <= N - (sub_s_len + 1))]
            waiting_list += next_waiting_list
            waiting_list = list(set(waiting_list))

            if waiting_list:
                waiting_list = sorted(waiting_list)
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
    else:
        waiting_list += next_list
        waiting_list = sorted(list(set(waiting_list)))
        pattern = waiting_list[0]
        waiting_list.remove(pattern)

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

Submission status: Wrong Answer

Solution code:

# https://atcoder.jp/contests/abc097/tasks/arc097_a
# C - K-th Substring

s = input().split()[0]
K = int(input().split()[0])

sub_s_list = []
N = len(s)
sorted_char_list = sorted(list(set(s)))
char_N = len(sorted_char_list)

# Kは最大で5であることに着目する
# 全部列挙する必要はなく、5番目まで見つかればよい
# 最初の1文字目
start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
pattern = sorted_char_list[0]
sorted_char_list.remove(pattern)
char_i = 0
j = 1

waiting_list = []

while len(sub_s_list) < 5:
    sub_s_len = len(pattern)
    sub_s_list.append(pattern)
    next_list = [s[i:i+sub_s_len+2] for i in start_index_list
                if (i <= N - sub_s_len - 1) and (s[i:sub_s_len+1] == pattern)]

    if not next_list:
        if min(start_index_list) + sub_s_len > N:
            # 末尾まで伸びた
            if waiting_list:
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
        else:
            # 末尾まで伸ばす
            next_waiting_list =  [s[i:i+sub_s_len+1] for i in start_index_list
                                    if (i <= N - (sub_s_len + 1))]
            waiting_list += list(set(next_waiting_list))

            if waiting_list:
                waiting_list = sorted(waiting_list)
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
    else:
        sub_s_list += list(set(next_list))
        waiting_list += sorted(list(set(next_list)))
        pattern = waiting_list[0]
        waiting_list.remove(pattern)

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

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    K = int(input())
    ind = []
    for i in range(len(s)):
        for j in range(i+1, min(len(s)+1, i+6)):
            ind.append(s[i:j])
    ind = sorted(list(ind))
    print(ind[K-1])

if __name__ == "__main__":
    main()