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):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



s = input()
k = int(input())
n = len(s)
a = set()
for i in range(n):
    for j in range(1, k + 1):
        if i + j <= n:
            a.add(s[i : i + j])
b = list(a)
b.sort()

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

Solution (Python):
def main():
    s = input()
    k = int(input())
    d = len(s)
    m = set()
    for i in range(d):
        for j in range(1, k + 1):
            m.add(s[i:i + j])

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input()
    k = int(input())
    d = len(s)
    m = set()
    if k >= d:
        for i in range(d):
            for j in range(1, d - i + 1):
                m.add(s[i:i + j])
    else:
        for i in range(d):
            for j in range(1, k + 1):
                m.add(s[i:i + j])

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input()
    k = int(input())
    d = len(s)
    m = set()
    if k >= d:
        for i in range(d + 1):
            for j in range(1, d - i + 1):
                m.add(s[i:i + j])
    else:
        for i in range(d):
            for j in range(1, k + 1):
                m.add(s[i:i + j])

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


if __name__ == '__main__':
    main()

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

Solution (Python):
def abc097_c():
    S = str(input())
    K = int(input())
    subs = set()

    for l in range(1, K+1):
        for i in range(len(S)):
            subs.add(S[i: i+l])
            

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

abc097_c()

Solution (Python):
def abc097_c():
    S = str(input())
    K = int(input())
    subs = set()

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

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

abc097_c()

Solution (Python):
def solve():
    S = input()
    K = int(input())

    N = len(S)

    st = set()

    for left in range(N):
        for right in range(left+1,N+1):
            if right - left > K:
                break
            st.add(S[left:right])
    
    tmp = list(st)
    tmp.sort()
    print(tmp[K-1])

if __name__ == '__main__':
    solve()

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

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

anslist = sorted(list(ansset))

print(anslist[k-1])

Solution (Python):
s = input()
K = int(input())
d = list()
for l in range(len(s)):
  for r in range(l,min(l+K+1, len(s))):
    n = s[l:r+1]
    if n not in d:
      d.append(n)
    d.sort()
    d = d[:5]
print(d[K-1])

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


def dfs(sub, i):
  if sub in s:
    i += 1
    if i == k:
      print(sub)
      exit()
    for c in range(ord('a'), ord('z') + 1):
      c = chr(c)
      i = dfs(sub + c, i)
  return i
  
dfs('', -1)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    s=readline().strip()
    K=int(readline())

    N=len(s)
    words=[]
    for i in range(N):
        words.append(s[i])
    for i in range(N-1):
        words.append(s[i:i+2])
    for i in range(N-2):
        words.append(s[i:i+3])
    for i in range(N-3):
        words.append(s[i:i+4])
    for i in range(N-4):
        words.append(s[i:i+5])
    words=set(words)
    words=list(words)
    words.sort()
    print(words[K-1])
    
if __name__=="__main__":
    main()

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

Solution (Python):
s=input()
k=int(input())
l=[]
n=len(s)

for i in range(n):
  if n+1>=i+6:
    l+=[s[i:j] for j in range(i+1,i+6)]
  else:
    l+=[s[i:j] for j in range(i+1,n+1)]

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

Solution (Python):
import string
s = input()
k = int(input())
d=set()
for sp in string.ascii_lowercase:
  for i,sd in enumerate(s,start=0):
    if sp == sd:
      e=set()
      for l in range(1, 6):
        if i+l > len(s):
          break
        e.add(s[i:i+l])
      d=d|e
  if len(d) >= k:
    break

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

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

s = list(s)
ans = []
for i in range(n + 1):
    for j in range(i + 1, min(i + 1 + k, n + 1)):
        ans.append(str(''.join(s[i:j])))

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007



class dd:
	def __init__(self, k):
		d='zzzzzz'
		self.v = [d]*k
		
		
		
	def add(self, v):
		if v in self.v:
			pass
		elif self.v[-1] <= v:
			pass
		else:
			for i,c in enumerate(self.v):
				if v < c:
					self.v = self.v[:i]+[v]+self.v[i:-1]
					break
		
				
	def get(self):
		return self.v[-1]


