Problem:


Score : 300 points

Problem Statement

You are given a string s.
Among the different substrings of s, print the K-th lexicographically smallest one.

A substring of s is a string obtained by taking out a non-empty contiguous part in s.
For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.
Also, we say that substrings are different when they are different as strings.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 ≤ |s| ≤ 5000

s consists of lowercase English letters.

1 ≤ K ≤ 5

s has at least K different substrings.

Partial Score

200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.

Input

Input is given from Standard Input in the following format:

s
K

Output

Print the K-th lexicographically smallest substring of K.

Sample Input 1

aba
4

Sample Output 1

b

s has five substrings: a, b, ab, ba and aba.
Among them, we should print the fourth smallest one, b.
Note that we do not count a twice.

Sample Input 2

atcoderandatcodeer
5

Sample Output 2

andat

Sample Input 3

z
1

Sample Output 3

z



Sample input:
aba
4


Sample output:
b

Submission status: Wrong Answer

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    s = input()
    k = intin()

    nlist = [(ord(c), i) for i, c in enumerate(s)]
    nlist.sort()

    prev_oc = None
    slist = []
    kcount = 0

    for oc, i in nlist:
        loopcount = min(k, len(s) - i)
        for j in range(loopcount):
            slist.append(s[i:(i+j+1)])
        kcount += loopcount
        if prev_oc is not None and oc != prev_oc and kcount >= k:
            break
        prev_oc = oc

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
s = input()
K = int(input())

l = {s}
for n in range(1, K+1):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])
    print(l)
l = list(l)

l.sort()

print(l[K-1])

Submission status: Wrong Answer

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()
print(a[k-1])

Submission status: Wrong Answer

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

l = {s}
for n in range(1, K):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])

l = list(l)

l.sort()

print(l[K-1])

Submission status: Wrong Answer

Solution code:
#coding: utf-8
s = input()
K = int(input())
l = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        l.append(s[i:j])
l = list(set(l))
print(l[K-1])

Submission status: Wrong Answer

Solution code:
s,k=open(0);print(sorted({s[I//6:I//6+I%6]for I in range(30000)})[int(k)])

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=[]
for i in range(len(s)):
  for j in range(min(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])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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+1):
            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: Wrong Answer

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 = ["z"*5 for i in range(5)]
    for k in range(len(s)):
        for i in range(1,len(s) - k + 1):
            #print(s[k:k + i], k , i)
            for l in range(5):
                if s[k:k + i] in ans:
                    break
                if ans[l] > s[k:k + i]:
                    ans[l] = s[k:k + i]
                    break
                    
    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: Wrong Answer

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

    def dfs(base):
        exists.append(base)
        print(exists)
        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()])))

Submission status: Wrong Answer

Solution code:
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))
        print(g)
        if len(g) < k:
            k -= len(g)
            continue
        return g[k - 1]


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# /user/bin/python
# -*- coding: utf-8 -*-
import sys

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

k_str = []
k_str = sorted(k_str)

for i in range(len(s)):
  for j in range(i+1, len(s)+1):
    if len(k_str) < k:
      k_str.append(s[i:j])
    elif (s[i:j] not in k_str) and (k_str[-1] >= s[i:j]):
      k_str[-1] = s[i:j]
      k_str = sorted(k_str)

print(k_str[-1])

Submission status: Wrong Answer

Solution code:
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):
            substrings.add(s[l:r+1])
            if len(substrings) >= K:
                break
        if len(substrings) >= K:
            break
    if len(substrings) >= K:
        break
substrings = list(substrings)
substrings.sort()
print(substrings[K-1])

Submission status: Wrong Answer

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,len(s)):
            string+=s[i]
            ret.add(string)
    return ret

if (len(s)<51):
	a=rec(s)
	print(sorted(a)[K-1])
else:
    print("部分点希望")

Submission status: Wrong Answer

Solution code:
str_s = input()
int_k = int(input())

result = list()

if len(str_s) == 1:
    print(str_s)
else:

    for f in range(len(str_s)):
        if len(result) == int_k and str_s[f] > result[-1][0]:
            continue
        pattern = set()
        for t in range(f + 1, len(str_s)):
            pattern.add(str_s[f:t])
        result = list(sorted(set(result + list(pattern))))[:5]

    print(result[-1])

