Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)

    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            # 尺取り
            for i in range(len(plus)):
                while j < len(minus) and plus[i]*minus[j]<=mid:
                    j+=1 
                count += j
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            ## plus
            for i in range(len(plus)-1,-1,-1):
                if plus[i]**2 <= mid:
                    count -= 1

                while j < len(plus) and plus[i]*plus[j] <= mid:
                    j += 1
                count += j
            
            ## minus
            j = 0
            for i in range(len(minus)-1,-1,-1):
                if minus[i]**2 <= mid:
                    count -= 1
                while j < len(minus) and minus[i]*minus[j] <= mid:
                    j += 1
                count += j
            
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)

    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            # 尺取り
            for i in range(len(plus)):
                while j < len(minus) and plus[i]*minus[j]<=mid:
                    j+=1 
                count += j
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            ## plus
            for i in range(len(plus)-1,-1,-1):
                if plus[i]**2 <= mid:
                    count -= 1

                while j < len(plus) and plus[i]*plus[j] <= mid:
                    j += 1
                count += j
            
            ## minus
            j = 0
            for i in range(len(minus)-1,-1,-1):
                if minus[i]**2 <= mid:
                    count -= 1
                while j < len(minus) and minus[i]*minus[j] <= mid:
                    j += 1
                count += j
            
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import numpy as np
from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = np.array(A)
    A.sort()

    zero_count = np.count_nonzero(A==0)
    plus = A[A>0]
    minus = A[A<0]

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)
    
    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            for i in range(len(plus)):
                target = mid//plus[i]
                # target以下の数をminusから見つける
                count += bisect_right(minus,target)
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            for i in range(len(plus)):
                target = mid//plus[i]
                # target以下の数をplusから見つける
                count += bisect_right(plus,target)
                if plus[i] <= target:
                    count -= 1

            for i in range(len(minus)):
                target = mid//minus[i]
                # target以下の数をplusから見つける
                count += bisect_right(minus,target)
                if minus[i] <= target:
                    count -= 1
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)

    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            # 尺取り
            for i in range(len(plus)):
                while j < len(minus) and plus[i]*minus[j]<=mid:
                    j+=1 
                count += j
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            ## plus
            for i in range(len(plus)-1,-1,-1):
                if plus[i]**2 <= mid:
                    count -= 1

                while j < len(plus) and plus[i]*plus[j] <= mid:
                    j += 1
                count += j
            
            ## minus
            j = 0
            for i in range(len(minus)-1,-1,-1):
                if minus[i]**2 <= mid:
                    count -= 1
                while j < len(minus) and minus[i]*minus[j] <= mid:
                    j += 1
                count += j
            
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])
    plus.sort()
    minus.sort()

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)
    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            for i in range(len(plus)):
                target = mid//plus[i]
                # target以下の数をminusから見つける
                count += bisect_right(minus,target)
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            for i in range(len(plus)):
                target = mid//plus[i]
                # target以下の数をplusから見つける
                count += bisect_right(plus,target)
                if plus[i] <= target:
                    count -= 1

            for i in range(len(minus)):
                target = mid//minus[i]
                # target以下の数をplusから見つける
                count += bisect_right(minus,target)
                if minus[i] <= target:
                    count -= 1
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)

    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            # 尺取り
            for i in range(len(plus)):
                while j < len(minus) and plus[i]*minus[j]<=mid:
                    j+=1 
                count += j
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            ## plus
            for i in range(len(plus)-1,-1,-1):
                if plus[i]**2 <= mid:
                    count -= 1

                while j < len(plus) and plus[i]*plus[j] <= mid:
                    j += 1
                count += j
            
            ## minus
            j = 0
            for i in range(len(minus)-1,-1,-1):
                if minus[i]**2 <= mid:
                    count -= 1
                while j < len(minus) and minus[i]*minus[j] <= mid:
                    j += 1
                count += j
            
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])
    plus.sort()
    minus.sort()

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)
    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            for i in range(len(plus)):
                target = mid//plus[i]
                # target以下の数をminusから見つける
                count += bisect_right(minus,target)
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            for i in range(len(plus)):
                target = mid//plus[i]
                # target以下の数をplusから見つける
                count += bisect_right(plus,target)
                if plus[i] <= target:
                    count -= 1

            for i in range(len(minus)):
                target = mid//minus[i]
                # target以下の数をplusから見つける
                count += bisect_right(minus,target)
                if minus[i] <= target:
                    count -= 1
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    zero_count = 0
    plus = []
    minus = []

    for i in range(N):
        if A[i] == 0:
            zero_count += 1
        elif A[i] >0 :
            plus.append(A[i])
        else:
            minus.append(A[i])

    zero_count = zero_count*(zero_count-1)//2+len(plus)*zero_count+len(minus)*zero_count
    minus_count = len(minus)*len(plus)

    if minus_count<K<=minus_count+zero_count:
        print(0)
        return
    elif K <= minus_count:
        left = -10**18-1
        right = 0

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            # 尺取り
            for i in range(len(plus)):
                while j < len(minus) and plus[i]*minus[j]<=mid:
                    j+=1 
                count += j
            
            if count >= K:
                right = mid
            else:
                left = mid
        print(right)

    else:
        K -= (minus_count+zero_count)
        left = -1
        right = 10**18+1

        for i in range(len(minus)):
            minus[i] = -minus[i]
        minus = minus[::-1]        

        while right - left > 1:
            mid = (right + left) //2
            ## mid 以下になる組み合わせがkこ以上あるか
            count = 0
            j = 0
            ## plus
            for i in range(len(plus)-1,-1,-1):
                if plus[i]**2 <= mid:
                    count -= 1

                while j < len(plus) and plus[i]*plus[j] <= mid:
                    j += 1
                count += j
            
            ## minus
            j = 0
            for i in range(len(minus)-1,-1,-1):
                if minus[i]**2 <= mid:
                    count -= 1
                while j < len(minus) and minus[i]*minus[j] <= mid:
                    j += 1
                count += j
            
            if count//2 >= K:
                right = mid
            else:
                left = mid
        print(right)


if __name__ == '__main__':
    main()