Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x):
    ans = 0
    la, lb = len(a), len(b)
    J = (i for i in range(lb)) if a == b else (-1 for i in range(la))

    j = lb - 1
    for i, k in enumerate(J):
        xa = a[i]

        for j in range(j, k, -1):
            x1 = b[j] * xa
            if x1 <= x:
                break
        else:
            break
        ans += j - k

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid) + cnt_val(A[2], A[2], mid)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)

    for i in range(len(a) - ai):
        xa = a[i]

        lo = i + 1 if ai else 0

        cnt = 0
        for lo in range(lo, lb):
            x1 = b[lo] * xa
            #print(i, lo, x1)
            if x1 > x:
                break
            cnt += 1
        #print("x", (i, cnt, ai), x)
        ans += cnt

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo = i + 1 if ai else 0

        cnt = loa[i]
        for lo in range(lo+cnt, lb):
            x1 = b[lo] * xa
            #print(i, lo, x1)
            if x1 > x:
                break
            cnt += 1
        #print("x", (i, cnt, ai), x)
        mia[i] = cnt
        ans += cnt

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo = i + 1 if ai else 0

        cnt = loa[i]
        for lo in range(lo+cnt, lb):
            x1 = b[lo] * xa
            #print(i, lo, x1)
            if x1 > x:
                break
            cnt += 1
        #print("x", (i, cnt, ai), x)
        mia[i] = cnt
        ans += cnt

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

from bisect import bisect
iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb]*la

        cache.append((-inf, loa))
        cache.append((inf, hia))
        ic = 1
    else:
        ic = bisect(cache, (x+1,))
        loa = cache[ic-1][1]
        hia = cache[ic][1]

    aa = [0] * len(a)
    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        aa[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    cache.insert(ic, (x, aa))
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

def cnt_val(a, b, x):
    ai = 1 if a == b else 0
    ans = 0
    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = i+1 if ai else 0, len(b)
        lo0 = lo

        #print(i, xa, x)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        ans += lo - lo0
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid) + cnt_val(A[2], A[2], mid)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()
    A = list(iim())

    x = 0

    B = []
    for i in range(N-1):
        for j in range(i+1, N):
            B.append(A[i]*A[j])
    B.sort()
    print(B[K-1])



if __name__ == "__main__":
    resolve()


Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ai = 1 if a == b else 0
    ans = 0

    la, lb = len(a), len(b)
    if len(cache) == 0:
        loa = [i+1 for i in range(la-1)] if ai else [0] * la
        hia = [lb] * la
        mia = [0] * la

        cache.append([-inf, loa])
        cache.append([x, mia])
        cache.append([inf, hia])
        ic = 1
    else:
        if x < cache[1][0]:
            cache[1], cache[2] = cache[2], cache[1]
        else:
            cache[0] ,cache[1] = cache[1], cache[0]

        cache[1][0] = x

        loa = cache[0][1]
        mia = cache[1][1]
        hia = cache[2][1]

    for i in range(len(a) - ai):
        xa = a[i]

        lo, hi = loa[i], hia[i]

        #print(ic, lo, hi)

        while lo < hi:
            mid = (lo + hi) // 2
            x1 = b[mid] * xa
            #print(i, (lo, hi), x1)

            if x1 <= x:
                lo = mid + 1
            else:
                hi = mid
        #print("x", (lo, lo0))
        mia[i] = lo
        ans += lo
        if ai:
            ans -= i + 1
    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()