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 = len(S)
k = int(input())
cnt = 0
itl = sorted(list(set(S)))
ans = set([])
for w in itl:
    for i, s in enumerate(S):
        if s != w:
            continue
        else:
            for j in range(i+1, n+1):
                ans.add(S[i:j])
                cnt += 1
                if cnt == k:
                    break

    ans.clear()

ans = list(ans)
ans.sort()
index = k - 1 - (cnt - len(ans))
print(ans[index])

Submission status: Runtime Error

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

x = dict()
y = []
for i in range(5000):
    y.append([])

#O(N^2)
"""
for i in range(n):
    t = ""
    for j in range(i,n):
        t += s[j]
        if len(t) in x:
            if t not in y[len(t)]:
                y[len(t)].append(t)
        else:
            x[len(t)] = t
            y[len(t)].append(t)
X = []
for i in range(5000):
    if len(y[i]) == 0:
        continue
    y[i].sort()
    for j in range(len(y[i])):
        X.append(y[i][j])
"""
for i in range(n):
    t = ""
    for j in range(i,i+1+K):
        if j >= (n-1):
            break
        t += s[j]
        x[t] = t
X = []
for i in x:
    X.append(i)
X.sort()


#print(X)
print(X[K-1])

Submission status: Runtime Error

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

slen = len(s)
bstr = '1'*slen

B = int(bstr,2)
f = '0'+str(slen)+'b'
ss = list(s)

a = []
for i in range(B):
  w = ''
  fb = str(format(i, f))
  for i,si in enumerate(list(fb)):
    if si == '1':
      w += ss[i]
      
  if w != '' and w not in a:
    a.append(w)
    
a = sorted(a)
print(a[k-1])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
S = []
s = list(input().rstrip())
K = int(input())
for i in range(len(s)):
    for j in range(i+1, i+5):
        if s[i:j] not in S:
            S.append(s[i:j])
S.sort()
print("".join(S[K-1]))

Submission status: Runtime Error

Solution code:
n = int(input())

ans = []
while n != 0:
	ans.append(abs(n % -2))

	n += n % -2
	n /= -2
	n = int(n)

print(''.join([str(i) for i in reversed(ans)]))

Submission status: Runtime Error

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

arr = []
for i in range(0, len(str) - 1):
	for j in range(i, len(str) + 1):
		if str[i : j] not in arr:
			arr.append(str[i : j])

arr = sorted(arr)
print(arr[th])

Submission status: Runtime Error

Solution code:
import collections
 
s = input()
K = int(input())
 
l = len(s)
sub = set()
 
