Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            border = 0
            for v in minus:
                while border < len(plus) and v * plus[border] > value:
                    border += 1 
                count += len(plus) - border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
        
    print(ans)

    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            border = 0
            for v in minus:
                while border < len(plus) and v * plus[border] > value:
                    border += 1 
                count += len(plus) - border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
        
    print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            for v in minus:
                border = 0
                while border < len(plus) and v * plus[len(plus)-border-1] <= value:
                    border += 1 
                count += border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r

    print(ans)

    
if __name__ == "__main__":
    main()



Fixed submission:
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            border = 0
            for v in minus:
                while border < len(plus) and v * plus[border] > value:
                    border += 1 
                count += len(plus) - border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
        
    print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            for v in minus:
                border = 0
                while border < len(plus) and v * plus[len(plus)-border-1] <= value:
                    border += 1 
                count += border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
    print(ans)
    #return ans

    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            border = 0
            for v in minus:
                while border < len(plus) and v * plus[border] > value:
                    border += 1 
                count += len(plus) - border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
        
    print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            for v in minus:
                border = (-value-1) // (-v) + 1
                count += len(plus) - bisect.bisect_left(plus, border)

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            edge = 0
            for v in minus:
                border = value // -v
                lo = bisect.bisect_left(minus, -border, lo=0)
                count += (len(minus) - lo)
                if -v <= border:
                    count -= 1
            
            edge = len(plus)
            for v in plus:
                border = value // v
                hi = bisect.bisect_right(plus, border, hi=edge)
                count += hi
                if v <= border:
                    count -= 1
            
            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
    print(ans)

    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            border = 0
            for v in minus:
                while border < len(plus) and v * plus[border] > value:
                    border += 1 
                count += len(plus) - border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
        
    print(ans)

    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            for v in minus:
                border = (-value-1) // (-v) + 1
                count += len(plus) - bisect.bisect_left(plus, border)

            if count >= k:
                r = value
            else:
                l = value

        ans = r
    elif k <= zero_count + minus_count:
        ans = 0
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            for v in minus:
                border = value // -v
                count += (len(minus) - bisect.bisect_left(minus, -border))
                if -v <= border:
                    count -= 1

            for v in plus:
                border = value // v
                count += bisect.bisect_right(plus, border)
                if v <= border:
                    count -= 1
            
            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
    print(ans)

    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
import bisect
input = sys.stdin.readline

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

    minus, plus, zero = [], [], 0
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        elif a[i] > 0:
            plus.append(a[i])
        else:
            zero += 1
    
    minus_count = len(minus) * len(plus)
    zero_count = zero * (zero - 1) // 2 + zero * (len(minus) + len(plus))

    minus.sort()
    plus.sort()

    if k <= minus_count:
        l, r = -int(1e18), 0
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            border = 0
            for v in minus:
                while border < len(plus) and v * plus[border] > value:
                    border += 1 
                count += len(plus) - border

            if count >= k:
                r = value
            else:
                l = value

        ans = r

    elif k <= zero_count + minus_count:
        ans = 0
        
    else:
        l, r = 0, int(1e18)
        count_default = minus_count + zero_count
        while r-l > 1:
            value = (r + l) // 2
            count = 0
            
            border = 0
            for v in minus:
                while border < len(minus) and v * minus[-border-1] <= value:
                    border += 1
                count += border
                if border > 0 and v >= minus[-border]:
                    count -= 1
            
            border = 0
            for v in plus:
                while border < len(plus) and v * plus[-border-1] > value:
                    border += 1
                count += len(plus) - border
                if border < len(plus) and v <= plus[-border-1]:
                    count -= 1

            count //= 2
            count += count_default

            if count >= k:
                r = value
            else:
                l = value
        ans = r
        
    print(ans)

    
if __name__ == "__main__":
    main()