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: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    s = f.read_str()
    k = f.read_int()
    n = len(s)
    cand = set()

    for i in xrange(1,6):
        for j in xrange(n-i+1):
            cand.add(s[j:j+i])

    cand = sorted(list(cand))

    return cand[k-1]


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
s = input()
K = int(input())
ans = []
for i in s:
    if not (i in ans):
        ans.append(i)
ans.sort()
ans = ans[:5]
j = len(s)
if j >= 2:
    for i in range(j-1):
        if (s[i] in ans) and not (s[i:i+2] in ans):
            ans.append(s[i:i+2])
ans.sort()
ans = ans[:5]
if j >= 3:
    for i in range(j-2):
        if (s[i:i+2] in ans) and not (s[i:i+3] in ans):
            ans.append(s[i:i+3])
ans.sort()
ans = ans[:5]
if j >= 4:
    for i in range(j-3):
        if (s[i:i+3] in ans) and not (s[i:i+4] in ans):
            ans.append(s[i:i+4])
ans.sort()
ans = ans[:5]
if j >= 5:
    for i in range(j-4):
        if (s[i:i+4] in ans) and not (s[i:i+5] in ans):
            ans.append(s[i:i+5])
ans.sort()
ans = ans[:5]
print(ans[K-1])

Submission status: Accepted

Solution code:
s=input()
N=len(s)
K=int(input())
L=[]
for i in range(1,K+1):
    for j in range(N-i+1):
        L.append(s[j:j+i])
L.sort()
M=len(L)
R=[L[0]]
k=0
for i in range(1,M):
    if L[i] !=R[k]:
        R.append(L[i])
        k+=1
print(R[K-1])

Submission status: Accepted

Solution code:
def solve(s, K):
    cs = sorted(set(s))
    ws = set([])
    for i in range(len(s)):
        c = s[i]
        if c in cs[:2]:
            ws.add(c)
            ws.add(s[i:i+2])
            ws.add(s[i:i+3])
            ws.add(s[i:i+4])
            ws.add(s[i:i+5])
    wss = sorted(ws)
    return wss[K - 1]

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

print(solve(s, K))

Submission status: Accepted

Solution code:
# encoding:utf-8

def main():
	s = input()
	k = int(input())
	substr = set()
	for start in range(len(s)):
		for end in range(start, start+5):
			if end <= len(s):
				substr.add(s[start:(end+1)])

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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

from heapq import heappush, heappop

Q = set()
u = set()
N = len(s)
for i in range(N):
    for j in range(i+1, i+K+1):
        ss = s[i:j]
        if ss in u:
            continue
        u.add(ss)
        Q.add(ss)
        if len(Q) > K:
            Q.remove(max(Q))
l = sorted(Q)
print(l[K-1])

Submission status: Accepted

Solution code:
def f():
  s = input()
  k = int(input())
  ss = [s[i:] for i in range(len(s))]
  ss.sort()
  cnt = 0
  done = []
  for sb in ss:
    for i in range(len(sb)):
      res = (sb[0:i+1])
      if res not in done:
        done.append(res)
        cnt += 1
        if cnt == k:
          print(res)
          return
f()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
S = input()
K = int(input())
ans = set()

for s in sorted(set(S)):
    if len(ans) >= K:
        break
    for i in range(len(S)):
        if S[i] == s:
            for k in range(K):
                ans.add(S[i:i+k+1])

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

Submission status: Accepted

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

ans = []
st = set()

for i in range(n):
    for j in range(i + 1, min(n + 1, i + 1 + K)):
        sub = S[i:j]
        # print(sub)
        if sub in st:
            continue
        st.add(sub)
        ans.append(sub)
        ans.sort()
        # print(ans)
        if len(ans) > K:
            ans = ans[:K]

print(ans[-1])

Submission status: Accepted

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

ss = []
for i in range(1, 6):
    for j in range(n):
        if j + i <= n:
            ss.append(''.join(s[j:j + i]))
