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()
n=int(input())

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	#print(res)
	if len(res[0])==n:
		print(res[0])
		chk=1    
	for i in range(1,n-1): 
		if chk==0 and len(res[i])==n:
			print(res[i][0:n-i])
			chk=1
			break
	if chk==0 and len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res)
	if len(res[0])==n:
		print(res[0])
		chk=1    
	for i in range(1,n-1): 
		if chk==0 and len(res[i])==n:
			print(res[i][0:n-i])
			chk=1
			break
	if chk==0 and len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	#print(res)
	if len(res[0])==n:
		print(res[0])
		chk=1    
	for i in range(1,n-1): 
		if chk==0 and len(res[i])==n:
			print(res[i][0:i+1])
			chk=1
			break
	if chk==0 and len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	#print(res)
	for i in range(n-1): 
		if len(res[i])==n:
			print(res[i][0:i+1])
			chk=1
			break
	if chk==0 and len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	for i in range(n-1): 
		if len(res[i])==n:
			print(res[i][0:(n-i)])
			chk=1
			break
	if chk==0 and len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	for i in range(n-1): 
		if len(res[i])==n:
			print(res[i][0:(n-i)])
			chk=1
			break
	if len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res)    
	for i in range(n-1): 
		if len(res[i])==n:
			print(res[i][0:(n-i)])
			chk=1
			break
	if len(res[n-1])==n:
		if res[n-1]!=s[(s_n-n):s_n]:
			print(res[n-1][0])
			chk=1
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')
chk=0

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	for i in range(n): 
		if len(res[i])==n:
			print(res[i][0:(n-i)])
			chk=1
			break
	if chk==0:
		print(res[n-1])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	if len(res[0])==n:
		print(res[0])
	else:
		if len(res[n-1])<n:
 			print(res[n-1])
		else:
			print(res[n-1][0])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res)
	if len(res[0])==n:
		print(res[0])
	else:
		if len(res[n-1])<n:
 			print(res[n-1])
		else:
			print(res[n-1][0])

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
heads = []
d = set()
for c in s:
    d.add(c)

for key in d:
    heads.append(key)

heads.sort()
ind = 0
ans = []
while True:
    if ind > len(heads)-1:
        break
    head = heads[ind]
    p = set()
    for i in range(len(s)):
        if s[i] == head:
            p.add(i)
    # print(head)
    ext = 0
    while True:
        flag = False
        dis = -1
        for key in p:
            if key+ext > n-1:
                flag = True
                dis = key
        if flag:
            p.discard(dis)
            # print(ext)
            # print(p)
        if not p:
            break
        for key in p:
            temp = s[key]
            for j in range(1,ext+1):
                temp += s[key+j]
            # print(temp)
            if temp not in ans:
                ans.append(temp)
        ext += 1
        if len(ans) >= 100:
            break
    if len(ans) >= 100:
        break
    else:
        ind += 1

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

# for i in range(len(s)):
#     if

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
heads = []
d = set()
for c in s:
    d.add(c)

for key in d:
    heads.append(key)

heads.sort()
ind = 0
ans = []
while True:
    if ind > len(heads)-1:
        break
    head = heads[ind]
    p = set()
    for i in range(len(s)):
        if s[i] == head:
            p.add(i)
    # print(head)
    ext = 0
    while True:
        flag = False
        dis = -1
        for key in p:
            if key+ext > n-1:
                flag = True
                dis = key
        if flag:
            p.discard(dis)
            # print(ext)
            # print(p)
        if not p:
            break
        for key in p:
            temp = s[key]
            for j in range(1,ext+1):
                temp += s[key+j]
            # print(temp)
            if temp not in ans:
                ans.append(temp)
        ext += 1
        if len(ans) >= 50:
            break
    if len(ans) >= 50:
        break
    else:
        ind += 1

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

# for i in range(len(s)):
#     if

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]
s=str(s+'z')

if n>=s_n:
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	for i in range(s_n-n,s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[0])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]

if n>=s_n:
	s=str(s+'z')
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n+1):
		j=i+n
		s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[0])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]

if n>=s_n:
	s=str(s+'z')
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n):
		j=i+n
		s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[0])

Submission status: Wrong Answer

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

s_n=len(s)
s_s=[]

if n>=s_n:
	s=str(s+'z')
	for i in range(s_n):
		for j in range(i+1,s_n+1):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[n-1])
else:
	for i in range(s_n-n):
		for j in range(i+n,s_n):
			s_s.append(s[i:j])
	res=list(sorted(set(s_s)))
	print(res[0])

Submission status: Wrong Answer

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

#時間計測テスト

s = str(input())
K = I()
n = len(s)

a = []
for i in range(n):
    for j in range(i+1,n+1):
        a.append(s[i:j])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=list(input())
words=[]
for i in range(len(s)):words.append("".join(s[i:]))
words=sorted(words)

