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:
# 部分点は取れるけど満点は微妙そう(O(n^3?))
# K≦5らしい、死
from sys import stderr
from functools import reduce
from operator import add
f = lambda :[int(i) for i in input().split()]
debug = lambda *x:stderr.write(reduce(add,repr(x))+'\n')

s = input()
k = int(input())
subs = set()

for i in range(len(s)):
    for j in range(5):
        subs.add(s[i:j+1])

ans = list(subs)
ans.sort()
debug(ans)

print(ans[k-1])

Submission status: Wrong Answer

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

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

while(ansnum < k):
    #print(s)
    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 = sorted(listj)
        # 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 + a]
                    ansnum = k + 1
                    break
        if ansnum > k:
            break

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

Submission status: Wrong Answer

Solution code:
s=input()
K=int(input())
n = len(s)
N = int(n*(n+1)/2)
g = 0
for i in range(n):
    if i*(2*n-i+1)<= 2*K and 2*K < (i+1)*(2*n-1):
        g = i
print(s[int(N-K+1-(g*(2*n-g+1)/2)):int(N-K+1-(g*(2*n-g+1)/2)+g)])

Submission status: Wrong Answer

Solution code:
x = input()
K = int(input())
s = []
for i in range(len(x)):
    s.append(x[i])

s1 = list(map(ord,s))
#s1.sort()
#print(s1)

lst = []
for i in range(26):
    lst.append(0)
for i in range(len(s1)):
    lst[s1[i]-97] += 1
#print(lst)

c = 0
for i in range(len(lst)):
    c+=lst[i]
    
print(c)
cnt = 0
if c>=K:
    ans = ""
    for i in range(len(lst)):
        if lst[i]!=0:
            for j in range(lst[i]):
                #print(c,cnt)
                #print(ans)
                ans += chr(97 + i)
                cnt += 1
                if cnt == c:break
        if cnt == c:break
    print(ans[:len(ans)-1])

Submission status: Wrong Answer

Solution code:
Strings = list(input())
k = int(input())
NEW = []
for i in range(len(Strings)):
    for j in range(len(Strings)):
        add_st = ''.join(Strings[i:j])
        NEW.append(add_st)

SUN = sorted(NEW)
print(SUN[k-1])

Submission status: Wrong Answer

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):
        tmp.append(str(S[j:i+j+1]))

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

#print(lis_uniq)
print(lis_uniq[len(lis_uniq)-K])

Submission status: Wrong Answer

Solution code:
import sys
s = input()
K = int(input())
    
temp = sorted(list(s))
temp = [x for x in set(temp) if temp.count(x) >= 1]
temp = sorted(temp)
# temp = list(temp)
# print(temp)

count =0

for i in temp:
    # print(type(i))
    index_num = [n for n, v in enumerate(list(s)) if v == i]
    if len(index_num) ==1:
        index_num = s.index(i)
        for j in range(index_num,len(s)+1):
            count += 1
            ans = s[index_num:j]
            if count == K+1:
                print(ans) 
                sys.exit()
    else:    
        test = []
        # print(index_num)
        for j in range(len(index_num)):
            # print(index_num[j])
            test.append(s[index_num[j]:index_num[j]+2])
        test = sorted(test)
        index_2 = s.index(test[0])
        for j in range (index_2,len(s)):
            count +=1
            ans = s[index_2:j]
            if count ==K+1:
                print(ans)
                sys.exit()

Submission status: Wrong Answer

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

pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

f = {}
for c in range(97, 123):
    for i in pos[c]:
        for j in range(i, n):
            f[s[i::j+1]] = 1
            if len(f) >= 1000:
                break
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + '1'
    while len(u) > len(v): v = v + '1'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Wrong Answer

Solution code:
import sys
s = input()
K = int(input())
    
temp = sorted(list(s))
temp = [x for x in set(temp) if temp.count(x) >= 1]
temp = sorted(temp)
# temp = list(temp)
# print(temp)

count =0

