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

Solution (Python):
from collections import defaultdict
def main():
	S = input()
	K = int(input())
	sub = defaultdict(set)
	for i in range(len(S)):
		sub[S[i]].add(S[i:len(S)+1])

	alphabet = [chr(ord('a') + i) for i in range(26)]
	ans = set()
	for c in alphabet:
		if c in sub:
			this_list = list(sub[c])
			this_list.sort()
			for e in this_list:
				for i in range(1, len(e)+1):
					ans.add(e[:i])
					if len(ans) == K:
						print(e[:i])
						return


if __name__ == '__main__':
    main()

Solution (Python):


s = input().rstrip()  
k = int(input())

arr = set()
for i in range(len(s)):
    for j in range(1, min(k, len(s)-i)+1):
        arr.add(s[i:i+j])

arr = sorted(list(arr))
print(arr[k-1])

Solution (Python):

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, min(N+1, l+1+K)):
                subs.append(s[l:r])
        subs = sorted(list(set(subs)))
        if len(subs) > K-1:
            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)  
    K = int(next(tokens))  
    solve(s, K)


if __name__ == '__main__':
    main()

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

a=set([])

for x in range(len(s)):
	for y in range(x, x+5):
		a.add(s[x:y+1])

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

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


for n in range(len(ex)):
    for i in range(len(ex[n])):
        for j in range(i+1, len(ex[n])+1):
            ex.append(ex[n][i:j])

ex = set(ex)
ex = sorted(list(ex))

print(ex[K-1])

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

a=set()
for x in sorted(list(set(s))):
    for i in range(len(s)):
        if s[i]==x:
            for j in range(K):
                if i+j+1>len(s): break
                a.add(s[i:i+j+1])
         

    if len(a)>=K: break

a=sorted(list(a))
print(a[K-1])

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

a=set()
for x in "abcdefghijklmnopqrstuvwxyz":
    for i in range(len(s)):
        if s[i]==x:
            for j in range(K):
                if i+j+1>len(s): break
                a.add(s[i:i+j+1])
         

    if len(a)>=K: break

a=sorted(list(a))
print(a[K-1])

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

subs = set()
L = len(s)
for l in range(1,min(L,5)+1):
    for i in range(L-l+1):
        subs.add(s[i:i+l])
print(sorted(list(subs))[K-1])

Solution (Python):
s=input()
k=int(input())
substrings=set()
for i in range(len(s)):
    for j in range(5):
        if i+j<len(s):
            substrings.add(s[i:i+j+1])
substrings=sorted(list(substrings))
print(substrings[k-1])

Solution (Python):
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+1,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])

Solution (Python):
def strcmp(x, y):
    short = min(len(x), len(y))
    for i in range(short):
        if ord(x[i]) < ord(y[i]): 
            return 0
        elif ord(x[i]) > ord(y[i]):
            return 1
    if short == len(x):
        return 0
    else:
        return 1

s = input()
lens = len(s)
K = int(input())
jisho = [] 


for i in range(1, K+1):
    for j in range(lens-i+1):
        temp = s[j:j+i]
        if temp not in jisho:
            jisho.append(temp)

size = len(jisho)-1
for i in range(K):
    for j in range(size, 0, -1):
        if strcmp(jisho[j], jisho[j-1]) == 0:
            temp = jisho[j-1]
            jisho[j-1] = jisho[j]
            jisho[j] = temp
print(jisho[K-1])

Solution (Python):
s = input()
K = int(input())
sub = []
for i in range(len(s)):
    for j in range(i, min(i+K, len(s))):
        sub.append(s[i:j+1])

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

Solution (Python):
s = input()
k = int(input())
st = set()
m = min(k, len(s))
t = sorted(list(set(list(s))))[:k]
for i in range(len(s)):
    if s[i] in t:
        for j in range(i + 1, i + 6):
            st.add(s[i:j])
l = sorted(list(st))
print(l[k - 1])

Solution (Python):
s = input()
N = len(s)
K = int(input())
l = []
for n in range(1, K + 1):
    for i in range(N - n + 1):
        l.append(s[i:i + n])
l = list(set(l))
l.sort()
print(l[K - 1])

Solution (Python):

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

part = [[]]

for i in range(len(s)):
    for j in range(1,k+1):
        if i + j > len(s):
            break
        part.append(s[i:i+j])
del part[0]

part.sort()

delete = []

for i in range(1,len(part)):
    if part[i-1] == part[i]:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del part[delete[i] - diff]
    diff += 1

print("".join(part[k-1]))

Solution (Python):



import queue

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

char2index= dict([(x, i) for i, x in enumerate('abcdefghijklmnopqrstuvwxyz')])
index2char= dict([(i, x) for i, x in enumerate('abcdefghijklmnopqrstuvwxyz')])
indices = [[] for _ in range(len(char2index))]


