Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        pos[s].append(i)
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        for position in pos[l]:
            for k in range(position+1, len(S)+1):
                dic.add(S[position:k])
        if len(dic) >= K:break

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



if __name__ == "__main__":
    run()


Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        heappush(pos[s], S[i:])
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        while pos[l]:
            sub = heappop(pos[l])
            for i in range(1, len(sub)+1):
                dic.add(sub[:i])

            if len(dic) >= K:
                dic = sorted(list(dic))
                print(dic[K - 1])
                return



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        pos[s].append(i)
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        for position in pos[l]:
            for k in range(position+1, len(S)+1):
                dic.add(S[position:k])
        if len(dic) >= K:break

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



if __name__ == "__main__":
    run()


Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        heappush(pos[s], S[i:])
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        while pos[l]:
            sub = heappop(pos[l])
            for i in range(1, len(sub)+1):
                dic.add(sub[:i])

            if len(dic) >= K:
                dic = sorted(list(dic))
                print(dic[K - 1])
                return



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    for k in range(1, len(S)+1):
        for p in range(len(S)-k+1):
            sub = S[p:p+k]
            dic.add(sub)
    dic = sorted(list(dic))
    print(dic[K-1])


if __name__ == "__main__":
    run()


Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        heappush(pos[s], S[i:])
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        while pos[l]:
            sub = heappop(pos[l])
            for i in range(1, len(sub)+1):
                dic.add(sub[:i])

            if len(dic) >= K:
                dic = sorted(list(dic))
                print(dic[K - 1])
                return



if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    for k in range(1, len(S)+1):
        for p in range(len(S)-k+1):
            sub = S[p:p+k]
            dic.add(sub)
    dic = sorted(list(dic))
    print(dic[K-1])


if __name__ == "__main__":
    run()


Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    S = input()
    K = int(input())
    dic = set()
    pos = defaultdict(lambda : [])
    for i, s in enumerate(S):
        heappush(pos[s], S[i:])
    base = 'abcdefghijklmnopqrstuvwxyz'

    for l in base:
        while pos[l]:
            sub = heappop(pos[l])
            for i in range(1, len(sub)+1):
                dic.add(sub[:i])

            if len(dic) >= K:
                dic = sorted(list(dic))
                print(dic[K - 1])
                return



if __name__ == "__main__":
    run()