for i in temp:
    # print(type(i))
    index_num = [n for n, v in enumerate(list(s)) if v == i]
    if len(index_num) ==1:
        index_num = s.index(i)
        for j in range(index_num,len(s)):
            count += 1
            ans = s[index_num:j]
            if count == K+1:
                print(ans) 
                sys.exit()
    else:    
        test = []
        # print(index_num)
        for j in range(len(index_num)):
            # print(index_num[j])
            test.append(s[index_num[j]:index_num[j]+2])
        test = sorted(test)
        index_2 = s.index(test[0])
        for j in range (index_2,len(s)):
            count +=1
            ans = s[index_2:j]
            if count ==K+1:
                print(ans)
                sys.exit()

Submission status: Wrong Answer

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

L = sorted(list(set(s)))

def f():
    k = K
    for l in L:
        numbers = []
        n = s.find(l)
        while n != -1:
            numbers.append(n)
            n = s.find(l, n + 1)
            
        substrings = set()
        for num in numbers:
            string = s[num:]
            if len(string) != 1:
                substrings.add(s[num:])
        substrings = sorted(list(substrings))
        
        if k == 1:
            return l
        
        if len(substrings) == 0:
            k -= 1
            continue
        
        for substring in substrings:
            if len(substring) >= k:
                return substring[:k]
            
            k -= len(substring)
    
print(f())

Submission status: Wrong Answer

Solution code:
def get_substrs(s):
    strs = set()
    l = len(s)
    for i in range(l):
        for k in range(i,l):
            strs.add(s[i:k+1])
    return strs

if __name__ == '__main__':
    s = input()
    K = int(input())
    strs = get_substrs(s)
    strs = list(strs)
    strs.sort()
    print(strs)

Submission status: Wrong Answer

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

pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

f = set()
for c in range(97, 123):
    for i in pos[c]:
        for j in range(i, n):
            f.add(s[i:j+1])
            if len(f) >= x:
                break
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + '1'
    while len(u) > len(v): v = v + '1'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Wrong Answer

Solution code:
# time complexity: O(|s|^2 + |subsample|log|subsample|)

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


def brute_force(s, K):
    substring_set = set()

    # brute-force
    for start in range(len(s)):
        for length in range(len(s) - start + 1):
            if length == 0:
                substring = s[start]
            else:
                substring = s[start:start+length]
            substring_set.add(substring)


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

Submission status: Wrong Answer

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


l = list(s)
alphabet = sorted(list(set(l)))

num = 0
for a in alphabet:
    cand = []
    n = s.count(a)
    for i in range(n):
        ind = l.index(a)
        for j in range(k):
            cand.append(s[ind+i: ind+j+1+i])
        l.remove(a)
    cand = list(set(cand))
    if len(cand) >= k:
        break
    else:
        num += len(cand)
print(sorted(cand)[k-num-1])

Submission status: Wrong Answer

Solution code:
s = input()
x = int(input())
n = len(s)
f = set()
pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

for c in range(97, 123):
    for i in pos[c]:
        for j in range(i, n):
            f.add(s[i:j+1])
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + 'a'
    while len(u) > len(v): v = v + 'a'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Wrong Answer

Solution code:
import string

s = input()
K = int(input())
candidate = set()
end = 0

for i in string.ascii_lowercase:
    pos = []#iの位置
    for j in range(len(s)):
        if s[j] == i:
            pos.append(j)
            
    if len(pos)!=0:
        candidate.add(i)
        c = 1
        while True:#subsetの長さc+1を変える
            if pos == []:
                break
            for j in range(len(pos)):
                if pos[j] == 10000:
                    continue
                if j+c>len(s)-1:#はみ出したらposから除く(10000に)
                    pos[j] = 10000
                    
            #10000を除く
            n = len(pos)
            for j in range(n):
                if pos[n-j-1] == 10000:
                    del pos[n-j-1]
            
            #posの可能性調べ終えたら次のiへ
            if pos == []:
                break
            
            #candidateに、iから始まる可能なc+1文字のsubsetを追加
            for j in pos:
                candidate.add(s[j:j+c+1])
            
            c += 1
        
        if len(candidate)>=K:
            end = 1
            break
            
    if end == 1:
        break
        
print(list(sorted(candidate)))
print(list(sorted(candidate))[K-1])

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if len(s) <= 50:
    l = []
    for i in range(1,len(s)+1):
        for j in range(0,len(s)):
           t = s[j:j+i]
           if len(t) != i:break
           if t in l: continue
           l.append(t)
    l = sorted(l)
    print(l[k-1])
