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

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

    if N <= 50:
        A = set()
        for i in range(N):
            for j in range(i, N):
                A.add(s[i:j+1])
        A = list(A)
        A.sort()
        print(A[K-1])
    else:
        c = sorted(list(s))[0]
        A = set()
        for i in range(N):
            if s[i] == c:
                for j in range(5):
                    A.add(s[i:i+j+1])
        A = sorted(list(A))
        print(A[K-1])



if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

    A = set()
    for i in range(N):
        for j in range(K):
            A.add(s[i:i+j+1])
    A = list(A)
    A.sort()
    print(A[K-1])


if __name__ == '__main__':
    main()

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

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

    if N <= 50:
        A = set()
        for i in range(N):
            for j in range(i, N):
                A.add(s[i:j+1])
        A = list(A)
        A.sort()
        print(A[K-1])
    else:
        A = list(s)
        A.sort()
        c = A[0]
        l = []
        for i in range(N):
            if s[i] == c:
                l.append(i)
        x = set()
        for v in l:
            for i in range(len(s[v:v+5])):
                x.add(s[v:v+i+1])
        x = list(x)
        x.sort()
        print(x[K-1])



if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

    A = set()
    for i in range(N):
        for j in range(K):
            A.add(s[i:i+j+1])
    A = list(A)
    A.sort()
    print(A[K-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

    A = set()

    for i in range(N):
        for j in range(i, N):
            A.add(s[i:j+1])

    A = list(A)
    A.sort()

    print(A[K-1])



if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    N = len(s)
    K = ii()

    A = set()
    for i in range(N):
        for j in range(K):
            A.add(s[i:i+j+1])
    A = list(A)
    A.sort()
    print(A[K-1])


if __name__ == '__main__':
    main()