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: Runtime Error

Solution code:
s = input()
N = int(input())
l = len(s)
li=list(set(s))
li.sort()
result=[]
print(li)
if len(li)>5:
    a=5
else:
    a=l-1
for i in range(a):
    index=s.index(li[i])
    for scope in range(1,l+1):
        if not s[index:index+l-scope+1] in result:
            result.append(s[index:index+l-scope+1])
print(result)
result.sort()
print(result[N-1])

Submission status: Runtime Error

Solution code:
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
    if len(li)==N:
      break
li.sort()   
print(li[N-1])

Submission status: Runtime Error

Solution code:
s=input()
N=int(input())
l=len(s)
li=[]
for scope in range(1,l+1):
  for first in range(l-scope+1):
    if not s[first:first+scope]:
      li.append(s[first:first+scope])
li.sort()
print(li[N-1])

Submission status: Runtime Error

Solution code:
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
li.sort()   
print(li[N-1])

Submission status: Runtime Error

Solution code:
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
li.sort()   
print(li[N])

Submission status: Runtime Error

Solution code:
s=input()
l=len(s)
N=int(input())
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
print(li[-N])

Submission status: Runtime Error

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

substr = []
for i in range(len(str)):
  substr.extend([str[i:j] for j in range(i+1,len(str) + 1)])

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

Submission status: Runtime Error

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

result = []

for i in range(len(s)):	#抜き取る文字の個数
	for j in range(len(s)):	#位置
		if i+j>len(s):
			break
		if s[j:j+i] not in result:
			result.append(s[j:j+i])

result.sort()
		
print(result[K])

Submission status: Runtime Error

Solution code:
import re

str = input()
k = int(input())

strl = list(set([c for c in str]))
strl.sort()

substring = []
for h in strl:
	compiled = re.compile(h)

	i = 0
	while i >= 0:
		m = compiled.search(str, i)
		if m:
			sub = m.start()
			for i in range(sub, len(str)):
				t = str[sub:i+1]
				if(not (t in substring)):
					substring.append(t)
			substring.sort()
			if(len(substring)-len(strl) >= k-1):
				break
			i = sub + 1
		else:
			break
	else:
		continue
	break


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

Submission status: Runtime Error

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

strl = []
for c in str:
    if(not (c in strl)):
        strl.append(c)
strl.sort()

substring = []
for h in strl:
	sub = str.find(h)
	for i in range(sub, len(str)-1):
		t = str[sub:i+1]
		if(not (t in substring)):
			substring.append(t)
		# substring.sort()
		# if(substring[k-1] is str[sub:i+1]):
			# break
	# else:
		# continue
	# break


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

Submission status: Runtime Error

Solution code:
s=input().strip()
k=int(input())
A=[]
for i in range(len(s)):
  for j in range(1,6):
    if i+j<=len(s):
      A.append(s[i:i+j])
B=sorted(list(set(A)))
print(B[k])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
st = set()
for i in range(len(s)):
    for j in range(min(k, len(s)-i)):
        st.add(s[i:i+j])
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
st = set()
for i in range(len(s)):
    for j in range(min(k, len(s)-i))
        st.add(s[i:i+j])
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
st = set()
for i in range(len(s)):
    for j in range(min(k, len(s)-i+1))
        st.add(s[i:i+j])
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))

Submission status: Runtime Error

Solution code:
import heapq

s=input()
k=int(input())
n=len(s)
ans=set()

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

ans.remove('')

ansh=[]
for ss in ans:
    heapq.heappush(ansh,ss)
    

for _ in range(k-1):
    heapq.heappop(ansh)
print(ansh[0])

Submission status: Runtime Error

Solution code:
s = str(input())
K = int(input())
n = len(s)
l = []
for b in range(1, K+1) :
    for i in range(1,n) :
        if( i+b-1 <= n ) :
            l.append(s[i:(i+b-1)])
l.sort()
print("{}".format(l[K+1]))