Submission status: Wrong Answer

Solution code:
a=list(input())
b=int(input())
l=[]
for t in range(len(a),0,-1):
  for s in range(len(a)):
    l.append("".join(a[s:s+t]))
print(sorted(set(l),key=lambda x:len(x))[-b])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

L = []
L.append(s)
for aaa in "abcdefghijklmnopqrstuvwxyz":
    for i in range(len(s)):
        if s[i] != aaa:
            continue
        for j in range(1,len(s)):
            if i + j >= len(s):
                break
            L.append(s[i:i+j])
    if len(set(L)) >= K:
        L = sorted(set(L))
        print(L[K-1])
        exit()

Submission status: Wrong Answer

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(cand)
print(cand[K-1])

Submission status: Wrong Answer

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(len(s)+1):
  for j in range(K):
    if len(s[j:j+i])>0:
      dic.add(s[j:j+i])

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

Submission status: Wrong Answer

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

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


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

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

d = {}
for i in range(len(S)):
    for j in range(i+1,i+K+1):
        s = S[i:j]
        if s in d.keys():
            pass
        else:
            d[s] = 0

d = sorted(d.keys())
print(d)

Submission status: Wrong Answer

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 and len(element[0]) <= 4:
        next_element = (element[0] + s[element[1] + 1], element[1] + 1)
        boundary.append(next_element)
  if len(boundary) == 0:
    if pointer + 1 >= len(ch):
      break
    pointer += 1
    if s.find(ch[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: Wrong Answer

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:
    if pointer + 1 >= len(ch):
      break
    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: Wrong Answer

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

subs = set()

ds = {}
for i, c in enumerate(s):
  if c in ds:
    ds[c].append(i)
  else:
    ds[c] = [i]

for c, il in sorted(ds.items(), key=lambda x: x[0]):
  print(c, il)
  subs |= set([c])
  i = 2
  while il[0]+i <= len(s):
    for j in il:
      if j + i > len(s):
        break
      subs.add(s[j:j+i])
    i += 1
  if len(subs) >= k:
    break
print(list(sorted(subs))[k-1])

Submission status: Wrong Answer

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

dic = []

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

dic = (list)(set(dic))
dic.sort()

print(dic[k-1])

Submission status: Wrong Answer

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

dic = []

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

dic = (list)(set(dic))
dic.sort()
print(dic)

print(dic[k-1])

Submission status: Wrong Answer

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

dic = []

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

dic = (list)(set(dic))
dic.sort()

print(dic[k-1])

Submission status: Wrong Answer

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

#正解(全列挙してソートしてる)
sub_string=[]
for i in range(len(s)):
  for j in range(1,k+1):
    string = s[i:i+j]
    if string not in sub_string:
      sub_string.append(string)
sub_string.sort()
print(sub_string)

Submission status: Wrong Answer

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

a = min(s)
if k == 1:
  print(a)
  exit()

indexes = [i for i, x in enumerate(s) if x == a]

b='z'*5001

for i in indexes:
  if i + 1 < len(s):
    if s[i]+s[i+1] < b:
      b = s[i]+s[i+1]
      index = i
if k == 2:
  print(b)
  exit()

if len(s) < k:
  a=min([i for i in s if i != a])
  print(s[s.index(a):k-len(s)+1])
  exit()
elif len(s[index:index+k]) < k:
  a=min([i for i in s if i != a])
  print(s[s.index(a)]+(s[index:index+(k-len(s[index:index+k]))-1]))
else:
  print(s[index:index+k])

Submission status: Wrong Answer

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

a = min(s)
if k == 1:
  print(a)
  exit()

indexes = [i for i, x in enumerate(s) if x == a]

b='z'*5001

for i in indexes:
  if i + 1 < len(s):
    if s[i]+s[i+1] < b:
      b = s[i]+s[i+1]
      index = i
if k == 2:
  print(b)
  exit()

if len(s) < k:
  a=min([i for i in s if i != a])
  print(s[s.index(a):k-len(s)+1])
  exit()
elif len(s[index:index+k]) < k:
  a=min([i for i in s if i != a])
  print(s[s.index(a):k-len(s[index:index+k])])
else:
  print(s[index:index+k])

Submission status: Wrong Answer

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

a = min(s)
if k == 1:
  print(a)
  exit()

indexes = [i for i, x in enumerate(s) if x == a]

b='z'*5001

for i in indexes:
  if i + 1 < len(s):
    if s[i]+s[i+1] < b:
      b = s[i]+s[i+1]
      index = i
if k == 2:
  print(b)
  exit()

if len(s) < k:
  a=min([i for i in s if i != a])
  print(s[s.index(a):k-len(s)+1])
  exit()

print(s[index:index+k])

Submission status: Wrong Answer

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

a = min(s)
if k == 1:
  print(a)
  exit()

indexes = [i for i, x in enumerate(s) if x == a]

b='z'*5001

for i in indexes:
  if i + 1 < len(s):
    if s[i]+s[i+1] < b:
      b = s[i]+s[i+1]
      index = i
if k == 2:
  print(b)
  exit()

if len(s) < k:
  print(s[indexes[0]+1:k-len(s)+1])
  exit()

print(s[index:index+k])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
ans = []
for i in set(s):
    ans.append(i)

if K == 1:
    print(sorted(ans)[0])
else:
    for i in range(2, 6):
        for j in range(len(s) - i + 1):
            ans.append(s[j:j+i])
    ans.sort()
    print(ans[K - 1])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
ans = []
for i in set(s):
    ans.append(i)

if K == 1:
    print(ans[0])
else:
    for i in range(2, 6):
        for j in range(len(s) - i +1):
            ans.append(s[j:j+i])
    ans.sort()
    print(ans[K - 1])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
one = list(set(s))
check = 2
if len(s) >= 2:
    while check <= len(s) and check <= 5:
        for i in range(len(s) - check + 1):
            one.append(s[i:i+check])
        check += 1
    one = sorted(one)
    print(one[K-1])
    
     
else:
    one = sorted(one)
    print(one[K-1])

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
one = list(set(s))
check = 2
if len(s) >= 2:
    while check <= len(s):
        for i in range(len(s) - check + 1):
            one.append(s[i:i+check])
        check += 1
    one = sorted(one)
    print(one[K-1])
    
     
else:
    one = sorted(one)
    print(one[K-1])

Submission status: Wrong Answer

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

t = len(s)
u = []
u2 = []
"""for i in range(t):
    u.append([])"""
for i in range(5):
    u.append([])

for j in range(5):
    for i in range(t):
        u[j].append([])

for i in range(t):
    u2.append([])


for j in range(5):
    for i in range(t):
        if j == 0:
            if s[i] not in u2[j]:
                u[j][i].append(s[i])
                u2[j].append(s[i])
                u[j][i].append(i)
        elif j == 1:
            if i + 1 < t:
                if s[i] + s[i + 1] not in u2[j] and s[i] + s[i + 1] not in u2[j - 1]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1])
                            u2[j].append(s[i] + s[i + 1])
                            u[r][i].append(i)
                            break
        elif j == 2:
            if i + 2 < t:
                if s[i] + s[i + 1] + s[i + 2] not in u2[j] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 1] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 2]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2])
                            u[r][i].append(i)
                            break
        elif j == 3:
            if i + 3 < t:
                if s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 1] \
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 2] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 3]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
                            u[r][i].append(i)
                            break
        elif j == 4:
            if i + 4 < t:
                if s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 1]\
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 2]and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 3]\
                        and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 4]:
                    for r in range(j + 1):
                        if u[r][i] == []:
                            u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])
                            u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])
                            u[r][i].append(i)
                            break
    """for i in range(t):
    for j in range(k):
        if j == 0:
            u[i].append(s[i])
        elif j == 1:
            u[i].append(s[i] + s[i + 1])
        elif j == 2:
            u[i].append(s[i] + s[i + 1] + s[i + 2])
        elif j == 3:
            u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3])
        elif j == 4:
            u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])"""