else:
    b = sorted(s)[0]
    print(1)

Submission status: Wrong Answer

Solution code:
s = input()
x = int(input())
n = len(s)
f = set()
pos = [set() for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].add(i)

for c in range(97, 123):
    for i in pos[c]:
        for j in range(i, n):
            f.add(s[i:j+1])
    if len(f) >= x:
        break

def cmp(u, v):
    while len(u) < len(v): u = u + 'a'
    while len(u) > len(v): v = v + 'a'
    return u > v

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]

print(p[x - 1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=str(input())
n=int(input())
if(len(s)<=5):
	arr=[]
	for i in range(len(s)):
		if(s[i] not in arr):
			arr.append(s[i])
		for j in range(i+1,len(s)):
			if(s[i:j+1] not in arr):
				arr.append(s[i:j+1])
	arr.sort()
	#print(*arr)
	print(arr[n-1])
else:
	flag=0
	z="abcdefghijklmnopqrstuvwxyz"
	
	while(flag==0):
		k=0
		arr=[]
		arr1=[]
		for i in range(len(s)):
			if(s[i]==z[k]):
				arr.append(i)
		arr1.append(s[0])
		for i in range(len(arr)):
			for j in range(arr[i]+1,len(s)):
				#print(s[arr[i]:j+1])
				if(s[arr[i]:j+1] not in arr1):
					arr1.append(s[arr[i]:j+1])
		if(len(arr1)>=n):
			arr1.sort()
			flag=1
			print(arr1[n-1])
		else:
			n-=len(arr1)
		k+=1

Submission status: Wrong Answer

Solution code:
s = input()
x = int(input())
n = len(s)
f = set()
def cmp(u, v):
    while len(u) < len(v): u = u + 'a'
    while len(u) > len(v): v = v + 'a'
    return u > v

for c in range(97, 123):
    ch = chr(c)
    for i in range(n):
        if s[i] == ch:
            for j in range(i, n):
                f.add(s[i:j+1])
    if len(f) >= x:
        break

p = [u for u in f]
for i in range(len(p)):
    for j in range(i+1, len(p)):
        if cmp(p[i], p[j]):
            p[i], p[j] = p[j], p[i]
print(p[x - 1])

Submission status: Wrong Answer

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    ones = i
    indexes = [p for p, x in enumerate(s) if x == i]
            
    for kk in indexes:
        st = s[kk]
        count = 0
        while count <= len(s) - kk + 1:
            count = count + 1
            try:
                st = st + s[kk + count]
                zis.append(st)
            except:
                pass
                
    if len(zis) > k:
        break
zissort = list(sorted(list(set(zis))))
print(zissort[k-1])

Submission status: Wrong Answer

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

ss=[]
for l in range(len(s),0,-1):
  e=len(s)
  tmp=[]
  while e-l >= 0:
    # print("appending " + s[e-l:e])
    tmp.append(s[e-l:e])
    e-=1
  tmp=list(set(tmp))
  tmp.sort(reverse=True)
  # print("tmp is ",end='')
  # print(tmp)
  ss.extend(tmp)
  if len(ss) >= K:
    break

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

Submission status: Wrong Answer

Solution code:
s = input()
n = input()
ans = set([])
test = list(s)

for i in range(len(test)):
    s = test[i]
    ans.add(s)
    for j in range(i+1, min(i+5, len(test))):
        s = s + test[j]
        ans.add(s)
    
ans = list(ans)

ans.sort()
print(ans)
print(ans[int(n)-1])

Submission status: Wrong Answer

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    ones = i
    indexes = [p for p, x in enumerate(s) if x == i]
            
    for kk in indexes:
        st = s[kk]
        count = 0
        while count <= len(s) - kk + 1:
            count = count + 1
            try:
                st = st + s[kk + count]
                zis.append(st)
            except:
                pass
                
    if len(zis) > k:
        break
zissort = list(sorted(list(set(zis))))
print(zissort)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import itertools

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

lst = [s]
slist = list(s)
for n in range(len(slist)):
	for i in itertools.permutations(slist, n):
		lst.append(i)

lst = list(set(lst))
ans = []
for i in lst:
	st = ""
	for j in i:
		st += str(j)
	if st == '':
		continue
	if st in s:
		ans.append(st)

ans.sort()
ans.sort(key=len)
print(ans[len(ans) - K])

Submission status: Wrong Answer

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

ss=[]
for l in range(len(s),0,-1):
  e=len(s)
  tmp=[]
  while e-l >= 0:
    # print("appending " + s[e-l:e])
    tmp.append(s[e-l:e])
    e-=1
  tmp=list(set(tmp))
  tmp.sort(reverse=True)
  # print("tmp is ",end='')
  # print(tmp)
  ss.extend(tmp)
  # if len(ss) >= K:
  #   break

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

Submission status: Wrong Answer

Solution code:
s=str(input())
n=int(input())
if(len(s)<=5):
	arr=[]
	for i in range(len(s)):
		if(s[i] not in arr):
			arr.append(s[i])
		for j in range(i+1,len(s)):
			if(s[i:j+1] not in arr):
				arr.append(s[i:j+1])
	arr.sort()
	#print(*arr)
	print(arr[n-1])
else:
	flag=0
	z="abcdefghijklmnopqrstuvwxyz"
	arr=[]
	arr1=[]
	while(flag==0):
		k=0
		for i in range(len(s)):
			if(s[i]==z[k]):
				arr.append(i)
		arr1.append(s[0])
		for i in range(len(arr)):
			for j in range(arr[i]+1,len(s)):
				#print(s[arr[i]:j+1])
				if(s[arr[i]:j+1] not in arr1):
					arr1.append(s[arr[i]:j+1])
		if(len(arr1)>=n):
			arr1.sort()
			flag=1
			print(arr1[n-1])
		k+=1

Submission status: Wrong Answer

Solution code:
s = input()
n = input()
ans = set([])
test = list(s)

for i in range(len(test)):
    s = test[i]
    ans.add(s)
    for j in range(i+1, len(test)):
        s = s + test[j]
        ans.add(s)
    
ans = list(ans)

ans.sort()
print(ans)
print(ans[int(n)-1])

Submission status: Wrong Answer

Solution code:

s = input()

K = int(input())

s2 = [i for i in s]
s3 = [i for i in s]
S = s2

S.sort()

S = s[:K]

S = list(set(S))

S.sort()

X = []
for w in S:
    for i in range(len(s3)):
        if s3[i]==w:
            k = min(len(s3)-i, K)
            for ki in range(k):
                word = s[i:i+ki+1]
                X.append(word)
                
X = list(set(X))
X.sort()

print(X[K-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def c_kth_substring(S, K):
    tmp = []
    for i in range(len(S)):
        for j in range(i + 1, len(S) + 1):
            if i != j and i + j <= len(S) + 1:
                tmp.append(S[i:j])
    tmp = sorted(set(tmp))
    ans = tmp[K - 1]
    return ans

S = input().strip()
K = int(input())
print(c_kth_substring(S, K))

Submission status: Wrong Answer

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

ss = list(set(sorted(s)))
zis = []
for i in ss:
    zis.append(i)
    ones = i
    indexes = [p for p, x in enumerate(s) if x == i]
            
    for kk in indexes:
        st = s[kk]
        count = 0
        while count <= len(s):
            count = count + 1
            try:
                st = st + s[kk + count]
                zis.append(st)
            except:
                pass
                
    if len(zis) > 6:
        break
zissort = list(sorted(list(set(zis))))
print(zissort)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=str(input())
n=int(input())
if(len(s)<=5):
	arr=[]
	for i in range(len(s)):
		if(s[i] not in arr):
			arr.append(s[i])
		for j in range(i+1,len(s)):
			if(s[i:j+1] not in arr):
				arr.append(s[i:j+1])
	arr.sort()
	#print(*arr)
	print(arr[n-1])
else:
	flag=0
	z="abcdefghijklmnopqrstuvwxyz"
	arr=[]
	arr1=[]
	while(flag==0):
		k=0
		for i in range(len(s)):
			if(s[i]==z[k]):
				arr.append(i)
		arr1=[s[0]]
		for i in range(len(arr)):
			for j in range(arr[i]+1,len(s)):
				#print(s[arr[i]:j+1])
				if(s[arr[i]:j+1] not in arr1):
					arr1.append(s[arr[i]:j+1])
		if(len(arr1)>=n):
			arr1.sort()
			flag=1
			print(arr1[n-1])

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

s = input()
k = int(input())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

dic = []

for char in alphabets:
    
    index = 0
    ss = []
    while index != -1:
        index = s.find(char, index)

        if index != -1:
            ss.append(s[index:])
            if len(ss) > 50:
                break
            index += 1

    if  len(ss) > 0:
        ss.sort()
        for x in ss:
            for i in range(len(x)):
                if x[0:i+1] not in dic:
                    dic.append(x[0:i+1])
                    if len(dic) >= k:
                        break
        if len(dic) >= k:
            break

print(dic[k-1])

Submission status: Wrong Answer

Solution code:
s = input()
n = input()
ans = set([])
test = list(s)

for i in range(len(test)):
    s = test[i]
    ans.add(s)
    for j in range(len(test)-i-1):
        s = s + test[j+1]
        ans.add(s)
    
ans = list(ans)

ans.sort()
print(ans[int(n)-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


#str = input()
#order =  int(input())

def get_all_substrings(string):
  length = len(string)
  alist = []
  for i in range(length):
    for j in range(i,length):
      alist.append(string[i:j + 1])
  return alist


str=input()
order = int(input())
allsubs = get_all_substrings(str)
allsubs.sort()
#print(allsubs)

neu = list(dict.fromkeys(allsubs))
#print(neu)

print(neu[order-1])

Submission status: Wrong Answer

Solution code:

s = input()

K = int(input())

s2 = [i for i in s]
S = s2

S.sort()

S = s[:K]

S = list(set(S))

S.sort()

X = []
for w in S:
    for i in range(len(s2)):
        if s2[i]==w:
            k = min(len(s2)-i, K)
            for ki in range(k):
                word = s[i:i+ki+1]
                X.append(word)
                
X = list(set(X))
X.sort()

print(X[K-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
string = list(input())
K = int(input())
#print(string)



def Result(string,K):
    lst = []
    for j in range(1,len(string)+1):
        for i in range(len(string)-j+1):
            lst.append("".join(string[i:i+j]))
            #print(lst)
        lst = list(set(lst))
        lst.sort()
        print(lst)
        if len(lst)>=K:
            #print(lst)
            return(lst[K-1])
        
print(Result(string,K))

Submission status: Wrong Answer

Solution code:
s=str(input())
n=int(input())
if(len(s)<=5):
	arr=[]
	for i in range(len(s)):
		if(s[i] not in arr):
			arr.append(s[i])
		for j in range(i+1,len(s)):
			if(s[i:j+1] not in arr):
				arr.append(s[i:j+1])
	arr.sort()
	#print(*arr)
	print(arr[n-1])
else:
	k=-1
	z="abcdefghijklmnopqrstuvwxyz"
	for i in range(26):
		if(z[i] in s):
			k=i
			break
	arr=[]
	for i in range(len(s)):
		if(s[i]==z[k]):
			arr.append(i)
	#print(*arr)
	arr1=[s[0]]
	for i in range(len(arr)):
		for j in range(arr[i]+1,len(s)):
			#print(s[arr[i]:j+1])
			if(s[arr[i]:j+1] not in arr1):
				arr1.append(s[arr[i]:j+1])
	#print(*arr1)
	if(len(arr1)>=n):
		arr1.sort()
		#print(*arr1)
		print(arr1[n-1])
	else:
		z=z[k+1:]
		for i in range(len(z)):
			if(z[i] in s):
				k=i
				break
		arr2=[]
		for i in range(len(s)):
			if(s[i]==z[k]):
				arr2.append(i)
		arr3=[]
		for i in range(len(arr)):
			arr.append(s[i])
			for j in range(i+1,len(s)):
				arr3.append(s[i:j+1])
		if(len(arr3)>=n):
			arr3.sort()
		print(arr3[n-1])

Submission status: Wrong Answer

Solution code:
import sys
import math
if __name__ == "__main__":
   s = str(input())
   K = int(input())
   uniq = sorted(list(set(list(s))))
   buf = []
   for i in range(len(uniq)):
      buf.append(uniq[i])
      for j in range(len(s)):
         if s[j] == uniq[i]:
            fin = K
            if (len(s) - j) - K < 0:
               fin = (len(s) - j)
            for k in range(1, fin):
               buf.append(s[j:j+k+1])
   ans = sorted(buf)
#   print(ans)
   print(ans[K-1])

Submission status: Wrong Answer

Solution code:
s=input()
K=int(input())
S=set()
l=len(s)
for i in range(l):
    for j in range(i,l):
        if len(S)>K:
            break
        S.add(s[i:j+1])
ans=sorted(S)
print(ans[K-1])

Submission status: Wrong Answer

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

smin = list(set(list(s)))
smin = sorted(smin)[0:5]


def search(st):
    ans = []
    cnt = 0
    for a in st:
        if len(set(ans)) >= 5:
            return ans
        for i in range(len(s)):
            if s[i] is a:
                for j in range(6):
                    ans.append(s[i:min(i+j,len(s))])

    
    return ans
    
b = list(set(search(smin)))

if b[0] == '':
    del b[0]

print(b[k-1])

Submission status: Wrong Answer

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

s_list = []
for i in range(0, len(s)):
    for j in range(1, len(s)-i+1):
        if len(s_list) < k:
            s_list.append(s[i:i+j])
            s_list.sort()
        elif s_list[k-1] > s[i:i+j]:
            s_list.append(s[i:i+j])
            s_list = list(set(s_list))
            s_list.sort()
            s_list = s_list[:k]

print(s_list)
dict_list = list(set(s_list))
dict_list.sort()

print(dict_list[k-1])

Submission status: Wrong Answer

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

smin = list(set(list(s)))
print(smin)
smin = sorted(smin)[0:5]
print(smin)

def search(st):
    ans = []
    cnt = 0
    for a in st:
        if len(set(ans)) >= 5:
            return ans
        for i in range(len(s)):
            if s[i] is a:
                for j in range(6):
                    ans.append(s[i:min(i+j,len(s))])

    
    return ans
    
b = list(set(search(smin)))

if b[0] == '':
    del b[0]

print(b[k-1])

Submission status: Wrong Answer

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

zisyo = []
for i in range(len(s)):
    count = 0
    st = s[i]

    zisyo.append(st)
    onelist = list(sorted(list(set(zisyo))))
    
    if onelist.index(st) > 6:
        continue
    while count <= len(s):
        count = count + 1
        try:
            st = st + s[i + count]
            zisyo.append(st)
        except:
            pass
    
zisyosort = list(sorted(list(set(zisyo))))
print(zisyosort)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sub = set()
for i in range(1, len(s) + 1):
    for k in range(int(len(s) / i) + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K])

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
uniqueS = []
for s in S:
    if s not in uniqueS:
        uniqueS.append(s)
lenS = len(S)
ansS = []
for us in uniqueS:
    for i in range(lenS):
        for j in range(1,min(lenS-i+1,6)):
            if S[i] == us:
                if S[i:i+j] not in ansS:
                    ansS.append(S[i:i+j])
    if len(ansS) >= 5:
        break
ansS.sort()
print(ansS[K-1])

Submission status: Wrong Answer

Solution code:
def solve():
    
    s = input()
    K = int(input())
    l = []
    for i in range(len(s)):
        for j in range(i, len(s)-i+1):
            if s[i:j+1] not in l:
                 l.append(s[i:j+1])
    l.sort()
    print(l[K-1])
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
result = []
for num in range(len(s) + 1):
    for location in range(len(s)):
        try:
            string = s[location : location+num]
        except:
            continue
        if not string in result:
            result.append(string)
print(result[K*-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
uniqueS = []
for s in S:
    if s not in uniqueS:
        uniqueS.append(s)
lenS = len(S)
ansS = []
for us in uniqueS:
    for i in range(lenS):
        if S[i] == us:
            for j in range(1,lenS-i+1):
                if S[i:i+j] not in ansS:
                    ansS.append(S[i:i+j])
    if len(ansS) >= 5:
        break
ansS.sort()
print(ansS[K-1])