record=[]
k=int(input())
for i in words:
    if len(words)>=k:
        print("".join(i[:k]))
        exit()
    else:
       for j in range(len(i)):
           if "".join(i[:j+1]) not in record:
               record.append("".join(i[:j+1]))
print(record[k-1])

Submission status: Wrong Answer

Solution code:
#辞書順で小さい文字から考えていく。まずｓ内を構成する文字で辞書順で小さいものを列挙。
#辞書順降順でその文字から始まる部分文字列を全列挙。その数がｋに達したら打ち切り。
s = input()
k = int(input())
substr = set()
for i in range(len(s)):
    substr.add(s[i])
check = sorted(list(substr))
x = 0
while len(substr) < k:
    for i in range(len(s)):
        if s[i] == check[x] and i < len(s) - 1:
            print(x,i)
            for j in range(i+1,len(s)+1):
                substr.add(s[i:j])
    x += 1
lis_substr = sorted(list(substr))
print(lis_substr[k-1])

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in sorted(d.copy().items()):
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.keys())
        print(str(d[k-1][0]).replace(" ", ""))
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in sorted(d.copy().items()):
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.items())
        print(str(d[k-1][0]).replace(" ", ""))
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in sorted(d.copy().items()):
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.items())
        print(str(d[k-1][0]))
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in sorted(d.copy().items()):
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.items())
        print(d[k-1][0])
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in d.copy().items():
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.items())
        print(d[k-1][0])
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in d.copy().items():
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, i + 10):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.items())
        print(d)
        print(d[k-1][0])
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in d.copy().items():
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, len(s) + 1):
                d[s[i:j]] += [1]
    if len(d) >= k:
        d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
        d = list(d.items())
        print(d[k-1][0])
        exit()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
k = int(input())
d = collections.defaultdict(list)
for i in range(len(s)):
    d[s[i]] += [1]
for ke, v in d.copy().items():
    for i in range(len(s)):
        if s[i] == ke:
            for j in range(i + 1, len(s) + 1):
                d[s[i:j]] += [1]
    d = collections.defaultdict(list, dict(sorted(d.items(), key=lambda x: x[0])))
    if len(d) >= k:
        d = list(d.items())
        print(d[k-1][0])
        exit()

Submission status: Wrong Answer

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

    S = set()

    for i in range(len(s)):
        for j in range(1, K+1):
            print(s[i:i+j])
            S.add(s[i:i+j])
    
    sort_S = sorted(list(S))

    print(sort_S[K-1])
main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    s = input()
    K = inputInt()
    
    d = []
    for i in range(len(s)+1):
        for j in range(i, K+1):
            tmp = s[i:j+1]
            if not(tmp in d):
                d.append(tmp)
            
    d = d[0:-1]
    #d.sort(key=len)
    d.sort()
    
    #print(d)
    print(d[K-1])
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

    S1 = {}
    for i, s in enumerate(S):
        if not s in S1.keys():
            S1[s] = [i]
        else:
            S1[s].append(i)
    alp = sorted(list(S1.keys()))

    c = 0
    for a in alp:
        aset = set()
        inds = S1[a]
        for d in inds:
            up = min(N-d+1, 5)
            for i in range(up):
                aset.add(S[d:d+i])
        L = len(aset)-1
        if L >= K-c:
            break
        c += L

    for _ in range(10):
        M = '何だこれはもうやめてくれよ'
        for a in aset:
            if a < M:
                M = a
        aset.discard(M)
        if M == '':
            continue
        c += 1
        if c >= K:
            ans = M
            break

    print(ans)



if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

S1 = {}
for i, s in enumerate(S):
    if not s in S1.keys():
        S1[s] = [i]
    else:
        S1[s].append(i)
alp = sorted(list(S1.keys()))

c = 0
for a in alp:
    aset = set()
    inds = S1[a]
    for d in inds:
        for i in range(N-d+1):
            aset.add(S[d:d+i])
    if len(aset)-1 > K-c:
        break
    c += len(aset)-1


while True:
    for i, a in enumerate(aset):
        if i == 0:
            min = a
            continue
        if a < min:
            min = a
    aset.discard(min)
    if min == '':
        continue
    c += 1
    if c >= K:
        ans = min
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def insertTo(arr, t, k):
    for x in arr:
        if x == t:
            return
    if len(arr) < k:
        arr.append(t)
    elif arr[k-1] > t:
        arr.pop()
        arr.append(t)
        arr.sort()

s = raw_input()
k = int(raw_input())
arr = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        t = s[i:j]
        insertTo(arr, t, k)
print arr[k-1]

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=[]
for i in range(min(len(s),k)):
    for j in range(i+1,min(len(s),k)+1):
        ans.append(s[i:j])
ans.sort()
a=[ans[0]]
for i in range(1,len(ans)):
    if ans[i-1]!=ans[i]:
        a.append(ans[i])