p = [0] * t
n = "z"
m = -1
l = -1
for i in range(5):
    for j in range(t + 5):
        if j < len(u[0]):
            if u[0][j] != []:
                if u[0][j][0] <= n:
                    n = u[0][j][0]
                    m = u[0][j][1]
                    l = j
    #sorted(u[0])
    if i + 1 == k:
        print(n)
        #print(u[0][0].pop(0))
        exit()
    else:
        u[0].append(u[1 + p[m]][m])
        p[m] += 1
        u[0][l].pop(0)
        u[0][l].pop(0)
        n = "z"
        m = -1
        l = -1

Submission status: Wrong Answer

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

if(len(s)==1):
    print(s)
else:
    substrings=[]
    for i in range(len(s)-1):
        for j in range(i,min(i+(K+2),len(s))):
            str=s[i:(j+1)]
            substrings.append(str)

            substrings=list(set(substrings))

            if(len(substrings)>K):
                substrings.sort()
                substrings.pop()

    print(substrings[-1])

Submission status: Wrong Answer

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

if(len(s)==1):
    print(s)
else:
    substrings=[]
    for i in range(len(s)-1):
        for j in range(i,min(i+(K+1),len(s))):
            str=s[i:(j+1)]
            substrings.append(str)

            substrings=list(set(substrings))

            if(len(substrings)>K):
                substrings.sort()
                substrings.pop()

    print(substrings[-1])