def main():
	
	
	s = input()
	k = int(input())
	rs=dd(k)
	for i in range(1, 5+1):
		for j in range(len(s)-i+1):
			v = s[j:j+i]
			rs.add(v)
			
	r=rs.get()
	print(r)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

se = set()
for L in range(1,K+1):
  for i in range(len(s)):
    se.add(s[i:i+L])

    
li = list(se)
li.sort()
print(li[K-1])

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

x = set()
n = len(s)

for i in range(k):
    for j in range(n-i):
        t = s[j:j+i+1]
        if not t in x:
            x.add(t)
x = list(x)
x.sort()
print(x[k-1])

Solution (Python):
s=input()
k=int(input())
print(sorted(list({s[i:i+f] for i in range(len(s)) for f in range(1,k+1)}))[k-1])

Solution (Python):









def main():
    S = input()
    N = len(S)
    K = int(input())

    def rec(tree, substr):
        if len(substr) > 0:
            ans.append(substr)

        if len(ans) == K:
            return None

        keys = sorted(tree.keys())
        for key in keys:
            rec(tree[key], substr+key)
    
    min_char_list = sorted(list(set(S)))

    ans = []
    for min_char in min_char_list:
        if len(ans) >= K:
            break

        min_char_i = []
        for i, s in enumerate(S):
            if s == min_char:
                min_char_i.append(i)

        substrs = []
        for i in min_char_i:
            substrs.append(S[i:min(i+(K-len(ans)), N)])

        prefix_tree = {}
        for substr in substrs:
            tree = prefix_tree
            for c in substr:
                if c not in tree:
                    tree[c] = {}
                tree = tree[c]

        

        rec(prefix_tree, "")

    return ans[K-1]


print(main())

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

x = set(list(S))

for i in range(K):
  for j in range(N-i):
    x.add(S[j:j+i+1])

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

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

target_ls = []
for start in range(len(s)):
    for length in range(1,k+1):
        target_ls.append(s[start:start + length])
unique_ls = list(set(target_ls))
unique_ls.sort()
print(unique_ls[k-1])

Solution (Python):
s = input()
k = int(input())
x = set()
n = len(s)
for i in range(k):
    for j in range(n-i):
        t = s[j:j+i+1]
        if not t in x:
            x.add(t)
x=list(x)
x.sort()
print(x[k-1])

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

Solution (Python):
S = input().strip()
K = int(input())

L = set(list(S))

for j in range(1, 5):
    for i in range(len(S)-j):
        L.add(S[i:i+j+1])

tmp = list(L)
tmp.sort()
print(tmp[K-1])

Solution (Python):
import sys
readline = sys.stdin.readline

def main():
    S = readline().rstrip()
    K = int(readline())
    N = len(S)
    d = {}
    for i in range(N):
        s = ''
        head = S[i]
        d.setdefault(head, set())
        for j in range(i, min(N, i+5)):
            s += S[j]
            d[head].add(s)

    for key, val in sorted(d.items()):
        if K <= len(val):
            print(sorted(list(val))[K-1])
            return
        else:
            K -= len(val)


if __name__ == '__main__':
    main()

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

sb=set()
for i in range(len(s)):
    for ii in range(i,i+k):
        if ii<len(s):

            sb.add(s[i:ii+1])
sb2=list(sb)
sb2.sort()
print(sb2[k-1])

Solution (Python):
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=input()
    K=int(input())
    l=[]
    for i in range(len(s)):
        for j in range(1,K+1):
            if i+j>len(s):
                continue
            l.append(s[i:i+j])
    l=list(set(l))
    l.sort()
    print(l[K-1])

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
k=int(input())
st=[[] for i in range(26)]
n=len(s)
for i in range(n):
    st[ord(s[i])-97].append(i)

