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:
#!/usr/bin/env python3
import sys


def solve_(S: str, K: int):
    mn = 'z'
    tmp = set()
    for i, c in enumerate(S):
        if c < mn:
            tmp = set()
            for j in range(5):
                tmp.add(S[i:i + j + 1])
            mn = c
        elif c == mn:
            for j in range(5):
                tmp.add(S[i:i + j + 1])
    #print(tmp)
    if len(tmp) < K:
        s = ''
        for c in S:
            if c != mn:
                s += c
        return solve_(s, K - len(tmp))
    else:
        tmp = list(tmp)
        tmp.sort()
        return tmp[K - 1]

def solve(S, K):
    ret = solve_(S, K)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

li=[]
if len(s)<=k:
    iif=0
else:
    iif=k
for i in range(len(s)):
    for j in range(1, len(s)-iif+1):
        li.append(s[i:i+j])
        #print(s[i:i+j])

se=set(li)
sli=list(se)
sli.sort()
#print(sli)
print(sli[k-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
ans = []
for i in range(1,len(s)):
  for j in range(len(s)):
    if j+i > len(s): break

    ans.append(s[j:j+i])

ans = list(sorted(set(ans))) #setはsortedではソートできる。リストでソートしてsetに帰ると順序は保証されない

print((ans[k-1]))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(s: str, K: int):
    N = len(s)
    for i in range(ord('a'), ord('z')+1):
        c = chr(i)
        l = -1
        subs = []
        while c in s[l+1:]:
            l = s.index(c, l+1)
            for r in range(l+1, N+1):
                subs.append(s[l:r])
        subs = sorted(list(set(subs)))
        if len(subs) > K:
            break
        else:
            K -= len(subs)
            continue
    print(subs[K-1])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

n = len(s)

ex = [s[:min(K, n)]]
for i in range(n):
    if i + K - 1 < n:
        if ex[0] > s[i:i+K]:
            ex[0] = s[i:i+K]
    else:
        if ex[0][:n-i] > s[i:]:
            ex.insert(0, s[i:])


if K > len(ex[-1]):
    for i in range(len(ex[0])):
        for j in range(i+1, len(ex[0])+1):
            ex.append(ex[0][i:j])
    ex = set(ex)
    ex = sorted(list(ex))
    print(ex[K-1])
else:
    print(ex[-1])

Submission status: Runtime Error

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

n = len(s)

sub = []
alp = [chr(i) for i in range(ord('a'), ord('z')+1)]

for a in alp:
    if a in s:
        start = -1
        while True:
            start = s.find(a, start+1)
            if start==-1:
                break
            for j in range(start+1, min(start+K,n+1)):
                if s[start:j] not in sub:
                    sub.append(s[start:j])
    if len(sub) > K:
        break

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

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
X=[]
for i in range(len(s)-4):
    X.append(s[i:i+5])
X.append(s[len(s)-4:len(s)])
X.append(s[len(s)-3:len(s)])
X.append(s[len(s)-2:len(s)])
X.append(s[len(s)-1:len(s)])
    
X.sort()
C=[]
for x in X[:k]:
    for j in range(len(x)):
        C.append(x[:j+1])
        
C=list(set(C))

C.sort()

print(C[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
 
li = sorted(list(set(s)))
result = []

def substring(l):
    result.append(l)
    if len(result) >= K:
        pass
    for m in li:
        if l+m in s:
            return substring(l+m)

for l in li:
    substring(l)

print(result[K-1])

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
 
li = sorted(list(set(s)))
result = []

def substring(l):
    result.append(l)
    if len(result) >= K:
        pass
    for m in li:
        if l+m in s:
            return substring(l+m)

for l in li:
    substring(l)
print(result)

print(result[K-1])

Submission status: Runtime Error

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

_set=set()

for i in range(len(s)-1):
  for j in range(i+1, len(s)):
    _set.add(s[i:j])

#print(sorted(list(_set)))
print(sorted(list(_set))[K-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
K = int(input())
length = len(s)
if (length>=5):
    substringList = list(set([s[i] for i in range(length)]))
else :
    substringList = []
    for i in range(1,length+1) :
        for j in range(length-i+1) :
            substringList.append(s[j:j+i])

substringList = sorted(substringList)
print(substringList[K])

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#A
def A():
    return

#B
def B():
    return

#C
def C():
    s = stdin.readline().rstrip()
    K = II() - 1
    ans = []
    for i in range(len(s)):
        for k in range(K):
            b = s[i:i + k + 1]
            ans.append(b)
    ans.sort()
    ans = list(set(ans))
    print(ans[K])
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Runtime Error

Solution code:
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字列
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字列
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの文字列
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def unqlst(lst):
    return list(set(lst))

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    N = LI()
    reds = sorted(MLIS(N), key=lambda x:x[0])
    blues = sorted(MLIS(N), key=lambda x:x[0])

    blueF = [False for x in range(N)]

    count = 0

    for i in range(N):
        for j in range(N):
            if blueF[j] == False and reds[i] < blues[j]:
                blueF[j] = True
                count += 1
                break
    print(count)

def D():
    pass

def E():
    s = LC()
    k = LI()
    words = []
    for b in range(len(s)):
        for e in range(5):
            if s[b:b+e] != '':
                words.append(s[b:b+e])
    words = sorted(unqlst(words))
    print(words[k-1])
def F():
    pass

def G():
    pass

def H():
    pass

E()

Submission status: Runtime Error

Solution code:
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字列
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字列
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの文字列
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def unqlst(lst):
    return list(set(lst))

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    N = LI()
    reds = sorted(MLIS(N), key=lambda x:x[0])
    blues = sorted(MLIS(N), key=lambda x:x[0])

    blueF = [False for x in range(N)]

    count = 0

    for i in range(N):
        for j in range(N):
            if blueF[j] == False and reds[i] < blues[j]:
                blueF[j] = True
                count += 1
                break
    print(count)

def D():
    pass

def E():
    s = LC()
    k = LI()
    words = []
    for b in range(len(s)):
        for e in range(min(5, len(s) - b + 1)):
            if s[b:b+e] != '':
                words.append(s[b:b+e])
    words = sorted(unqlst(words))
    print(words[k])
def F():
    pass

def G():
    pass

def H():
    pass

E()

Submission status: Runtime Error

Solution code:
def solve(string):
    s, k = string.split()
    g = []
    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            g.append(s[i:j])
    g = sorted(set(g))
    return g[int(k)-1]


if __name__ == '__main__':
    print(solve(input()))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

sub = set()

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

sub = sorted(sub)

print(sub[k])

Submission status: Runtime Error

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

tmp = set()
for i in range(len(S)):
  for j in range(5):
    tmp.add(S[i:i+j])
print(sorted(tmp)[K])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def rec(s):
    length=len(s)
    ret=set()
    for depth in range(length):
        string=s[depth]
        ret.add(string)
        for i in range(depth+1,depth+K):
            if i<length:
                string+=s[i]
                ret.add(string)
	return ret
  
ret=rec(s)
print(sorted(ret)[K-1])

Submission status: Runtime Error

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

def rec(s):
    ret=set()
    for depth in range(len(s)):
        string=s[depth]
        ret.add(string)
        for i in range(depth+1,length):
            string+=s[i]
            ret.add(string)
    return ret

a=rec(s)
print(sorted(a)[K-1])

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(map(int,input().split()))

su = 0

co = 0

for i in range(max(a)):
    for j in range(n):
        if a[j] > 0 and co == 0:
            co += 1
            su += 1
        if co  >=  1:
            if a[j] == 0:
                co = 0
            else:
                a[j] -= 1
    co = 0

print(su)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys


def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(sub)
  print(sub[K])


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c, i):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    i = S.index(c[0])
    return f(S, K-1, c, i)
  else:
    if c > S[i:]:
      c = c[:-1]
    c = makec(c)
    return f(S, K, c, 0)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a', 0)
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    if c > S:
      c = c[:-1]
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  print(c)
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    if c > S:
      c = c[:-1]
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
           'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = alph.index(c[-1]) + 1
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
           'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
           'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    if c > S:
      c = makec(c[-1])
    else:
      c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#encoding utf-8

import copy
import numpy as np
import random


s = list(str(input()))
k = int(input())

substrings = []
for length in range(1,len(s)+1):
    if length >= 5:
        break
    for i in range(len(s)-length+1):
        word = "".join(s[i:i+length])
        # print(word)
        if word in substrings:
            pass
        else:
            substrings.append(str(word))

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

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
def all(s, k):
    if s == '':
        return {}
    ret = set()
    for i in range(k):
        if i < len(s):
            ret.add(s[:(i+1)])
    return ret.union(all(s[1:], k))
koho = sorted(list(all(s,k)))
print(koho[k-1])

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
a = list(set(S))
a.sort()

k = []
l = 0
while True:
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1,6):
                if i+j <= len(S):
                    k.append(S[i:i+j])
                else:
                    break
    if len(k) >= 5:
        break
    if l == len(a)-1:
        break
    l += 1

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

Submission status: Runtime Error

Solution code:
n=int(input())
h=[int(x) for x in input().split()]
cost=[0]
cost.append(abs(h[0]-h[1]))
for p in range(2,n):
    cost.append(min(cost[p-1]+abs(h[p]-h[p-1]),abs(h[p]-h[p-2])+cost[p-2]))
print(cost)
print(cost[n-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

L = []
L.append(s)

for i in range(len(s),0,-1):
    for j in range(len(s)):
        if i + j >= len(s):
            break
        L.append(s[j:i+j])
    L = sorted(set(L))
#    if len(L) >= K:
print(L[K-1])

Submission status: Runtime Error

Solution code:
# ABC 097 C
S = input()
K = int(input())

cand = []
for l in range(1, K+1):
    for i in range(len(S) - l):
        cand.append(S[i:i+l])

cand = sorted(list(set(cand)))
print(cand[K-1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict

S = input()
K = int(input())

alphabet = defaultdict(list)
for i, s in enumerate(S):
    alphabet[s].append(i)

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        for l in range(1, len(S)-j+1):
            cand.append(S[j:j+l])
    cand = list(set(cand))
    if len(cand) < K:
        break
    i += 1
cand = sorted(cand)
print(cand[K-1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict

S = input()
K = int(input())

alphabet = defaultdict(list)
for i, s in enumerate(S):
    alphabet[s].append(i)

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        for l in range(1, len(S)-j+1):
            cand.append(S[j:j+l])
    i += 1
cand = sorted(list(set(cand)))
print(cand[K-1])

Submission status: Runtime Error

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
s = input()
K = int(input())

dic = set()

for i in range(K):
  for j in range(len(s)):
    if len(s[j:j+i])>0:
      dic.add(s[j:j+i])

ans = sorted(list(dic))
print(ans[K-1])

Submission status: Runtime Error

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

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 #length = n
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    

for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)

#print(min_c,chars)

'''
for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])
'''

print(sorted(chars)[k-1])

Submission status: Runtime Error

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

l=len(s)
chars=set()
sub1=['']*l


for i in range(l-1):
  n=i+1 #length = n
  for j in range(l-i):
    chars.add(s[j:j+n])

print(sorted(chars)[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import string

ch = string.ascii_lowercase

s = input()
K =  int(input())
pointer = 0
buf = []
boundary = [('a', i) for i in range(len(s)) if s[i] == 'a']
boundary.sort(key=lambda x: x[0])
while True:
  if len(buf) >= 5 or pointer >= len(ch):
    break
  tmp = len(boundary)
  if tmp > 0:
    for _ in range(1):
      element = boundary.pop(0)
      buf.append(element[0])
      buf = list(set(buf))
      if element[1] < len(s) - 1:
        next_element = (element[0] + s[element[1] + 1], element[1] + 1)
        boundary.append(next_element)
  if len(boundary) == 0:
    pointer += 1
    boundary = [(ch[pointer], i) for i in range(len(s)) if s[i] == ch[pointer]]
  buf.sort()
  boundary.sort(key=lambda x: x[0])
  print(boundary)
  print(buf)
  
print(buf[K - 1])

Submission status: Runtime Error

Solution code:
import string

ch = string.ascii_lowercase

s = input()
K =  int(input())
pointer = 0
buf = []
boundary = [('a', i) for i in range(len(s)) if s[i] == 'a']
boundary.sort(key=lambda x: x[0])
while True:
  if len(buf) >= 5 or pointer >= len(ch):
    break
  tmp = len(boundary)
  for _ in range(tmp):
    element = boundary.pop(0)
    buf.append(element[0])
    buf = list(set(buf))
    if element[1] < len(s) - 1:
      next_element = (element[0] + s[element[1] + 1], element[1] + 1)
      boundary.append(next_element)
  if len(boundary) == 0:
    pointer += 1
    boundary = [(ch[pointer], i) for i in range(len(s)) if s[i] == ch[pointer]]
  buf.sort()
  
print(buf[K - 1])

Submission status: Runtime Error

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

A = []

k = 0

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

Submission status: Runtime Error

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

for i in range(1, min(N, 6)):
    for j in range(N - i + 1):
        ans.append(s[j:j+i])

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

Submission status: Runtime Error

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

sub_list=[]

for i in range(len(s)):
    for j in range(1,K+1):
        if(i+j<len(s)):
            sub_list.append(s[i:i+j])

sub_set=set(sub_list)
sub_dict=sorted(sub_set,key=str)

print(sub_dict[K-1])

Submission status: Runtime Error

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

sub_list=[]
i,j=0,1
while True:
    if(i+j>=len(s) and i==len(s)-1):
        break
    else:
        sub_list.append(s[i:i+j])
        if(j<=K):
            j+=1
        else:
            i+=1
            j=1
set_list=set(sub_list)

dict_list=list(set_list)
dict_list.sort(key=str)

print(dict_list[K-1])

Submission status: Runtime Error

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

c = []

if len(s) < 100:

    for i in range(len(s)):
        for k in range(1,len(s)+1):
            c.append(s[i:i+k])

    b = sorted(list(set(c)))

    print(b[m-1])

else:
    po = []
    for i in range(len(s)):
        if s[i] not in po:
            po.append(s[i])

    for i in range(len(s)):
        if s[i:i+2] not in po:
            po.append(s[i:i+2])

    for i in range(len(s)):
        if s[i:i+3] not in po:
            po.append(s[i:i+3])
    print(po[m-1])

Submission status: Runtime Error

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

c = []

if len(s) < 100:

    for i in range(len(s)):
        for k in range(1,len(s)+1):
            c.append(s[i:i+k])

    b = sorted(list(set(c)))

    print(b[m-1])

else:
    po = []
    for i in range(len(s)):
        po.append(s[i])
    po = sorted(set(po))
    print(po[m-1])

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
c = len(s)
a = []
for i in range(5):
  b = [s[j:i+j+1] for j in range(c-i-1)]
  b = list(set(b))
  a = a + b
a.sort()
print(a[k-1])

Submission status: Runtime Error

Solution code:
x=input()
k=int(input())
#print(x)

import itertools

text = x
l = len(text)
list1=[]
for s, e in itertools.combinations(range(l+1), 2):
  list1.append(text[s:e])
list1=set(list1)
list1=list(list1)
list1.sort()
print(list1[k-1])

Submission status: Runtime Error

Solution code:
a = input()
b = int(input())
ar = list(a)
ar.sort()
br = []
for i in range(len(a)):
    if a[i] == ar[0]:
        try:
            for j in range(1,b+1):
                br.append(a[i:i+j])
        except indexError:
            break
cr = set(br)
if len(cr) < b:
    for i in range(len(a)):
        if ar[i] == ar[1]:
            try:
                for j in range(1,b+1):
                    br.append(a[i:i+j])
            except indexError:
                break
dr = set(br)
er = sorted(dr)
print(er[b-1])

Submission status: Runtime Error

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

n = len(s)

d = set()
for i in range(n):
    for j in range(i+1, min(i+k,n+1)):
        tmp = s[i:j]
        d.add(tmp)
a = sorted(list(d))
print(a[k-1])

Submission status: Runtime Error

Solution code:
import itertools
import bisect
s = input()
K = int(input())
array = []
for i, j in itertools.combinations(range(len(s) + 1), 2):
    index = bisect.bisect_left(array, s[i:j])
    if len(array) <= index:
        array += [s[i:j]]
    elif array[index] != s[i:j]:
        array = array[0 : index] + [s[i:j]] + array[index + 1:len(s)]
print(array[K - 1])

Submission status: Runtime Error

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



length = len(s)

checksubstring = set()
substrings = []

if length < 5:    
    for i in range(length-1):
        for j in range(i+1,length+1):
            substring = s[i:j]
            if substring not in checksubstring:
                checksubstring.add(substring)
                substrings.append(substring)
    
    if s not in substrings:
        substrings.append(s)

else:
    for i in range(length):
        if s[i] not in checksubstring:
            substrings.append(s[i])
            checksubstring.add(s[i])

substrings.sort()

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

Submission status: Runtime Error

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

length = len(s)

checksubstring = set()
substrings = []

for i in range(length-1):
    for j in range(i+1,length+1):
        substring = s[i:j]
        if substring not in checksubstring:
            checksubstring.add(substring)
            substrings.append(substring)

if s not in substrings:
    substrings.append(s)
    
substrings.sort()

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