Submission status: Wrong Answer

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

if(len(s)==1):
    print(s)
else:
    substrings=[]
    for i in range(len(s)-1):
        for j in range(i,min(i+K,len(s))):
            str=s[i:(j+1)]
            substrings.append(str)

            substrings=list(set(substrings))

            if(len(substrings)>K):
                substrings.sort()
                substrings.pop()

    print(substrings[-1])

Submission status: Wrong Answer

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

if(len(s)==1):
    print(s)
else:
    substrings=[]
    for i in range(len(s)-1):
        for j in range(i,len(s)):
            if(i-j>K):
                continue
            str=s[i:(j+1)]
            substrings.append(str)

        substrings=list(set(substrings))
        substrings.sort()

        if(len(substrings)>K):
            substrings.pop()

    print(substrings[-1])

Submission status: Wrong Answer

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

t = sorted(set(s))[0:K]

l = sorted(set(s))[0:K]

for i in range(min(K,len(t))):
    w = t[i]
    for j in range(len(s)):
        for k in range(i+2,K+1):
            if s[j]==w:
                l.append(s[j:j+k])

l = sorted(set(l))

print(l[K-1])

Submission status: Wrong Answer

Solution code:
s = 'atcoderandatcodeer'
K = 5

t = sorted(set(s))[0:K]

l = sorted(set(s))[0:K]

for i in range(min(K,len(t))):
    w = t[i]
    for j in range(len(s)):
        for k in range(i+2,K+1):
            if s[j]==w:
                l.append(s[j:j+k])

l = sorted(set(l))

print(l[K-1])

Submission status: Wrong Answer

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

dic={}
for i in range(len(s)):
    dic[s[i:]]=1
arr=sorted(dic)
dic={}
ans=''
for x in arr:
    for i in range(0,len(x)):
        tmp = x[:i+1]
        if dic.get(tmp,0)==0:
            K-=1
            dic[tmp]=1
        else:
            continue
        if K==0:
            ans=x[:i+1]
            break
    if K<0:
        break

Submission status: Wrong Answer

Solution code:
import sys

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

lst = []
cnt = 0
for i in range(97,123):
    idx = s.find(chr(i))
    if idx>=0:
        for j in range(idx+1,len(s)+1):
            lst.append(s[idx:j])
            cnt += 1
            if cnt>=K:
                lst.sort()
                print(lst[K-1])
                sys.exit()

Submission status: Wrong Answer

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

lst = []
cnt = 0
for i in range(97,123):
    idx = s.find(chr(i))
    if idx>=0:
        for j in range(idx+1,len(s)+1):
            lst.append(s[idx:j])
            cnt += 1
            if cnt>=K:
                lst.sort()
                ans = lst[K-1]
print(ans)

Submission status: Wrong Answer

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

# s = "atcoderandatcodeer"
# K = 5

alphabet = ["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"]

count = 0

for alp in alphabet:
    ss = []
    # print(alp)
    if alp in s:
        pos = [i for i, x in enumerate(s) if x == alp]
        # print(pos)
        for i in pos:
            for j in range(1,6):
                if i+j == len(s):
                    break
                else:
                    ss.append(s[i:i+j])
        ss = list(set(ss))
        ss.sort()
        # print(ss)
        if K - count <= len(ss):
            print(ss[K - count -1])
            break
        else:
            count += len(ss)