pre=0
now=set()
for i in st:
    for v in i:
        for c in range(v+1,min(n+1,v+6)):
            now.add(s[v:c])
    if len(now)+pre<k:pre+=len(now);now=set()
    else:
        print(sorted(list(now))[k-pre-1]);exit()

Solution (Python):
import sys
input = sys.stdin.readline
s = input().rstrip()
l = len(s)
k = int(input())
chk = set()
for i in range(26):
  for j in range(l):
    if s[j] == chr(i+97):
      for m in range(min(5,l-j)):
        chk.add(s[j:j+1+m])
  if len(chk) >= k:
    break
    
chk = sorted(list(chk))
print(chk[k-1])

Solution (Python):
s = input()
k = int(input())
a = set()
for i in range(len(s)+1):
    for j in range(i, min(i+6, len(s)+1)):
        a.add(s[i:j])
print(sorted(a)[k])

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

ss = set()
n = len(s)
for x in range(1, K + 1):
    for i in range(n):
        ss.add(s[i : i + x])
print(sorted(ss)[K - 1])

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()

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

N = len(s)
subst = set()
for i in range(N):
    for j in range(1,K+1):
        subst.add(s[i:min(i+j, N)])
print(sorted(subst)[K-1])

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

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

Solution (Python):

import sys


def solve(s: str, K: int):
    n = len(s)
    ss = {
        s[i:j]
        for i in range(n)
        for j in range(i + 1, min(n + 1, i + K + 1))
    }
    print(sorted(ss)[K - 1])
 

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


data = input()

qwe = int(input())

dic = set()

for i in range(len(data)):
    for j in range(qwe):
        if i+j+1 <= len(data):
            dic.add(data[i:i+j+1])
di = list(dic)
di.sort()
print(di[qwe-1])

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

if __name__ == '__main__':
  main()

Solution (Python):
from bisect import *
s = str(input())
K = int(input())
ls = len(s)
l = []
for i in range(ls):
  for j in range(i+1,i+K+2):
    l.append(s[i:j])

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

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))


s = ns()
k = ni()

check = set()

for left in range(0, len(s)):
    for right in range(left+1, left+k+1):
        check.add(s[left:right])

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

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))


s = ns()
k = ni()

check = set()

for left in range(0, len(s)):
    for right in range(left+1, left+k+1):
        check.add(s[left:right])

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

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    s = ns()
    k = ni()

    check = set()

    for left in range(0, len(s)):
        for right in range(left+1, left+k+1):
            check.add(s[left:right])
    
    print(sorted(list(check))[k-1])

if __name__ == '__main__':
    main()

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    s = ns()
    k = ni()

    check = set()

    for left in range(0, len(s)):
        for right in range(left+1, left+k+1):
            check.add(s[left:right])
    
    print(sorted(list(check))[k-1])

if __name__ == '__main__':
    main()

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

Solution (Python):
s = input()
k = int(input())
n = len(list(s))
kouho = set()
for i in range(n):
    for d in range(1, k + 1):
        if i + d <= n:
            kouho.add(s[i : i + d])
ans = list(kouho)
ans.sort()

print(ans[k - 1])

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

lS = len(S)
asc = 97
while True:
    st = set()
    for i in range(lS):
        if S[i] == chr(asc):
            j = i + 1
            while j - i <= 5 and j <= lS:
                st.add(S[i:j])
                j += 1
    if len(st) >= K:
        print(sorted(list(st))[K - 1])
        break
    else:
        K -= len(st)
        asc += 1

Solution (Python):
s = input()
N = len(s)
K = int(input())
ss = []
for i in range(N):
    for j in range(1,6):
        if  i+j <= N:
            ss.append(s[i:i+j])

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

Solution (Python):
s = input()
k = int(input())
n = len(list(s))
kouho = set()
for i in range(n):
    for d in range(1, k + 1):
        if i + d <= n:
            kouho.add(s[i : i + d])
ans = list(kouho)
ans.sort()