if l <= 50:
    for i in range(l):
        for j in range(i+1):
            sub.add(s[j:i+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    #print(subl)
    print(subl[K-1])
 
else:
    cl = collections.Counter(s).most_common()
    cl.sort(key=lambda x: x[0])
    #print(cl)
    be = cl[0][0]
    for i in range(l):
        if s[i] == be:
            for j in range(K):
                sub.add(s[i:i+j+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    print(subl[K-1])

Submission status: Runtime Error

Solution code:
import collections

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

l = len(s)
sub = set()

if l <= 50:
    for i in range(l):
        for j in range(i+1):
            sub.add(s[j:i+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    #print(subl)
    print(subl[K-1])

else:
    cl = collections.Counter(s).most_common()
    cl.sort(key=lambda x: x[0])
    print(cl)
    be = cl[0][0]
    for i in range(l):
        if s[i] == be:
            for j in range(K):
                sub.add(s[i:i+j+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    print(subl[K-1])

Submission status: Runtime Error

Solution code:
import collections

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

l = len(s)
sub = set()

if l <= 0:
    for i in range(l):
        for j in range(i+1):
            sub.add(s[j:i+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    #print(subl)
    print(subl[K-1])

else:
    cl = collections.Counter(s).most_common()
    cl.sort(key=lambda x: x[0])
    print(cl)
    be = cl[0][0]
    for i in range(l):
        if s[i] == be:
            for j in range(K):
                sub.add(s[i:i+j+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    print(subl[K-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)

def main():
    res = set()
    for i in range(n):
        for j in range(i, i+4):
            res.add(s[i:j+1])
    
    return sorted(res)[k-1]

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <set>
using namespace std;


int main () {
    string str;
  	int m;
    cin >> str;
    cin >> m;
  	int n = str.length();
  	set <string> st;
    for (int i = 0; i < n; i++)
        for (int j = 1; i + j <= n && j <= 5; j++)
            st.insert(str.substr(i, j));
    auto itr = st.begin();
    cout << *next(itr, m-1) << endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<set>
using namespace std;

int main(){
  string s;cin >> s;
  int l=(int)s.size();
  int k;cin >> k;
  set<string> x;
  for(int i=1;i<=l;i++){
    for(int j=0;j<l;j++){
      x.insert(s.substr(j,i));
    }
  }
  int a=0;
  for(auto itr=x.begin();itr!=x.end();itr++){
    a++;
    if(a==k){cout << *itr << endl;break;}
  }

}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Solution code:
from sys import stdin
import bisect
from itertools import accumulate
import numpy as np

s = stdin.readline().rstrip()
n = int(stdin.readline().rstrip())
li = []

for i in range(1,len(s)+1):
    for j in range(len(s)-i+1):
        li.append(s[j:j+i])
li = list(set(li))
li.sort()
print(li[n-1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
 
sub_s = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in sub_s and len(s[i:j]) == K:
            sub_s.append(s[i:j])
 
sub_s = sorted(sub_s)        
#print(sub_s)
print(sub_s[K-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=list(input())
k=int(input())
z=[]
for i in range(1,k+1):
    for j in range(len(s)):
        if j+i<len(s):
            z.append(s[j:j+i])
z.sort()
print(z[k-1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
lst = []
if len(s) == 1:
    print(s)
    exit()
for end in range(1, min(K, len(s))):
    start = 0
    while end < len(s)+1:
        if s[start:end] not in lst:
            lst.append(s[start:end])
        start += 1
        end += 1
lst.sort()
print(lst[-K])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]

  for i in index_list:##初期位置
    for j in range(1,min(k+1,len(s)-i)):##長さ
      substrings.append(s[i:i+j])
  if len(set(substrings)) >= k:
    break

print(sorted(list(set(substrings)))[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]
  index.append(index_list)

for ind in index:
  for i in ind:##初期位置
    for j in range(1,len(s)-i+1):##長さ
      substrings.append(s[i:i+j])
  if len(substrings) >= k:
    break
  

print(sorted(list(set(substrings)))[k-1])

Submission status: Runtime Error

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

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)==K:
        pass
    else:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])

Submission status: Runtime Error

Solution code:
s=list(input())

K=int(input())

L=[]

for i in range (1,K+1):
    for j in range (0, len(s)-i+1):
        L.append("".join(s[j:j+1]))

L=sorted(set(L))

print(L[K-1])

Submission status: Runtime Error

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

L = []
for i in range(len(s)):
    L.append(s[i])
    
L.sort()
word_list = []
idx = 0
if len(s) >= 18:
    while idx < len(s):
        if s[idx] == L[0]:
            for j in range(1, K+1):
                word_list.append(s[idx:idx+j])
        idx += 1
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            word_list.append(s[i:j])
    
word_set = set(word_list)
word_list = list(word_set)
word_list.sort()
print(word_list[K-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
result = []
for i in range(min(len(s),k)):
  result = result + [s[j:j+i+1] for j in range(len(s)-i)]
  
result = sorted(set(result))
print(result[3])

Submission status: Runtime Error

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+z])
        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: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

def main():
    s = input()
    k = int(input())
    n = len(s)
    dp = []
    for l in range(n):
        for r in range(l + 1, n + 1):
            t = s[l:r]
            i = bisect.bisect_left(dp, t)
            if t == dp[i]: continue
            if len(dp) < k:
                bisect.insort(dp, t)
            elif t < dp[-1]:
                dp.pop()
                bisect.insort(dp, t)
    print(dp[-1])

main()

Submission status: Runtime Error

Solution code:
s = list(input())
k = int(input())
sub = []
for i in range(1, min(len(s) + 1, k)):
    for j in range(1, len(s) + 2 - i):
        if not([s[s_i - 1] for s_i in range(j, j + i)] in sub):
            sub.append([s[s_i - 1] for s_i in range(j, j + i)])
sub.sort()
print(''.join(sub[k-1]))

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
lst=[]
cnt=0
r=sorted(s)
for idx in range(5):
  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: Runtime Error

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
r=sorted(s)
for idx in range(5):
  Lst=getChar(s.index(r[idx]),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: Runtime Error

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.append(getChar(i,s)[j] for j in range(len(getChar(i,s))))

print(lst[k-1])

Submission status: Runtime Error

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.append(getChar(i,s))
lst.sort()
print(lst[k-1])

Submission status: Runtime Error

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.append(i,s)
lst.sort()
print(lst[k-1])

Submission status: Runtime Error

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

subs = set()
for i in range(len(s)):
  for len in range(1, min(4, len(s) - i + 1)):
    subs.add(s[i : i + len])
    if len(subs) == k:
      break
  if len(subs) == k:
    break

print(max(subs))

Submission status: Runtime Error

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

substring_set = set()
for i in range(len(S)):
    for j in range(min([K, len(S)-i])):
        substring_set.add(S[i, i+j])

print(sorted(list(substring_set))[K-1])

Submission status: Runtime Error

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)
        if not p:
            break
        for key in p:
            temp = s[key]
            for j in range(1,ext):
                temp += s[key+j]
            if temp not in ans:
                ans.append(temp)
        ext += 1
        if len(ans) >= 500:
            break
    if len(ans) >= 500:
        break
    else:
        ind += 1
# print(ans)
ans.sort()
print(ans[k-1])

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

Submission status: Runtime Error

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])
    ansset = sorted(list(set(ans)))
    print(ansset[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
char = []
if len(s) == 1:
    print(1)
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])
    ansset = sorted(list(set(ans)))
    print(ansset[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
sl = []
if len(s) > 1:
    for i in range(len(s)-1):
        for j in range(i, len(s)+1):
            if abs(i-j) <= 5 and i != j:
                s_part = s[i:j]
                if s_part not in set(sl):
                    sl.append(s_part)
    sll = sorted(sl)
    print(sll[k-1])
else:
    print(s)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
sl = []
if len(s) > 1:
    for i in range(len(s)-1):
        for j in range(i, len(s)+1):
            if abs(i-j) <= 5:
                s_part = s[i:j]
                if s_part not in sl and s_part != "":
                    sl.append(s_part)
    sll = sorted(sl)
    print(sll[k-1])
else:
    print(s)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
sl = []
if len(s) > 1:
    for i in range(len(s)-1):
        for j in range(i, len(s)+1):
            s_part = s[i:j]
            if s_part not in set(sl) and s_part != "" and len(s_part)<= 5:
                sl.append(s_part)
    sll = sorted(sl)
    print(sll[k-1])
else:
    print(s)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
sl = []
if len(s) > 1:
    for i in range(len(s)-1):
        for j in range(i, len(s)+1):
            s_part = s[i:j]
            if s_part not in set(sl) and s_part != "":
                sl.append(s_part)
    sll = sorted(sl)
    print(sll[k-1])
else:
    print(s)

Submission status: Runtime Error

Solution code:
s = input()
k =int(input())
sl = []
if len(s) >1:
    for i in range(len(s)-1):
        for j in range(i, len(s)+1):
            s_part = s[i:j]
            if s_part not in sl and s_part != "":
                sl.append(s_part)
    sll = sorted(sl)
    print(sll[k-1])
else:
    print(s)

Submission status: Runtime Error

Solution code:
def resolve():
    s = input()
    k = int(input())
    l = len(s)
    subs = set()
    for i in range(l):
        for j in range(i + 1, l):
            sub = s[i:j]
            print(sub)
            subs.add(sub)
    return sorted(subs)[k - 1]


if __name__ == "__main__":
    print(resolve())

Submission status: Runtime Error

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

ans = []
for i in range(K):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (i != 0 and c.count(c[0]) == len(c)):
      c = "".join(set(c))
    ans.append(c)
  
set_ans = sorted(set(ans))
print(set_ans[K-1])

Submission status: Runtime Error

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

ans = []
flg = False
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (len(c) > K):
      flg = True
      break
    if (i != 0 and c.count(c[0]) == len(c)):
      c = "".join(set(c))
    ans.append(c)
  if flg:
    break
  
set_ans = list(set(ans))
set_ans.sort()
print(set_ans[K-1])

Submission status: Runtime Error

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

ans = []
flg = False
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (len(c) > K):
      flg = True
      break
    if (i != 0 and c.count(c[0]) == len(c)):
      c = c[0]
    ans.append(c)
  if flg:
    break
  
set_ans = list(set(ans))
set_ans.sort()
print(set_ans[K-1])

Submission status: Runtime Error

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

ans = []
flg = False
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (i != 0 and c.count(c[0]) == len(c)):
      c = c[0]
    ans.append(c)
    
set_ans = list(set(ans))
set_ans.sort()
print(set_ans[K-1])

Submission status: Runtime Error

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

ans = []
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if c.count(c[0]) == len(c):
      c = c[0]
    if c not in ans:
      ans.append(s[j:j+i+1])
ans.sort()
print(ans[K-1])

Submission status: Runtime Error

Solution code:
import itertools

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

ans = []
for i in range(1, len(s)+1):
  for j in list(itertools.combinations(s,i)):
    c = "".join(j)
    if (len(c) == c.count(c[0])):
      c = c[0]
    if c not in ans:
      ans.append(c)
print(ans[-K])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


for _ in range(5):
    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: Runtime Error

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


alist = sorted(list(aset))
for al in alist:
    if al == '':
        continue
    c += 1
    if c == K:
        ans = al
        break

print(ans)

Submission status: Runtime Error

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

a = len(s)
l = []

if k+1 > a:
    c = a
else:
    c = k+1

for i in range(a):
    for j in range(1,c):
        b = s[i:j]
        l.append(b)
        
w = list(set(l))

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <set>
using namespace std;
int main(void){
    // Your code here!
    string s; cin>>s;
    int k; cin>>k;
    set<string> can;
    for(int i = 1; i <= k; ++i){
        for(int j = 0; j + i <= s.size(); ++j){
            can.insert(s.substr(j,i));
        }
    }
    int a=1;
    string ans;
    for(string x:can){
        ans = x;
        if(a==k)break;
        ++a;
    }
    cout<<ans<<endl;
}

Submission status: Runtime Error

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

substr = []
for i in range(len(s)):
    for j in range(i+1, K):
        if len(s) >= K:
            substr.append(s[i:j])
        else:
            if j == len(s)+1:
                break
            substr.append(s[i:j])

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

Submission status: Runtime Error

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

S = sys.stdin.readline().rstrip()
K = int(sys.stdin.readline())


def prune(it):
    hist = set()
    ret = []
    for s, l in it:
        if s not in hist:
            hist.add(s)
        if len(hist) > K:
            break
        ret.append((s, l))
    return ret


collections = prune(sorted([(c, L) for L, c in enumerate(S)]))
for size in range(1, len(S)):
    threshold, _ = collections[-1]
    for s, left in collections:
        r = left + size + 1
        if len(s) == size and r <= len(S):
            t = S[left:r]
            if t <= threshold:
                collections.append((t, left))
    collections = prune(sorted(collections))

strings = list(set([s for s, _ in collections]))
strings.sort()
print(strings[K - 1])

Submission status: Runtime Error

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

S = sys.stdin.readline().rstrip()
K = int(sys.stdin.readline())


def prune(it):
    print(list(it))
    hist = set()
    ret = []
    for s, l in it:
        if s not in hist:
            hist.add(s)
        if len(hist) > K:
            break
        ret.append((s, l))
    return ret


collections = prune(sorted([(c, L) for L, c in enumerate(S)]))
for size in range(1, len(S)):
    threshold, _ = collections[-1]
    for s, left in collections:
        r = left + size + 1
        if len(s) == size and r <= len(S):
            t = S[left:r]
            if t <= threshold:
                collections.append((t, left))
    collections = prune(sorted(collections))

strings = list(set([s for s, _ in collections]))
strings.sort()
print(strings[K - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(a)
m = b[0]
n = 0
c = []
INF = 97+26
while len(c) < k:
    a1 = [i for i in range(len(s)) if a[i] == m]
    while b[n] == m:
        n += 1
    m = b[n]
    for i in a1:
        j = 0
        while i+j < len(s):
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
            j += 1

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

Submission status: Runtime Error

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

a = list(s)
a = [ord(i) for i in a]
b = sorted(a)
m = b[0]
n = 0
c = []
INF = 97+26
while len(c) < k:
    a1 = [i for i in range(len(s)) if a[i] == m]
    while b[n] == m:
        n += 1
    m = b[n]
    for i in a1:
        j = 0
        while i+j < len(s):
            if s[i:i+j+1] not in c:
                c.append(s[i:i+j+1])
            j += 1

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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


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

#重複の排除
sub_string = set(sub_string)
#辞書順にソートする
sub_string = sorted(sub_string)
#空白を削除
sub_string.remove('')
print(sub_string[K - 1])

Submission status: Runtime Error

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=[]

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

        l.append(s[j:j+1])

        l.append(s[j:j+2])

        l.append(s[j:j+3])

        l.append(s[j:j+4])

        l.append(s[j:j+5])

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

  return l[k-1]

print(main())

Submission status: Runtime Error

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=[]

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

        l.append(s[j:j+2])

        l.append(s[j:j+3])

        l.append(s[j:j+4])

        l.append(s[j:j+5])

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

  return l[k-1]

print(main())

Submission status: Runtime Error

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=[]

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

Solution code:
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])