ss = sorted(set(ss))
print(ss[k - 1])

Submission status: Accepted

Solution code:
def solve(s, k):
    can = set()

    for l in range(k):
        for i in range(len(s) - l):
            can.add(s[i:i + l + 1])
    can.discard('')
    can = sorted(can)
    return can[k-1]


s = input()
k = int(input())
print(solve(s, k))

Submission status: Accepted

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

s = set()
for i in range(1, 6):
    for j in range(len(S)):
        if i + j <= len(S):
            s.add(S[j:j + i])

ans = list(sorted(s))[K - 1]

print(ans)

Submission status: Accepted

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

subs = set()
for i in range(N):
    for k in range(K):
        subs.add(S[i:i+1+k])
print(sorted(subs)[K-1])

Submission status: Accepted

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

Submission status: Runtime Error

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

T = set()
for i in range(N):
    for j in range(i + 1, N + 1):
        T.add(S[i:j])
A = sorted(list(T))
print(A[K])

Submission status: Runtime Error

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

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

ans_set = set(ans_list)
ans_list_min = sorted(list(ans_set))
print(ans_list_min[K-1])

Submission status: Runtime Error

Solution code:
fun main() {
    val s= readLine()!!
    val n=s.length
    val k= readLine()!!.toInt()
    var subs= mutableSetOf<String>()
    for (i in 0 until n){
        for (j in i until Math.min(n, i+k)){
            val sub=s.slice(i until j+1)
            subs.add(sub)
        }
    }
    println(subs.sorted()[k-1])
}

Submission status: Runtime Error

Solution code:
s = str(input())
K = int(input())
L = []
M = []
con = 0
for i in s:
  L.append(i)
L = list(set(L))
L.sort()
for j in range(len(s)):
    if s[j] == L[0]:
      for k in range(1,6):
        if j + k >=len(s):
          M.append(s[j:])
          break
        else:
          M.append(s[j:j+k])

for l in range(len(s)):
  if s[l] == L[1]:
    for m in range(1,6):
      if l + m >= len(s):
        M.append(s[l:])
        break
      else:
        M.append(s[l:l+m]) 
if len(M) < K:
  for n in range(len(s)):
    if s[n] == L[2]:
      for o in range(1,6):
        if n + o >=len(s):
          M.append(s[n:])
          break
        else:
          M.append(s[n:n+o])
M = list(set(M))
M.sort()
print(M)
print(M[K - 1])

Submission status: Runtime Error

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

orders = set()

for i in range(n):
    for j in range(1, 6):
        if i + j < n:
            orders.add(S[i:i + j])