print(ans[k - 1])

Solution (Python):
import sys

s, k = sys.stdin.read().split()
k = int(k)

def main():
    cand = set()
    for j in range(1, k + 1):
        for i in range(len(s) - j + 1):
            cand.add(s[i:i+j])
    print(sorted(cand)[k-1])

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    s = IS()
    k = II()
    subs = []
    n = len(s)
    for i in range(k):
        for j in range(n-i):
            subs.append(s[j:j+(i+1)])
    subs = sorted(list(set(subs)))
    print(subs[k-1])

if __name__ == '__main__':
    main()

Solution (Python):




mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    k = int(input())
    
    
    
    
    
    
    
    r = []
    for i in range(1,6): 
        for j in range(len(s) - i + 1): 
            r.append(s[j:j+i])
    
    print(sorted((set(r)))[k-1])


if __name__ == '__main__':
  main()

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


substrings = set()
for i in range(len(s)):
    for j in range(1, K+1):
        substrings.add(s[i:i+j])

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

Solution (Python):

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


substrings = set()
for i in range(len(s)):
    for j in range(1, K+1):
        substrings.add(s[i:i+j])

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

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

s_sorted = sorted(s)
array = set()

n = len(s)
for i in range(n):
  for j in range(n):
    if s_sorted[i] == s[j]:
      for l in range(k):
        if l+j >= n:
          break
        
        array.add(s[j:l+j+1])
      
  if len(array) >= k:
    break
    
array = sorted(array)
print(array[k-1])

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

s1list=[]
for i in range(len(s)):
  s1list.append((s[i],i))
s1list.sort()


cold=s1list[0][0]
sset=set()
for i in range(len(s1list)):
  c1,index=s1list[i]
  if cold!=c1 and len(sset)>=5:
    break
  else:
    cold=c1
  
  for j in range(5):
    sub=s[index:index+j+1]
    sset.add(sub)
    
slist=list(sset)
slist.sort()
print(slist[K-1])

Solution (Python):
def main():
    s = input()
    k = int(input())
    n = len(s)
    ans = set()
    for i in range(n):
        for j in range(i+1, i+k+1):
           ans |= {s[i:j]}
    print(list(sorted(ans))[k-1])

if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    for i in range(1, K+1): 
        for j in range(len(s)): 
            subs = s[j:j+i]
            if subs not in mem:
                mem.append(subs)
    mem.sort()
    
    print(mem[K-1])
    
    
if '__main__' == __name__:
    resolve()

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

for i in range(len(s)):
    for j in range(i + 1, i + 1 + k):
        subs = s[i: j]
        res.add(subs)

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

Solution (Python):
s = input()
k = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
n = len(s)
lis = set()
for i in range(26):
    for j in range(len(s)):
        if s[j] == alpha[i]:
            for l in range(j, j+k+1):
                if l < n:
                    lis.add(s[j:l+1])
lis = list(lis)
lis.sort()


print(lis[k-1])

Solution (Python):
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

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

for i in range(len(s)):
    for j in range(5):
        end = i+j+1
        if end > len(s):
            break
        strings.add(s[i:end])

strings = sorted(list(strings))


print(strings[k-1])

Solution (Python):
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
k = int(input())
d = 'abcdefghijklmnopqrstuvwxyz'
n = len(s)
lis = set()
for i in range(26):
    for j in range(len(s)):
        if s[j] == d[i]:
            for l in range(j, j+k+1):
                if l < n:
                    lis.add(s[j:l+1])
lis = list(lis)
lis.sort()


print(lis[k-1])

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
k = inp()
n = len(s)
t = []
for i in s:
    t.append(ord(i) - ord('a'))
se = set()
for i in range(26):
    for j in range(n):
        if t[j] == i:
            for l in range(j,min(j+k,n)):
                tmp = s[j:l+1]
                if tmp == '':
                    continue
                se.add(tmp)
    if len(se) >= k:
        break