print(a[k-1])

Submission status: Wrong Answer

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

for i in range(len(s)):
    x = s[i:]
    for j in range(len(x)):
        d.add(x[:j+1])
        if len(d) == k:
            print(sorted(d)[k-1])
            break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	s = input()
	K = int(input())
	
	d = []
	for i in range(len(s)+1):
		for j in range(i, len(s)+1):
			tmp = s[i:j+1]
			if not(tmp in d):
				d.append(tmp)
				
	d = d[0:-1]
	d.sort(key=len)
	
	#print(d)
	print(d[-K])
	
			
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	s = input()
	K = int(input())
	
	d = []
	for i in range(len(s)+1):
		for j in range(i, len(s)+1):
			tmp = s[i:j+1]
			if not(tmp in d):
				d.append(tmp)
				
	d = d[0:-1]
	d.sort(key=len)
	
	print(d)
	print(d[-K])
	
			
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
us=[]
for i in s:
  if i not in us:
    us.append(i)
us.sort()
l=len(us)
cnt=0
for i in range(l+1):
  ans=""
  if i==0:
    pass
  ans+=us[i-1]
  for j in range(l+1):
    if j==0:
      pass
    ans+=us[j-1]
    for h in range(l+1):
      if h==0:
        pass
      ans+=us[h-1]
      for m in range(l+1):
        if m==0:
          pass
        ans+=us[m-1]
        for n in range(l+1):
          if n==0:
            pass
          ans+=us[n-1]
          if ans in s:
            cnt+=1
          if cnt==k:
            print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# K-th Substring
S = input()
# 5000
K = int(input())
# K < 5

s = []
for i in range(len(S)):
    for k in range(K):
        s.append(S[i:i+k])

print(sorted(set(s))[K-1])

Submission status: Wrong Answer

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  k=I()

  _s=sorted(s)

  l=[]
  l.append('zzzzzzzzzzzzzzzzzzzz')
  l.append('zzzzzzzzzzzzzzzzzzzzz')

  for i in range(3):
    for j in range(len(s)):
      if len(s)>i and _s[i]==s[j]:
        l.append(s[j])

        if len(s)-j>=2:
          l.append(s[j:j+2])

        if len(s)-j>=3:
          l.append(s[j:j+3])

        if len(s)-j>=4:
          l.append(s[j:j+4])

        if len(s)-j>=5:
          l.append(s[j:j+5])

  l=list(set(l))
  l.sort()

  return l[k-1]

print(main())

Submission status: Wrong Answer

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  k=I()

  _s=sorted(s)

  l=[]
  l.append('zzzzzzzzzzzzzzzzzzzz')
  l.append('zzzzzzzzzzzzzzzzzzzzz')

  for i in range(3):
    for j in range(len(s)):
      if len(s)>i and _s[i]==s[j]:
        l.append(s[j])

        if len(s)-j>=2:
          l.append(s[j:j+2])

        if len(s)-j>=3:
          l.append(s[j:j+3])

        if len(s)-j>=4:
          l.append(s[j:j+4])

        if len(s)-j>=5:
          print('aaa')
          l.append(s[j:j+5])

  l=list(set(l))
  l.sort()

  return l[k-1]

print(main())

Submission status: Wrong Answer

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  k=I()

  _s=sorted(s)

  l=[]
  l.append('zzzzzzzzzzzzzzzzzzzz')
  l.append('zzzzzzzzzzzzzzzzzzzzz')

  for i in range(3):
    for j in range(len(s)):
      if len(s)>i and _s[i]==s[j]:
        l.append(s[j])

        if len(s)-j>=2:
          l.append(s[j:j+2])

        if len(s)-j>=3:
          l.append(s[j:j+3])

        if len(s)-j>=4:
          l.append(s[j:j+4])

        if len(s)-j>=5:
          print('aaa')
          l.append(s[j:j+5])

  l=list(set(l))
  l.sort()

  print(l)

  return l[k-1]

print(main())

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
ans = []
for l in range(len(s)):
    for r in range(1, K + 1):
        ans.append(s[l:r])
        
print(sorted(set(ans))[K - 1])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
ans = []
for l in range(len(s)):
    for r in range(l + 1, K + 1):
        ans.append(s[l:r])
        
print(sorted(set(ans))[K - 1])

Submission status: Wrong Answer

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


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


def main():
    s = input()
    k = intin()

    nlist = [(ord(c), i) for i, c in enumerate(s)]
    nlist.sort()

    prev_oc = None
    slist = []

    for oc, i in nlist:
        for j in range(min(k, len(s) - i)):
            slist.append(s[i:(i+j+1)])
        slist = list(set(slist))
        kcount = len(slist)
        if prev_oc is not None and oc != prev_oc and kcount >= k:
            break
        prev_oc = oc

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

if __name__ == '__main__':
    main()