Submission status: Runtime Error

Solution code:
s = str(input())
K = int(input())
n = len(s)
l = []
for i in range(1,n) :
    for b in range(1, K+1) :
        if( i+b-1 <= n ) :
            l.append(s[i:(i+b-1)])
l.sort()
print("{}".format(l[K-1]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input().strip()
K=int(input())
st=set()
for i in range(len(s)-1):
    for k in range(i+1,min(len(s),i+K+1)):
        st.add(s[i:k])
print(sorted(st)[K-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s = input()
K = int(input())


def substring(s, K):
    substrings = []
    length = len(s)
    for i in range(length):
        for j in range(K+1):
            if i + j >= length:
                break
            substrings.append(s[i:i + j])
    unique_substrings = list(set(substrings))
    unique_substrings.sort()
    return substrings[K]


print(substring(s, K))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s = input()
K = int(input())


def substring(s, K):
    substrings = []
    length = len(s)
    for i in range(length):
        for j in range(K+1):
            if i + j >= length:
                break
            substrings.append(s[i:i+j])
    return substrings[K]


print(substring(s, K))

Submission status: Runtime Error

Solution code:
from math import log, floor
x = int(input())
ans = 1
for b in range(2, x):
    p = floor(log(x,b))
    if p <= 1: continue
    tmp = b**p
    tmp2 = b**(p+1)
    if tmp2 <= x:
        tmp = tmp2
    ans = max(ans, tmp)

print(ans)

Submission status: Runtime Error

Solution code:
def substring():
    sub = []
    words = input()
    num = int(input())
    for i in range(len(words)):
        for j in range(len(words)):
            word = words[i:j+1]
            if word not in sub:
                sub.append(word)
    sub.sort()
    del sub[0]
    print(sub[num-1])
    
if __name__ == '__main__':
    substring()

Submission status: Runtime Error

Solution code:

from functools import cmp_to_key
s = input()
K = int(input())
 
e = set([])
 
def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1
    
def substring_sort(a,b):
    if len(a) != len(b):
        return cmp(len(a), len(b))
    else:
        return cmp(a,b)
 
for i in range(1,5):
    for j in range(len(s)):
    #     if len(e) < 5:
    #         e.add(s[j:j+i])
    #     if len(e) == 5:
    #         break
    # else:
    #     continue
    # break
        e.add(s[j:j+i])
# print(e)
# result = sorted(e,key=cmp_to_key(substring_sort),reverse=True)
result = sorted(e)
# print(result)
print(result[K-1])

Submission status: Runtime Error

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

sub = []
a = 0

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

print(sorted(sorted(list(set(sub)), reverse=True), key=lambda x: len(x), reverse=True)[k - 1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
L = len(s)
cand = []

if L > 5:
    c = []
    order = sorted(list(s))
    for i in range(L):
        if order[i] in c:
            pass
        else:
            c.append(order[i])
            if len(c) == 3: #5:
                break
else:
    c = list(s)

for i in range(L):
    if s[i] in c:
        for j in range(i+1,min(i+K+1,L+1)):
            cand.append(s[i:j])
cand.sort()

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()
while True:
    if cand[i] == cand[i+1]:
        i+=1
        continue
    K-=1
    i+=1
    if K == 0:
        print(cand[i-1])
        break

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
L = len(s)
cand = []

if L > 5:
    c = []
    order = sorted(list(s))
    for i in range(L):
        if order[i] in c:
            pass
        else:
            c.append(order[i])
            if len(c) == 3; #5:
                break
else:
    c = list(s)

for i in range(L):
    if s[i] in c:
        for j in range(i+1,min(i+K+1,L+1)):
            cand.append(s[i:j])
cand.sort()

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()
while True:
    if cand[i] == cand[i+1]:
        i+=1
        continue
    K-=1
    i+=1
    if K == 0:
        print(cand[i-1])
        break

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
L = len(s)
cand = []

if L > 5:
    c = []
    order = sorted(list(s))
    for i in range(L):
        if order[i] in c:
            pass
        else:
            c.append(order[i])
            if len(c) == 5:
                break
else:
    c = list(s)

for i in range(L):
    if s[i] in c:
        for j in range(i+1,min(i+K+1,L+1)):
            cand.append(s[i:j])
cand.sort()

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()
while True:
    if cand[i] == cand[i+1]:
        i+=1
        continue
    K-=1
    i+=1
    if K == 0:
        print(cand[i-1])
        break

Submission status: Runtime Error

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

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()
while True:
    if cand[i] == cand[i+1]:
        i+=1
        continue
    K-=1
    i+=1
    if K == 0:
        print(cand[i-1])
        break

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
N = len(S)
tmp = []
lis = []
lis_uniq = []

for i in range(N):
    tmp = []
    for j in range(N-i):
        lis.append(str(S[j:i+j+1]))

    lis_uniq = list(set(lis_uniq))
    m = len(lis_uniq)
    if(m > K+1):break

#print(lis_uniq)
lis_uniq = sorted(lis_uniq)
lis_uniq = sorted(lis_uniq)
print(lis_uniq[K-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
def ss(s,k):
    M=len(s)
    sss=set()
    for i in range(M):
        for j in range(i+1,M+1):
            tmp = s[i:j]
            sss.update(tmp)
    l = list(sss)
    l.sort()
    #print(l)
    ret = l[k-1]
    return(ret)
 
res=ss(s,k)
print(res)

Submission status: Runtime Error

Solution code:
import math

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

n=0
z=[]
while(n<len(s)):
    x=[]
    for i in range(len(s)-n):
        x.append(s[i:i+n+1])
    y = sorted(list(set(x)))
    z += y[:5]
    n += 1
print(sorted(list(set(z)))[4])

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

s = ns()
k = ni()
ans = []

for i in range(len(s)):
    for j in range(1,len(s)+1):
        if j - i > 5:
            break
        ans.append(s[i:j])

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

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
a=[]
a = [s[i:j] for i in range(0,len(s)) for j in range(1,len(s)+1) if i != j]
a = set(a)
a.remove("")
a=sorted(a)
print(a[k-1])

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
a=[]
for i in range(0,len(s)):
    for j in range(1,len(s)+1):
        a.append(s[i:j])
num = a.count("")
for i in range(num):
    a.remove("")
a=set(a)
a=sorted(a)

print(a[k-1])

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
a=[]
a = [s[i:j] for i in range(0,len(s)) for j in range(1,len(s)+1) if i != j]
a=set(a)
a.remove("")
a=sorted(a)
print(a[k-1])

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min({6,k-i})):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np
 
e = list(input())
num =int(input())
 
 
alpha = list("abcdefghijklmnopqrstuvwxyz")
n = len(e)
a=[0]*(n+5)
#print(alpha)
for t in range(n) :
    for k in range(26):
        if alpha[k] == e[t]:
            a[t] = k
            break
#print(a)
 
ma = [-1]*5
mlen = 1
 
b= [1]*n
for k in range(n):
    b[k]= a[k]
ma[0] = np.argmin(b)
 
#print(ma[0],e[ma[0]])
 
for i in range(1,num):
#    print(b, ma[i-1], n, mlen)
    if ma[i-1] < (n-mlen):
        for k in range(n):
            b[k]= b[k] * 26 + a[k+mlen] 
        mlen += 1
    else:
        b[n-i]= 26 ** 5
        mlen = 1
 
    ma[i] = np.argmin(b)
 
#    for j in range(1,mlen+1):
#        print(e[ma[i]+j-1],end='')
#    print("")
 
for j in range(1,mlen+1):
    print(e[ma[num-1]+j-1],end='')
print("")

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
listS = list(s)
revS = sorted(set(listS))[0:5]
ans = []
for i in revS:
    if len(ans) >= 5:
        break
    n = listS.count(i)
    m = 0
    # 同じ文字の2文字目以降対応
    for j in range(n):
        if m + j >= len(listS):
            break

        m = listS[m + j:].index(i) + m + j
        for k in range(len(listS[m + j:m + j + K])):
            ans.append("".join(listS[m: m + k + 1]))

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

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min({5,k-i+1})):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min(5,k-i)):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min(5,k-i+1)):
    p.append(d[i:i+j+1])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

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


list_pair = []
i = 0
while i <= len(s):
    for j in range(i+1,len(s)+1):
        list_pair.append(s[i:j])
    i = i + 1

list_pair = list(set(list_pair))

abc = "abcdefghijklmnopqrstuvwxyz"
tmp = []

i = 0
j = 0
while len(tmp) < k + 1:
    for list_j in list_pair:

        if abc[i]==list_j[0]:
            tmp.append(list_j)

    i = i+1

tmp.sort()

print(tmp[k-1])










# if len(s)<=50:
#     list_pair.sort()
#     print(list_pair[k-1])
# else:
#     print(1)
    # tmp = copy.deepcopy(list_pair)
    # abc = "abcdefghijklmnopqrstuvwxyz"
    # i = 0
    # while len(tmp) < 100:
    #     for j in range(1,len(s)):
    #         if abc[i] == tmp[j][] :
    #     i = i + 1

Submission status: Runtime Error

Solution code:
# sliceを使って、k以下でforを回せば良い

s = str(input())
k = int(input())
kouho = [s]

for i in range(len(s)):
    for plus in range(k):
        st = s[i:i + k]
        kouho.append(st)
so = list(sorted(set(kouho)))
print(so[k-1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
listS = list(s)
revS = sorted(set(listS))[0:5]
ans = []
for i in revS:
    if len(ans) >= 5:
        break
    n = listS.count(i)
    m = 0
    # 同じ文字の2文字目以降対応
    for j in range(n):
        m = listS[m + j:].index(i) + m + j

        for k in range(0,len(listS[m:])):
            ans.append("".join(listS[m: m + k + 1]))

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

Submission status: Runtime Error

Solution code:
string = str(input())
n=int(input())
substringlist = [string]
for i in range(len(string)-1):
    for j in range(i+1,i+6):
        substringlist.append(string[i:j])

substringli=list(set(substringlist))

print(sorted(substringli)[n-1])

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min(5,k-i+1)):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  if i <= k-6:
    for j in range(5):
      if i + j + 1 <= k-1:
        p.append(d[i:i+j+1])
  else:
    for j in range(k - i):
      p.append(d[i:i+j+1])
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase
from collections import defaultdict

def larger(s, k):
    a = [[None] * len(s) for c in (ascii_lowercase)]
    l = len(s)
    d = defaultdict(set)
    for (i, c) in enumerate(s):
        for j in range(1, l - i + 1):
            d[c].add(s[i:i+j])
    count = 0
    for c in ascii_lowercase:
        if c in d:
            prev_count = count
            count += len(d[c])
            if count > k:
                break
    subs = sorted(list(d[c]))
    return subs[k - prev_count - 1]


if __name__ == '__main__':
    s = input()
    k = int(input())
    print(larger(s, k))

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
l=[]
for i in range(K):
    for n in range(5000):
        slice = s[n:n+i]
        if slice not in l:
            l.append(slice)
l.sort()
print(l[K])

Submission status: Runtime Error

Solution code:
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(5):
    if i + j + 1 <= k-1:
      p.append(d[i:i+j+1])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Submission status: Runtime Error

Solution code:
import sys
# a = [int(raw_input()) for i in xrange(n)]
# a,b,c,d = map(int, raw_input().split())

s = raw_input()
k = int(raw_input())

l = list(s)
d = list(set(l))

for i in xrange(len(l)):
    ss = l[i]
    for j in xrange(len(l)):
        if i >= j:
            continue
        ss += l[j]
        d.append(ss)
dd = sorted(list(set(d)))
print dd[k-1]
    
# print "".join(["a","b"])

# print "Yes" if 3 > 0 else "No"

Submission status: Runtime Error

Solution code:

s = list(input())
k = int(input())
ansnum = 0

for j in range(k):
    # listj = []
    # for i in range(len(s)-j):
    #     #print(s[i:i+j+1])
    #     listj.append(s[i:i+j+1])
    listj = [s[i:i + j + 1] for i in range(len(s) - j)]
    listj.sort()
    # print('listj:',listj)
    # print('j:',j)
    if len(listj) >= 2 and listj[0] == listj[1]:
        # print('choufuku')
        pass
    else:
        # j+1文字で重複なしの場合(j=0,1,2,3,4)
        s = ''.join(s)
        lens = len(s)
        for i in range(len(listj)):
            num = s.index(''.join(listj[i]))
            a = lens - num
            # print('index:',num)
            # print('ansnum:',ansnum)
            if a < k - ansnum:
                ansnum += a
            else:
                ans = s[num:num + k - ansnum]
                ansnum = k + 1
                break
#print('ans:',ans)
print(ans)

Submission status: Runtime Error

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

for j in range(k):
    # listj = []
    # for i in range(len(s)-j):
    #     #print(s[i:i+j+1])
    #     listj.append(s[i:i+j+1])
    listj = [s[i:i + j + 1] for i in range(len(s) - j)]
    listj.sort()
    # print('listj:',listj)
    # print('j:',j)
    if len(listj) >= 2 and listj[0] == listj[1]:
        # print('choufuku')
        pass
    else:
        # j+1文字で重複なしの場合(j=0,1,2,3,4)
        s = ''.join(s)
        lens = len(s)
        for i in range(len(listj)):
            num = s.index(''.join(listj[i]))
            a = lens - num
            # print('index:',num)
            # print('ansnum:',ansnum)
            if a < k - ansnum:
                ansnum += a
            else:
                ans = s[num:num + k - ansnum]
                ansnum = k + 1
                break
    if ansnum > k:
        break

#print('ans:',ans)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
flag = 0
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
  if len(d)==z:
    break
print(sorted(set(d))[z-1])

Submission status: Runtime Error

Solution code:
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
flag = 0
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  if len(indexes)==0:
    continue
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
  if len(d)==k:
    break
print(sorted(set(d))[z-1])

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
a=[]
for i in range(0,len(s)):
    for j in range(1,len(s)+1):
        if i != j and s[i:j] not in a:
            a.append(s[i:j])
a.remove("")
a=sorted(a)
print(b[k-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

e = list(input())
num =int(input())


alpha = list("abcdefghijklmnopqrstuvwxyz")
n = len(e)
a=[0]*(n+5)
#print(alpha)
for t in range(n) :
    for k in range(26):
        if alpha[k] == e[t]:
            a[t] = k
            break
#print(a)

ma = [-1]*5
mlen = 1

b= [1]*n
for k in range(n):
    b[k]= a[k]
ma[0] = np.argmin(b)

#print(ma[0],e[ma[0]])

for i in range(1,num):
    print(mlen)
    if ma[i] <= (n-mlen):
        for k in range(n-mlen):
            b[k]= b[k] * 26 + a[k+mlen] 
        mlen += 1
    b[n-i]= 26 ** 5

    ma[i] = np.argmin(b)
    for j in range(1,mlen+1):
        print(e[ma[i]+j-1],end='')
    print("")

Submission status: Runtime Error

Solution code:
s = input()
z = int(input())
list = [chr(i) for i in range(97,97+26)]
d = []
flag = 0
for j in list:
  indexes = [i for i,x in enumerate(s) if x==j]
  for k in indexes:
    for l in range(len(s)-k):
      d.append(s[k:l+k+1])
  if len(d)==k:
    break
print(sorted(set(d))[z-1])

Submission status: Runtime Error

Solution code:
s = input()
l = len(s)
K = int(input())
dict = {}
dicts = {}
ddict = {}
for i in range(l):
	dict[s[l-i-1]] = i
	dicts[s[i]] = 0
for i in range(l):
	dicts[s[i]] = dicts[s[i]] + 1
list = dict.keys()
for h in range(len(dict)):
	letter = min(list)
	if dict[letter]>=K-1:
		for i in range(dicts[letter]):
			index = s.rfind(letter)
			for j in range(1,6):
				ddict[s[index:j]]=1
		for k in range(K-1):
			list=ddict.keys()
			del ddict[(min(list))]
		result = min(list)
		break
	list.remove(letter)
print(result)

Submission status: Runtime Error

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


# alphabet順に探査する
# 探査順序配列
search_seq = sorted(list(set(s)))

count = 0
previous = 0

for key in search_seq:
    previous = count
    indexes = [i for i, x in enumerate(s) if x == key]
    sublist = []
    for index in indexes:
        stop = min(len(s) - index, k)
        for end in range(index+1, index + stop + 1):
            sublist.append(s[index:end])
    count += len(sublist)
    if k-1 < count:
        list_uq = list(set(sublist))
        list_sorted = sorted(list_uq)
        print(list_sorted[k-previous-1])
        exit()

Submission status: Runtime Error

Solution code:
import sys
import string


def search(prev,count,s,K):
    if not prev:
        prev_prime = [i for i in string.ascii_lowercase]
    else:
        prev_prime = [[i+j for j in string.ascii_lowercase] for i in prev]
        prev_prime = [a for b in prev_prime for a in b]
    prev = [strn in prev_prime if s.find(strn) != -1]
    if len(prev) + count >= K:
        print(prev[K - count - 1])
        sys.exit()
    else:
        count = count + len(prev)
    search(prev,count,s,K)


s = input()
K = int(input())
search([],0,s,K)

Submission status: Runtime Error

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

li = []
for i in range(len(s)-1):
    for j in range(len(s)-i):
        li.append(s[j:j+i+1])

print(sorted(list(set(li)))[K-1])

Submission status: Runtime Error

Solution code:
s = str(input())
K = int(input())
n = len(s)
l = []
for i in range(1,n) :
    for b in range(1, n) :
        if( i+b-1 <= n ) :
            l.append(s[i:(i+b-1)])
l.sort()
print("{}".format(l[K]))

Submission status: Runtime Error

Solution code:
import sys
import string


def search(prev,count,s,K):
    if not prev:
        prev_prime = [i for i in string.ascii_lowercase]
    else:
        prev_prime = [[i+j for j in string.ascii_lowercase] for i in prev]
        prev_prime = [a for b in prev_prime for a in b]

    prev = [string in prev_prime if string.find(s) != -1]
    if len(prev) + count >= K:
        print(prev[K - count - 1])
        sys.exit()
    else:
        count = count + len(prev)
    search(prev,count,s,K)


s = input()
K = int(input())
search([],0,s,K)

Submission status: Runtime Error

Solution code:
# coding : utf-8

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

strlist = sorted(range(len(s)), key=lambda k :list(s)[k], reverse=False)
s_len = len(s)
strset = set(s[strlist[0]])

calcEnd = False
for i in range(len(s)):
    #for j in range(i+1, len(s)+1):
    j_index = min(i+1, len(s) -1)
    for j in range(strlist[j_index], len(s)):
        #strset.add(s[i:j])
        strset.add(s[strlist[i]:j])

    if s[strlist[i+1]] != s[strlist[i]]:
        if len(strset) >= K:
            calcEnd = True
            break

    if calcEnd:
        break


strsetsort = sorted(strset, reverse=False)
ans = strsetsort[K-1]
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
a = []
if len(s) >= 5:
    for i in range(len(s)):
        if not s[i] in a:
            a.append(s[i])
    a.sort()
    i = 1
    while i < K:
        for j in range(len(s)):
            if s[j] == a[0] and j != len(s)-i:
                if not s[j:j+i+1] in a:
                    a.append(s[j:j+i+1])
        i+=1
    a.sort()
elif len(s) == 1:
    a.append(s)
else:
    for i in range(len(s)):
        if not s[i] in a:
            a.append(s[i])
    for j in range(len(s)-1):
        if not s[j:j+2] in a:
            a.append(s[j:j+2])
    for k in range(len(s)-2):
        if not s[j:j+3] in a:
            a.append(s[j:j+3])
    for l in range(2):
        if not s[j:j+4] in a:
            a.append(s[j:j+4])
    a.append(s)
    a.sort()
print(a[K-1])

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
a=[]
a = [s[i:j] for i in range(0,len(s)) for j in range(1,len(s)+1) if i != j]
a.remove("")
a=sorted(a)
b=[]
for i in a:
    if i not in b:
        b.append(i)
print(b[k-1])

Submission status: Runtime Error

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    indexes = [p for p, x in enumerate(s) if x == i]            
    count = 0
    onedict = []
    
    for ii in range(len(indexes)):
        onedict.append(i)
        
    while count <= len(s)  + 1 and len(onedict) <= k + 5:
        count = count + 1
        
        if True:
            quint = indexes
            for sss in range(len(onedict)):
                try:
                    pppp = onedict[sss]
                    pppp = pppp + s[ int(quint[sss])+ count]
                    onedict.append(pppp)
                except:
                    pass
    for jj in onedict:
        zis.append(jj)


zissort = list(sorted(list(set(zis))))

print(zissort[k-1])

Submission status: Runtime Error

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    indexes = [p for p, x in enumerate(s) if x == i]            
    count = 0
    onedict = []
    
    for ii in range(len(indexes)):
        onedict.append(i)
        
    while count <= len(s)  + 1 and len(onedict) <= k + 5:
        count = count + 1
        
        if True:
            quint = indexes
            for sss in range(len(onedict)):
                try:
                    pppp = onedict[sss]
                    pppp = pppp + s[ int(quint[sss])+ count]
                    onedict.append(pppp)
                except:
                    pass
            for jj in onedict:
                zis.append(jj)


zissort = list(sorted(list(set(zis))))

print(zissort[k-1])

Submission status: Runtime Error

Solution code:
s = input()
flag = False
K = int(input())
strl = len(s)
s_list = []
i = -1
while not flag:
    i += 1
    while chr(65+i) not in s:
        i += 1
    for k in range(strl):
        if s[k] == chr(65 + i):
            if k + K > strl:
                s_list.append(s[k:strl])
            else:
                s_list.append(s[k:k+K])
    s_list = list(set(s_list))
    s_l = []
    for c in s_list:
        for j in range(K):
            if j >= len(c):
                break
            s_l.append(c[:i+1])
    s_l = list(set(s_l))
    if len(s_l) >= K:
        flag = True
s_l.sort()
print(s_l[K-1])

Submission status: Runtime Error

Solution code:
s = str(input())
K = int(input())
n = len(s)
l = []
for i in range(1,n-1) :
    for j in range(2, n) :
        if( i < j ) :
            l.append(s[i:j])
l.sort()
print("{}".format(l[K]))

Submission status: Runtime Error

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    indexes = [p for p, x in enumerate(s) if x == i]            
    count = 0
    onedict = []
    
    for ii in range(len(indexes)):
        onedict.append(i)
        
    while count <= len(s)  + 1 and len(onedict) <= k + 1:
        count = count + 1
        
        if True:
            quint = indexes
            for sss in range(len(onedict)):
                try:
                    pppp = onedict[sss]
                    pppp = pppp + s[ int(quint[sss])+ count]
                    onedict.append(pppp)
                except:
                    pass
            for jj in onedict:
                zis.append(jj)


zissort = list(sorted(list(set(zis))))

print(zissort[k-1])