res = sorted(list(se))
print(res[k-1])

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

lst=[]
for length in range(1,K+1):
    for start in range(len(s)-length+1):
        lst.append(s[start:start+length])

lst=sorted(list(set(lst)))

print(lst[K-1])

Solution (Python):
s=list(input())
K=int(input())
substring=set()
alphabet=list('abcdefghijklmnopqrstuvwxyz')
l=0
while len(substring)<K:
    x=alphabet[l]
    l+=1
    for i in range(len(s)):
        if s[i]==x:
            string=s[i]
            substring.add(string)
            for k in range(1,5):
                try:
                    string+=s[i+k]
                    substring.add(string)
                except:
                    pass
ans=sorted(list(substring))
print(ans[K-1])

Solution (Python):
s=str(input())
k=int(input())
ans=[]
for i in range(len(s)):
    for j in range(i+1,i+k+1):
        ans.append(s[i:j])

ans=sorted(list(set(ans)))

print(ans[k-1])

Solution (Python):
s=input()
l=len(s)
k=int(input())
alp=[chr(i) for i in range(97, 97+26)]
ans=set()
for i in range(26):
    for j in range(l):
        if s[j]==alp[i]:
            for m in range(j,min(l,j+k)):
                ans.add(s[j:m+1])
    if len(ans)>=k:
        break
print(sorted(list(ans))[k-1])

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    k = int(input().strip())
    n = len(s)
    strs = set()
    for i in range(n):
        for j in range(1, k+1):
            strs.add(s[i:min(i+j, n)])
    strs = list(strs)
    
    print(sorted(strs)[k-1])


if __name__ == '__main__':
    main()

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

Solution (Python):
list_S = list(input())
k = int(input())
set_ANS = set()
list_Alph = list(set(list_S))
cnt = 0
list_Alph.sort()

for c in list_Alph:
    q = [i for i, x in enumerate(list_S) if x == c]
    list_M = []
    for i in q:
        l = "".join(list_S[i:])
        list_M.append(l)
    list_M.sort()
    for s in list_M:
        m = list(s)
        for j in range(1,len(m)+1):
            b = "".join(m[:j])
            if b not in set_ANS:
                set_ANS.add(b)
                cnt += 1
                if cnt == k:
                    print(b)
                    exit()

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

import collections
S_count = collections.Counter(S)

ans_list = set()

for key in S_count:
    for idx, s in enumerate(S):
        if s == key:
            short_S = S[idx:min(idx+5, len(S))]
            append_s = ""
            for s in short_S:
                append_s += s
                ans_list.add(append_s)
    if len(ans_list) >= 5:
        break

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

Solution (Python):
def main():
    s = input()
    k = int(input())
    ss = set()
    sss = sorted(s)
    for i in range(len(s)):
        for j in range(i+1, i+6):
            ss |= {s[i:j]}
    print(sorted(ss)[k-1])

if __name__ == "__main__":
    main()

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

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

Solution (Python):
S=input()
K=int(input())
l = []
for alpha in [chr(i) for i in range(97, 97+26)]:
  indexs = [k for k, v in enumerate(list(S)) if v == alpha]
  for index in indexs:
    for j in range(index,min(index+6,len(S)+1)):
      sub_s = S[index:j]
      l.append(sub_s)
  l = sorted(list(set(l)))
  if '' in l:
    l.remove('')
  if len(l) >= K:
    break
print(l[K-1])

Solution (Python):
import math
import collections
from operator import mul
from functools import reduce
import bisect



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

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

Solution (Python):
s = input()
k = int(input())
t = sorted(s)[min(k-1,len(s)-1)]
data = []
for i in range(len(s)):
    if s[i] <= t:
        data.append(s[i:])
data.sort()
if len(data) > k:
    data = data[:k]

ndata = []
for ss in data:
    for i in range(len(ss)):
        ndata.append(ss[:i+1])
ndata = list(set(ndata))
ndata.sort()
print(ndata[k-1])