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

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_plus):
            while j < len_minus and A_plus[i] * A_minus[j] <= M:
                j += 1
            count += j
        
        if count == K - 1 and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
    
else:
    K -= pairs_num[0] + pairs_num[1]
    A_minus = list(map(lambda x: -x, reversed(A_minus)))
    L = 1
    R = 10 ** 18
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_minus-1, -1, -1):
            while j < len_minus and A_minus[i] * A_minus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
        j = 0
        for i in range(len_plus-1, -1, -1):
            while j < len_plus and A_plus[i] * A_plus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
            
        if count == K - 1 and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M


Fixed submission:
import bisect

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_plus):
            while j < len_minus and A_plus[i] * A_minus[j] <= M:
                j += 1
            count += j
        
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
    
else:
    K -= pairs_num[0] + pairs_num[1]
    A_minus = list(map(lambda x: -x, reversed(A_minus)))
    L = 1
    R = 10 ** 18
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_minus-1, -1, -1):
            while j < len_minus and A_minus[i] * A_minus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
        j = 0
        for i in range(len_plus-1, -1, -1):
            while j < len_plus and A_plus[i] * A_plus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
            
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M

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

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = (L + R) // 2
        count = 0
        for i in range(len_minus):
            count += len_plus - bisect.bisect_left(A_plus, -(M // -A_minus[i]))
#             count[1] += len_plus - bisect.bisect_left(A_plus, -(M[1] // -A_minus[i]))

        if count == K - 1 and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
#         if count[0] < K <= count[1]:
#             print(M[1])
#             break
#         elif K <= count[0]:
#             R = M[0]
#         elif count[1] < K:
#             L = M[1]
#         else:
#             assert 0
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
else:
    K -= pairs_num[0] + pairs_num[1]
    L = 1
    R = 10 ** 18
    while True:
        M = (L + R) // 2
        count = 0
        for i in range(len_minus):
            count += min(len_minus - i - 1, len_minus - bisect.bisect_left(A_minus, -(M // -A_minus[i])))
#             count[1] += min(len_minus - i - 1, len_minus - bisect.bisect_left(A_minus, -(M[1] // -A_minus[i])))
        for i in range(len_plus):
            count += max(0, bisect.bisect_right(A_plus, M // A_plus[i]) - i - 1)
#             count[1] += max(0, bisect.bisect_right(A_plus, M[1] // A_plus[i]) - i - 1)

        if count == K - 1 and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
# #         if count[0] < K < count[1] or count[0] < K == count[1]:
#         if count[0] < K <= count[1]:
#             print(M[1])
#             break
# #         elif K == count[0] < count[1] or K == count[0] == count[1] or K < count[0] == count[1] or K < count[0] < count[1]:
# #         elif K <= count[0] <= count[1]:
#         elif K <= count[0]:
#             R = M[0]
# #         else:
# #         elif count[0] == count[1] < K or count[0] < count[1] < K:
#         elif count[1] < K:
#             L = M[1]
#         else:
#             assert 0

Fixed submission:
import bisect

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_plus):
            while j < len_minus and A_plus[i] * A_minus[j] <= M:
                j += 1
            count += j
        
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
    
else:
    K -= pairs_num[0] + pairs_num[1]
    A_minus = list(map(lambda x: -x, reversed(A_minus)))
    L = 1
    R = 10 ** 18
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_minus-1, -1, -1):
            while j < len_minus and A_minus[i] * A_minus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
        j = 0
        for i in range(len_plus-1, -1, -1):
            while j < len_plus and A_plus[i] * A_plus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
            
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M

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

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = [(L + R) // 2, (L + R) // 2 + 1]
        count = [0, 0]
        for i in range(len_minus):
            count[0] += len_plus - bisect.bisect_left(A_plus, -(M[0] // -A_minus[i]))
            count[1] += len_plus - bisect.bisect_left(A_plus, -(M[1] // -A_minus[i]))
            
        if count[0] < K <= count[1]:
            print(M[1])
            break
        elif K <= count[0]:
            R = M[0]
        elif count[1] < K:
            L = M[1]
        else:
            assert 0
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
else:
    K -= pairs_num[0] + pairs_num[1]
    L = 1
    R = 10 ** 18
    while True:
        M = [(L + R) // 2, (L + R) // 2 + 1]
        count = [0, 0]
        for i in range(len_minus):
            count[0] += min(len_minus - i - 1, len_minus - bisect.bisect_left(A_minus, -(M[0] // -A_minus[i])))
            count[1] += min(len_minus - i - 1, len_minus - bisect.bisect_left(A_minus, -(M[1] // -A_minus[i])))
        for i in range(len_plus):
            count[0] += max(0, bisect.bisect_right(A_plus, M[0] // A_plus[i]) - i - 1)
            count[1] += max(0, bisect.bisect_right(A_plus, M[1] // A_plus[i]) - i - 1)
            
#         if count[0] < K < count[1] or count[0] < K == count[1]:
        if count[0] < K <= count[1]:
            print(M[1])
            break
#         elif K == count[0] < count[1] or K == count[0] == count[1] or K < count[0] == count[1] or K < count[0] < count[1]:
#         elif K <= count[0] <= count[1]:
        elif K <= count[0]:
            R = M[0]
#         else:
#         elif count[0] == count[1] < K or count[0] < count[1] < K:
        elif count[1] < K:
            L = M[1]
        else:
            assert 0

Fixed submission:
import bisect

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_plus):
            while j < len_minus and A_plus[i] * A_minus[j] <= M:
                j += 1
            count += j
        
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
    
else:
    K -= pairs_num[0] + pairs_num[1]
    A_minus = list(map(lambda x: -x, reversed(A_minus)))
    L = 1
    R = 10 ** 18
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_minus-1, -1, -1):
            while j < len_minus and A_minus[i] * A_minus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
        j = 0
        for i in range(len_plus-1, -1, -1):
            while j < len_plus and A_plus[i] * A_plus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
            
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M

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

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = [(L + R) // 2, (L + R) // 2 + 1]
        count = [0, 0]
        for i in range(len_minus):
            count[0] += len_plus - bisect.bisect_left(A_plus, -(M[0] // -A_minus[i]))
            count[1] += len_plus - bisect.bisect_left(A_plus, -(M[1] // -A_minus[i]))
            
        if count[0] < K <= count[1]:
            print(M[1])
            break
        elif K <= count[0]:
            R = M[0]
        elif count[1] < K:
            L = M[1]
        else:
            assert 0
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
else:
    K -= pairs_num[0] + pairs_num[1]
    L = 1
    R = 10 ** 18
    while True:
        M = [(L + R) // 2, (L + R) // 2 + 1]
        count = [0, 0]
        for i in range(len_minus):
            count[0] += min(len_minus - i - 1, len_minus - bisect.bisect_left(A_minus, -(M[0] // -A_minus[i])))
            count[1] += min(len_minus - i - 1, len_minus - bisect.bisect_left(A_minus, -(M[1] // -A_minus[i])))
        for i in range(len_plus):
            count[0] += max(0, bisect.bisect_right(A_plus, M[0] // A_plus[i]) - i - 1)
            count[1] += max(0, bisect.bisect_right(A_plus, M[1] // A_plus[i]) - i - 1)
            
#         if count[0] < K < count[1] or count[0] < K == count[1]:
        if count[0] < K <= count[1]:
            print(M[1])
            break
#         elif K == count[0] < count[1] or K == count[0] == count[1] or K < count[0] == count[1] or K < count[0] < count[1]:
#         elif K <= count[0] <= count[1]:
        elif K <= count[0]:
            R = M[0]
#         else:
#         elif count[0] == count[1] < K or count[0] < count[1] < K:
        elif count[1] < K:
            L = M[1]
        else:
            assert 0

Fixed submission:
import bisect

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# Aを正負で分け、「積が負、積が0、積が正」それぞれのペア数を求める
A_minus = sorted([a for a in A if a < 0])
A_plus = sorted([a for a in A if a > 0])
len_minus = len(A_minus)
len_plus = len(A_plus)
len_zero = N - len_minus - len_plus
pairs_num = (len_minus * len_plus,
             (len_minus + len_plus) * len_zero + len_zero * (len_zero - 1) // 2,
             len_minus * (len_minus - 1) // 2 + len_plus * (len_plus - 1) // 2)
assert sum(pairs_num) == N * (N - 1) // 2

if K <= pairs_num[0]:
    L = -10 ** 18
    R = -1
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_plus):
            while j < len_minus and A_plus[i] * A_minus[j] <= M:
                j += 1
            count += j
        
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M
            
elif pairs_num[0] < K <= pairs_num[0] + pairs_num[1]:
    print(0)
    
else:
    K -= pairs_num[0] + pairs_num[1]
    A_minus = list(map(lambda x: -x, reversed(A_minus)))
    L = 1
    R = 10 ** 18
    while True:
        M = (L + R) // 2
        count = 0
        j = 0
        for i in range(len_minus-1, -1, -1):
            while j < len_minus and A_minus[i] * A_minus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
        j = 0
        for i in range(len_plus-1, -1, -1):
            while j < len_plus and A_plus[i] * A_plus[j] <= M:
                j += 1
            count += max(0, j - i - 1)
            
        if count < K and R - L == 1:
            print(R)
            break
        elif K <= count:
            R = M
        else:
            L = M