print(sorted(list(orders))[k - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
readline = sys.stdin.readline
n, m = map(int, readline().split())
P = list(map(lambda x:int(x)-1, readline().split()))
G = [set() for _ in range(n)]
for i in range(m):
    x, y = map(lambda x:int(x)-1, readline().split())
    G[x].add(y)
    G[y].add(x)

D = {}
cnt = 0
V = [-1]*n
while -1 in V:
    st = V.index(-1)
    que = deque([st])
    V[st] = cnt
    D[cnt] = set([P[st]])
    while que:
        nw = que.popleft()
        for nx in G[nw]:
            if V[nx] != -1: continue
            D[cnt].add(P[nx])
            V[nx] = cnt
            que.append(nx)
    cnt += 1
print(sum([int(i in D[V[i]]) for i in range(n)]))

Submission status: Runtime Error

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, A, B, C, D = LI()
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    S = SS()

    ## 移動経路に2連続以上の岩があったらダメ
    if '##' in S[A:C+1] or '##' in S[B:D+1]:
        print('No')
    else:
        ## ふぬけ君を先に移動させればいい
        if C < D:
            print('Yes')
        ## ふぬけ君を飛び越えられる瞬間が存在すればいい
        else:
            # 岩の間のどこかに3以上の隙間があること
            if '...' in S[B:D+1]:
                print('Yes')
            else:
                print('No')

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
,# 最大で5文字になりそうなので上位K個を保持しつつ全探索
s = input() + " "
k = int(input())
ans = []
for i in range(len(s)):
    for j in range(i + 1, min(len(s), i + 5 + 1)):
        t = "".join(s[i:j])
        if t not in ans:
            ans.append(t)
            ans = sorted(ans)[:6]
print(ans[k - 1])

Submission status: Runtime Error

Solution code:
# 最大で5文字になりそうなので上位K個を保持しつつ全探索
s = input()
k = int(input())
ans = []
for i in range(len(s)):
    for j in range(i + 1, min(len(s), i + 5 + 1)):
        t = "".join(s[i:j])
        if t not in ans:
            ans.append("".join(s[i:j]))
            ans = sorted(ans)[:5]
print(ans[k - 1])

Submission status: Runtime Error

Solution code:
sList = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        sList.append(s[i:j])
sSet = sorted(set(sList))

print(sSet[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
#ss = sorted(set(s))

sList = list(s)
for i in range(len(s)):
    for j in range(i+1, len(s)):
        sList.append(s[i:j])
sSet = sorted(set(sList))

print(sSet[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
#ss = sorted(set(s))

sList = []
for i in range(len(s)):
    for j in range(i+1, len(s)):
        sList.append(s[i:j])
sSet = sorted(set(sList))

print(sSet[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
ans = set()
r = len(s)
if r <= 50:
    for i in range(r):
        for j in range(r):
            ans.add(s[i:r-j])
    print(sorted(list(ans))[k])
else:
    print('Pass')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
class Bit:
  def __init__(self,n):
    self.bl = n.bit_length()
    self.size = n
    self.tree = [0]*(n+1)
 
  def sum(self,i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s

  def add(self,i,x):
    while i <= self.size:
      self.tree[i] += x
      i += i & -i
import sys
input = sys.stdin.readline
from copy import deepcopy
def main():
  n = int(input())
  ca = [input().rstrip() for i in range(2*n)]
  dc = [0]*(2*n+1)
  for i in range(2*n):
    if ca[i][0] == "W":
      dc[int(ca[i][2])] = i+1
    else:
      dc[n+int(ca[i][2])] = i+1
  dp = [[10**7 for i in range(n+1)] for j in range(n+1)]
  dp[0][0] = 0
  bit0 = Bit(2*n)
  for i in range(n+1):
    wx = dc[i+1]
    if i:
      bit0.add(dc[i],1)
    if i < n:
      dp[i+1][0] = dp[i][0]+wx-bit0.sum(wx)-1
    bitc = deepcopy(bit0)
    for j in range(n+1):
      if j < n:
        bx = dc[n+j+1]
        dp[i][j+1] = min(dp[i][j+1],dp[i][j]+bx-bitc.sum(bx)-1)
        bitc.add(bx,1)
      if i < n:
        dp[i+1][j] = dp[i][j]+wx-bitc.sum(wx)-1
  print(dp[-1][-1])
main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

s = input()
n = len(s)
k = int(input())
ans = []
used = set()
"""
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[s[i]].append(i)
""" 
for i in range(n):
    start = list(s[i])
    if s[i] not in used:
        ans.append(s[i])
        used.add(s[i])
    for j in range(i + 1, i + k):
        start.append(s[j])
        temp = "".join(start)
        if temp not in used:
            ans.append(temp)
            used.add(temp)
ans.sort()
print(ans[k - 1])

Submission status: Runtime Error

Solution code:
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
        ans = list(set(ans))
    else:
        c = key.pop(0)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(min(5, len(s) - i - 1)):
                queue.append(s[i:i+j+1])

print(ans[K-1])

Submission status: Runtime Error

Solution code:
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
        ans = list(set(ans))
    else:
        c = key.pop(0)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(len(s) - i - 1):
                queue.append(s[i:i+j+1])

print(ans[K-1])

Submission status: Runtime Error

Solution code:
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
    else:
        c = key.pop(0)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(1, len(s) - i - 1):
                queue.append(s[i:i+j+1])

print(ans[K-1])

Submission status: Runtime Error

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

s_set = set()
for i in range( N - K + 1 ):
  for j in range( 1, K + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

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

Submission status: Runtime Error

Solution code:

N=len(s)
L=[]
flag=False
for a in abc:
    for i in range(N):
        if s[i]==a:
            L.append(s[i:])
            
    if flag:
        break
L=sorted(L)
#print(L)
ans=[]
for l in L:
    n=len(l)
    for i in range(n):
        t=l[:i+1]
        if t not in ans:
            ans.append(l[:i+1])
    if len(ans)>=K:
        break
#print(ans)
print(ans[K-1])

Submission status: Runtime Error

Solution code:
from numba import njit
s=input()
K=int(input())

N=len(s)
L=[]
@njit
def solve():
    for i in range(N):
        for j in range(i,N):
            L.append(s[i:j+1])
L=sorted(list(set(L)))
print(L[K-1])

Submission status: Runtime Error

Solution code:
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(i+1,min(len(S)+1,i+K+1)):
                    lis.add(S[i:j])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

Submission status: Runtime Error

Solution code:
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(i+1,min(len(S),i+K+1)):
                    lis.add(S[i:j])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

Submission status: Runtime Error

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

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

ans_lis = []
for i in range(min(5, len(lis))):
    i = lis[i]
    s2 = s
    while 1:
        idx = s2.find(i)
        if idx==-1:
            break
        ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx-1))]
        s2 = s2[idx+1:]
ans_lis = list(set(ans_lis))
ans_lis.sort()
print(ans_lis[4])

Submission status: Runtime Error

Solution code:
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(1,K+1):
                    lis.add(S[i:min(len(S),i+j)])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

Submission status: Runtime Error

Solution code:
from sys import stdin
from sys import setrecursionlimi
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

def main():
    finish = set()
    S = len(s)
    for i in range(S):
        for j in range(i+1,S+1):
            finish.add(s[i:j])

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = list(input().strip())
K = int(input())
N = len(s)

if N == 1:
    print(s[0])
    exit()
sub = set()
for i in range(N):
    for j in range(N):
        sub.add(s[i:j+1])

print(sorted(sub)[K])

Submission status: Runtime Error

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

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 
'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
'''

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

s = input().strip()
K = int(input())
N = len(s)

sub = set()
for i in range(N):
    for j in range(N):
        sub.add(s[i:j + 1])

print(sorted(sub)[K])

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase


def main():
    all_s = input()
    k = int(input())
    ind = {a: [] for a in ascii_lowercase}
    if len(all_s) == 1:
        print(all_s)
    else:
        for i in range(len(all_s)):
            ind[all_s[i]].append(i)
        for s, index in ind.items():
            if not index:
                continue
            else:
                substr = {s}
                i = 1
                all_substr = len(all_s) * len(index) - sum(index) - 1
                if all_substr < k:
                    k -= all_substr
                    continue
                before_len = 0
                while len(substr) != before_len:
                    before_len = len(substr)
                    for j in index:
                        substr.add(all_s[j:i + j + 1])
                    i += 1
                substr = list(substr)
                substr.sort()
                print(substr[k - 1])
                break


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

if k==1:
    print(st)
    exit()

ans=[]
x=1
while x<6:
    for i in range(n-x):
        if i<0:
            continue
        for j in range(i+x,n+x):
            if j>n:
                continue
            ans.append(s[i:j])
    x+=1
    
ans=list(set(ans))
ans=sorted(ans)
print(ans[k-1])

Submission status: Runtime Error

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

if k==1:
    print(st)
    exit()

ans=[]
x=1
while x<6:
    for i in range(n-x):
        if n-x<0:
            continue
        for j in range(i+x,n+x):
            if n+x>n:
                continue
            ans.append(s[i:j])
    x+=1
    
ans=list(set(ans))
ans=sorted(ans)
print(ans[k-1])

Submission status: Runtime Error

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

if k==1:
    print(st)
    exit()

ans=[]
x=1
while x<6:
    for i in range(n-x):
        for j in range(i+x,n+x):
            ans.append(s[i:j])
    x+=1
    
ans=list(set(ans))
ans=sorted(ans)
print(ans[k-1])

Submission status: Runtime Error

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

if k==1:
    print(st)
    exit()

if n<=20:
    ans=[]
    for i in range(n-1):
        for j in range(i+1,n+1):
            ans.append(s[i:j])
    ans=list(set(ans))
    ans=sorted(ans)
    print(ans[k-1])
    exit()

option=[]
option.append(st)
ans=[]
while option:
    option=sorted(option)
    now=option[0]
    print(option,now)
    option=option[1:]
    ans.append(now)
    if len(ans)>=k:
        break
    for i in range(n-len(now)):
        tmp=s[i:i+len(now)+1]
        if tmp[:len(now)]==now and tmp not in option:
            option.append(tmp)

ans=sorted(ans)
print(ans[k-1])

Submission status: Runtime Error

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

a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1])
print(a)

Submission status: Runtime Error

Solution code:
s=input();k=int(input())    
a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)}[k-1])
print(a)

Submission status: Runtime Error

Solution code:
from collections import deque 
def k_sub():
    s=input()
    k=int(input())
    dq=deque()
    for i in range(1,len(s)+1):
        for j in range(k):
            a.append(s[j:j+i])
    a.sort()
    print(a[k-1])
if __name__=='__main__':
    k_sub()

Submission status: Runtime Error

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

if __name__=='__main__':
    k_sub()

Submission status: Runtime Error

Solution code:
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        print(s[i:j])
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    sys.stdin = open("sample.txt")
    S = Scanner.string()
    K = Scanner.int()
    m = []
    N = len(S)
    for i in range(N):
        for j in range(i, min(i+K, N)):
            m.append(S[i: j + 1])
    m = sorted(set(m))
    print(m[K-1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    sys.stdin = open("sample.txt")
    S = Scanner.string()
    K = Scanner.int()
    m = []
    N = len(S)
    for i in range(N):
        for j in range(i, N):
            m.append(S[i: j + 1])
    m = sorted(set(m))
    print(m[K-1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
d=dict()
if len(s)==1:
  print(s)
else:
  for i in range(len(s)-1):
    a=s[i]
    if a not in d:
      d[a]=0
    for j in range(i+1,len(s)):
      a+=s[j]
      if a not in d:
        d[a]=0
  l=list(d)
  l.sort()
  print(l[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    s=input()
    m=int(input())
    tank=[]
    n=len(s)
    alpha=[chr(i) for i in range(97, 97+26)]
    for i in range(26):
        for j in range(n):
            if alpha[i]==s[j]:
                for k in range(n-j):
                    if s[j:j+k+1] not in tank:
                        tank.append(s[j:j+k+1])
        if len(tank)>=k:
            break
    tank.sort()
    print(tank[m-1])
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

if K==1:
  print(sorted(S)[0])
  exit()

ans=[]
if K<len(S):
  s0=sorted(S[:-K+1])[0]
  for j,e in enumerate(S[:-K+1]):
    if e==s0:
      for i in range(1,K+1):
        a="".join(S[j:j+i])
        if a not in ans:
          ans.append(a)
      
sl=S[-K+1:]
for i in range(K-1):
  for j in range(i+1,K):
    a="".join(sl[i:j])
    if a not in ans:
      ans.append(a)

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

Submission status: Runtime Error

Solution code:
import bisect
 
s = input()
n = int(input())
 
dic = set()
a = []
 
for i in range(1, len(s)):
  for j in range(len(s) - i):
    sub = s[j:j + i]
    if sub in dic:
      continue
    dic.add(sub)
    bisect.insort(a, sub)
    
print(a[n - 1])