Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

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

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

print(ans[K-1])


Fixed submission:
from heapq import heappush, heappop

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

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

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

ans = sorted(list(set(q)))[K-1]

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

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

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

print(ans[K-1])


Fixed submission:
from heapq import heappush, heappop

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

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

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

ans = sorted(list(set(q)))[K-1]

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

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

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

print(ans[K-1])


Fixed submission:
from heapq import heappush, heappop

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

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

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

ans = sorted(list(set(q)))[K-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

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

min_index = [n for n, v in enumerate(s) if v == min(s)]

ans_list = [min(s)]
queue = []
i = 2

while len(ans_list) < K:
    # 候補の生成
    for m in min_index:
        for i in range(1, 6):
            if m + i < len(s):
                heappush(queue, s[m:m+i])
    while queue:
        c = heappop(queue)
        if c not in ans_list:
            ans_list.append(c)

print(ans_list[K-1])


Fixed submission:
from heapq import heappush, heappop

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

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

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

ans = sorted(list(set(q)))[K-1]

print(ans)