Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

import sys
input = lambda : sys.stdin.readline().strip()

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def check(m):
    cnt = 0
    for ai in a:
        if ai == 0:
            if m >= 0:
                cnt += n-1
        elif ai < 0:
            x = -(-m//ai)
            cnt += n - bisect_left(a, x)
            if ai>= x:
                cnt -= 1
        else:
            x = m//ai
            cnt += bisect_left(a, x+1)
            if ai <= x:
                cnt -= 1
        if cnt//2 >= k:
            return True
    return False

left = -10**20
right = 10**20
while right-left>1:
    mid = (right+left)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(right)

Fixed submission:
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

n,k = map(int, input().split())
a = list(map(int, input().split()))

plus = minus = zero = 0
ps = []
ms = []
for i in a:
    if i == 0:
        zero += 1
    elif i > 0:
        plus += 1
        ps.append(i)
    else:
        minus += 1
        ms.append(-i)

ps.sort()
ms.sort()

def check(m):
    if m == 0:
        return plus*minus + zero*(zero-1)//2 + zero*(plus+minus) >= k
    elif m > 0:
        tmp = plus*minus + zero*(zero-1)//2 + zero*(plus+minus)
        for l in [ps, ms]:
            X = len(l)
            cur = X-1
            for i in range(X):
                while cur >= 0 and l[i]*l[cur] > m:
                    cur -= 1
                if cur <= i:
                    break
                tmp += cur-i
        return tmp >= k
    else:
        tmp = 0
        cur = 0
        for i in reversed(range(plus)):
            while cur < minus and ms[cur]*ps[i] < -m:
                cur += 1
            tmp += minus-cur
        return tmp >= k

left = -10**20
right = 10**20

while right-left>1:
    mid = (right+left)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def check(m):
    cnt = 0
    for ai in a:
        if ai == 0:
            if m >= 0:
                cnt += n-1
        elif ai < 0:
            x = -(-m//ai)
            cnt += n - bisect_left(a, x)
            if ai>= x:
                cnt -= 1
        else:
            x = m//ai
            cnt += bisect_left(a, x+1)
            if ai <= x:
                cnt -= 1
    return cnt//2

left = -10**20
right = 10**20
while right-left>1:
    mid = (right+left)//2
    cnt = check(mid)
    if cnt >= k:
        right = mid
    else:
        left = mid

print(right)


Fixed submission:
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

n,k = map(int, input().split())
a = list(map(int, input().split()))

plus = minus = zero = 0
ps = []
ms = []
for i in a:
    if i == 0:
        zero += 1
    elif i > 0:
        plus += 1
        ps.append(i)
    else:
        minus += 1
        ms.append(-i)

ps.sort()
ms.sort()

def check(m):
    if m == 0:
        return plus*minus + zero*(zero-1)//2 + zero*(plus+minus) >= k
    elif m > 0:
        tmp = plus*minus + zero*(zero-1)//2 + zero*(plus+minus)
        for l in [ps, ms]:
            X = len(l)
            cur = X-1
            for i in range(X):
                while cur >= 0 and l[i]*l[cur] > m:
                    cur -= 1
                if cur <= i:
                    break
                tmp += cur-i
        return tmp >= k
    else:
        tmp = 0
        cur = 0
        for i in reversed(range(plus)):
            while cur < minus and ms[cur]*ps[i] < -m:
                cur += 1
            tmp += minus-cur
        return tmp >= k

left = -10**20
right = 10**20

while right-left>1:
    mid = (right+left)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(right)