Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        key = i
        break

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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


Fixed submission:
s = input()
K = int(input())

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        break

key = i

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

list_rank = []
for i in range(len(s)):
    if i < len(s) - K + 1:
        for j in range(K+1):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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


Fixed submission:
s = input()
K = int(input())

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        break

key = i

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

alp = 'abcdefghijklmnopqrstuvwxyz'
loc = []
ini = []
flg = 0
rem = 0
for i in alp:
    flg_2 = 0
    idx = 0
    for j in s:
        if j == i:
            if flg_2 == 0:
                flg_2 = 1
                ini.append(i)
                loc.append((idx, i))
                rem += len(s[idx:])
                if rem >= K:
                    flg = 1
            else:
                loc.append((idx, i))
        idx += 1
    if flg == 1:
        break

len_s = len(s)
list_rank = []
for i in ini:
    tmp = [j for j in loc if j[1] == i]
    for j in tmp:
        idx = j[0]
        for k in range(len_s-idx):
            if len(s[idx:idx+k+1]) <= K:
                if s[idx:idx+k+1] not in list_rank:
                    list_rank.append(s[idx:idx+k+1])
    if len(list_rank) >= K:
        break

list_rank.sort()

print(list_rank[K-1])


Fixed submission:
s = input()
K = int(input())

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        break

key = i

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

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