substrings = set()
K_substring = []
count = -1
def recursive(char, indices):
    global count
    count += 1
    if count == K:
        K_substring.append(char)
        return
    
    new_indices = [[] for _ in range(len(char2index))]
    
    for i in indices:
        if i + 1 < len(S):
            new_indices[char2index[S[i + 1]]].append(i + 1)
         
    for i, index in enumerate(new_indices):
        if len(index) > 0:
            recursive(index2char[i], index)
            if count == K:
                K_substring.append(char)
                break
            
    return

indices = list(range(-1, len(S)-1))
recursive('', indices)
    
print(''.join(K_substring[::-1]))

Solution (Python):
s=input()
k=int(input())
X=[]
for i in range(len(s)):
    for j in range(k):
        X.append(s[i:i+j+1])
X=list(set(X))

X.sort()

print(X[k-1])

Solution (Python):
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(reverse=True)
st=[]
while len(st)<K:
  t=li.pop()
  if t not in st:
    st.append(t)
print(st[-1])

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

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

print(memo[K-1])

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

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


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

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



S = ""
K = 0


def set_inputs():
    global S, K
    S = get_str()
    K = get_int()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    substrings = set()
    for i in range(1, K + 1):
        for j in range(len(S) + 1 - i):
            substrings.add(S[j:j+i])
    print(list(sorted(substrings))[K-1])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



S = ""
K = 0


def set_inputs():
    global S, K
    S = get_str()
    K = get_int()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    d = defaultdict(list)
    for i, s in enumerate(S):
        d[s].append(i)
    cnt = 0
    for s in sorted(d.keys()):
        substrings = set(s)
        for i in d[s]:
            for ss in [S[i:i+k] for k in range(2, K + 1)]:
                substrings.add(ss)
        if cnt + len(substrings) >= K:
            print(list(sorted(substrings))[K-1-cnt])
            return
        cnt += len(substrings)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
k=int(input())
ans=[]
for i in range(len(s)):
  for j in range(max(0,len(s)-5),len(s)):
    ans.append(s[j:])
  s=list(s)
  s.pop()
  s=''.join(s)
ans=list(set(ans))
ans.sort()
print(ans[k-1])

Solution (Python):
s = input()
K = int(input())
substrings = {s[i:j]:0 for i in range(len(s)) for j in range(i+1, min(i+1+K, len(s)+1))}
print(sorted(substrings)[K-1])

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

cand = []
for i in range(len(s)):
    for j in range(1, k+1):
        if i + j <= len(s):
            cand.append(s[i:i+j])

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

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

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

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

result=[]

def substring(l):
    result.append(l)
    if len(result) < k:
        for m in list:
            if l+m in s:
                return substring(l+m)
            else:
                pass
for l in list:
    substring(l)
print(result[k-1])

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

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

for l in li:
    substring(l)

print(result[K-1])

Solution (Python):
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(input())])

Solution (Python):
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(input())])

Solution (Python):
s=input();print(sorted({s[I//6:I//6+I%6]for I in range(len(s)*6)})[int(input())])

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

length = len(s)
sub = []
for item in "abcdefghijklmnopqrstuvwxyz":
  if item in s:
    for i, c in enumerate(s):
      if c == item:
        for j in range(0,length - i + 1):
          if j > 5:
            break
          if j==0:
            if s[i] not in sub:
              sub.append(s[i])
          else: 
            if s[i:i+j] not in sub:
              sub.append(s[i:i+j])
    if len(sub) >= k:
      break
print(sorted(sub)[k-1])

Solution (Python):
def su(a,s,K):
    for i in range(1,K+1):
        for j in range(len(s)-i+1):
            a.add(s[j:j+i])
    a = sorted(a)
    return(a)
    
s = input()
K = int(input())
a = set([])
a = su(a,s,K)
print(a[K-1])

Solution (Python):
S = input()
k = int(input())
A = set()
for l in range(k+1):
	for i in range(len(S)-l):
			A.add(S[i:i+l+1])
A = sorted(list(A))
print(A[k-1])

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

l = set()

for i in range(1, 6):
    l |= set([s[n:n+i] for n in range(len(s))])

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

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

b = set()

for i in range(0, len(s)):
    for j in range(1, k + 1):
        if i + j <= len(s):
            b.add(s[i:i+j])

b = sorted(list(b))

print(b[k - 1])

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

s = input()
K = I()



combis = []
for i in range(1, K+1):
    start = 0
    while start+i <= len(s):
        combi = s[start:start+i]
        combis.append(combi)
        start += 1

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

Solution (Python):
S=input()
K=int(input())
chars=sorted(list(set(list(S))))
strings=set()

for c in chars:
  if len(strings)>=5:
    break
  for i in range(len(S)):
    if S[i]==c:
      for j in range(5):
        if i+j<=len(S):
          strings.add(S[i:i+j+1]) 
          
print(sorted(list(strings))[K-1])

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


l=sorted(set(l))

print(l[K-1])

Solution (Python):
s = input()
k = int(input())
lst = []
start = 0
end = 1
while start < len(s):
    while end - start <= 5:
        lst.append(s[start:end])
        end += 1
    start += 1
    end = start +1
lst.append(s[-1])

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

Solution (Python):
s = input()
K = int(input())
length = len(s)

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


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

Solution (Python):

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")


def A():
    return


def B():
    return


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


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    C()

Solution (Python):
S = input()
K = int(input())
lst = []
for k in range(1, K + 1):
    for i in range(len(S) - k + 1):
        lst.append(S[i:i+k])
print(sorted(set(lst))[K-1])

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

def LI():  
    
    return int(input())
def LIS():  
    
    return [int(x) for x in input().split()]
def MLIS(n):  
    
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  
    
    return input()
def LCS(): 
    
    return [x for x in input().split()]
def MLCS(n): 
    
    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(1, 6):
            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()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    s = input()
    k = I()
    l = []
    n = len(s)
    alp = list("abcdefghijklmnopqrstuvwxyz")
    for i in alp:
        for j in range(n):
            if s[j] == i:
                l.append(s[j])
                for m in range(j+1,min(j+k,n)):
                    l.append(s[j:m+1])
        l = sorted(list(set(l)))
        if len(l) >= k:break
    print(l[k-1])

def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

Solution (Python):
s = str(input())
K = int(input())
stack = []
for i in range(len(s)):
    for j in range(i+1, min(i+K, len(s))+1):
        sub = s[i:j]
        stack.append(sub)
stack = sorted(set(stack))
print(stack[K-1])

Solution (Python):
s = str(input())
K = int(input())
stack = []
for i in range(len(s)):
    for j in range(i+1, min(i+K, len(s))+1):
        sub = s[i:j]
        if sub not in stack:
            stack.append(sub)
stack.sort()
print(stack[K-1])

Solution (Python):
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars[:3]:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars[:3]:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
from collections import Counter


def solve(string):
    s, k = string.split()
    k = int(k)
    count = Counter(s)
    chars = sorted(set(s))
    for t in range(min(3, len(chars))):
        tmp = []
        i = s.index(chars[t])
        tmp.append(s[i:i + k])
        if count[chars[t]] > 1:
            for _ in range(count[chars[t]] - 1):
                i = s.index(chars[t], i + 1)
                tmp.append(s[i:i + k])
        g = []
        for p in tmp:
            for j in range(1, len(p) + 1):
                g.append(p[:j])
        g = sorted(set(g))
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
from collections import Counter


def solve(string):
    s, k = string.split()
    k = int(k)
    count = Counter(s)
    chars = sorted(set(s))
    for t in range(min(3, len(chars))):
        tmp = []
        i = s.index(chars[t])
        tmp.append(s[i:i + 5])
        if count[chars[t]] > 1:
            for _ in range(count[chars[t]] - 1):
                i = s.index(chars[t], i + 1)
                tmp.append(s[i:i + 5])
        g = []
        for p in tmp:
            for j in range(1, len(p) + 1):
                g.append(p[:j])
        g = sorted(set(g))
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
from collections import Counter


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]
    """
    k = int(k)
    count = Counter(s)
    chars = sorted(set(s))
    for t in range(min(3, len(chars))):
        tmp = []
        i = s.index(chars[t])
        tmp.append(s[i:i + 5])
        if count[chars[t]] > 1:
            for _ in range(count[chars[t]] - 1):
                i = s.index(chars[t], i + 1)
                tmp.append(s[i:i + 5])
        g = []
        for p in tmp:
            for j in range(1, len(p) + 1):
                g.append(p[:j])
        g = sorted(set(g))
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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

d = dict()
SET = set()
for i in range(len(s)):
    if not d.__contains__(s[i]):
        d[s[i]] = []
    d[s[i]].append(i)


alphabet = 'abcdefjhijklmnopqrstuvwxyz'

for c in alphabet:
    if not d.__contains__(c):
        continue
    l = d[c].copy()
    SET.add(c)
    if(len(SET) >= K):
        break
    tmp = []
    for idx in l:
        if idx+1>=len(s):
            continue
        tmp.append((idx,s[idx+1:len(s)]))
    tmp.sort(key = lambda x:x[1])
    for idx,nxt in tmp:
        for step in range(2,len(s)+1):
            if idx+step>len(s):
                break
            if s[idx:idx+step] not in SET:
                SET.add(s[idx:idx+step])
                if len(SET) >= K:
                    break
        if len(SET) >= K:
            break
    if len(SET) >= K:
         break

res = list(SET)
res.sort()
print(res[K-1])

Solution (Python):
s = input()
sLen = len(s)
K = int(input())

result = set()
for i in range(sLen):
    for j in range(1, K + 1):
        if i + j > sLen:
            break
        ss = s[i:i+j]
        result.add(ss)
print(sorted(result)[K - 1])

Solution (Python):


import sys

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

i_r = 0
k_str = []
nm = 0
for i_l in range(len(s)):
  i_r = i_l+1
  while i_r <= len(s):
    nm += 1
    if len(k_str) < k:
      k_str.append(s[i_l:i_r])
      k_str = sorted(k_str)
    elif (s[i_l:i_r] not in k_str) and (k_str[-1] >= s[i_l:i_r]):
      k_str[-1] = s[i_l:i_r]
      k_str = sorted(k_str)

    if k_str[-1] < s[i_l:i_r]:
      i_r = len(s)
    i_r += 1

print(k_str[-1])

Solution (Python):

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

for i in range(len(s)+1):
	for j in range(i,i+6):
		substring.append(s[i:j])

		
sub = list(set(substring))
sub.remove('')
sub.sort()

print(sub[k-1])

Solution (Python):
s = raw_input()
K = input()

S = set()
for i in range(len(s)):
  for j in range(K):
    S.add(s[i:i+j+1])
print sorted(list(S))[K-1]

Solution (Python):



S = input()
K = int(input())
substrings = []
for i in range(1, min(len(S)+1, 6)):  
    for n in range(len(S) - i + 1):
        sub = S[n:n + i]
        if sub not in substrings:
            substrings.append(sub)

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

Solution (Python):


"""
Created on 2019/3/
Solved on 2019/3/
@author: shinjisu
"""






def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m)]*n 

def getIntMat(n, m):  
    
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def register(db, word):
    global K
    
    
    if word >= db[-1]:
        return -1
    else:
        for i in range(K):
            if word == db[i]:
                return 0
            elif word < db[i]:
                db[i+1:] = db[i:-1]
                db[i] = word
                break
    
    return 0
    
    
def prob():
    global K
    d = Debug()
    d.off()
    S = input()
    d.dmp(S)
    K = getInt()
    d.dmp(K)
    db = ['~' for i in range(K)]  
    for i in range(len(S)):
        for j in range(i, len(S)):
            if register(db, S[i:j+1]):
                break
    return db[-1]


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Solution (Python):
s = input()
k = int(input())
n = len(s)
dic = []
for i in range(n):
    for j in range(1, k + 1):
        if i + j > n:
            break
        if s[i:i+j] not in dic:
            dic.append(s[i:i+j])
dic.sort()
print(dic[k-1])

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

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

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


def main():
    st = set()

    for i in range(len(s)):
        for j in range(i + 1, min(i + K + 1, len(s) + 1)):
            st.add(s[i:j])

    l = sorted(st)

    print(l[K - 1])
    return


main()

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

diff = k - len(s)
if len(s) < k:
    k -= diff
else:
    diff = 0

l = []
for a in range(len(s) - k + 1):
    subsByK = s[a:a + k]
    
    for b in range(k):
        for c in range(b + 1, k + 1):
            
            subs = subsByK[b:c]
            l.append(subs)

print(sorted(set(l))[k - 1 + diff])

Solution (Python):
s = input()
K = int(input())
ab = 'abcdefghijklmnopqrstuvwxyz'
N = len(s)
substrings = set()
for i in ab:
    for l in range(N):
        if s[l] != i:
            continue
        for r in range(l,N):
            if r-l+1 > K:
                break
            substrings.add(s[l:r+1])
    if len(substrings) >= K:
        break
substrings = list(substrings)
substrings.sort()
print(substrings[K-1])

Solution (Python):
import bisect

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

alpha_list = [chr(i) for i in range(97, 97+26)] 
dic = []
for i in range(len(s)):
    dic = sorted(dic)
    if k < bisect.bisect_left(dic,s[i]):
        continue
    for j in range(i+1, min(i+6, len(s)+1)):
        s0 = s[i:j]
        
        if s0 not in dic:
            dic.append(s0)

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

Solution (Python):
def solve():
    s=input()
    K=int(input())
    words = set()
    ls = len(s)
    for i in range(ls):
        for j in range(i+1,min(i+6,ls+1)):
            words.add(s[i:j])
    words = sorted(list(words))
    return words[K-1]

print(solve())

Solution (Python):
s = input()
K = int(input())
lst = []

ssize = min(5,len(s))

for i in range(1 , ssize + 1):
    
    for j in range(len(s)-i+1):
        
        lst.append(s[j:i+j])


sset = set(lst)

llst = list(sset)

llst.sort()

print(llst[K-1])