Problem:


Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064



Sample input:
4 3
3 3 -4 -2


Sample output:
-6

Submission status: Runtime Error

Solution code:
AN = input().split()
AN = [int(a) for a in AN]
AN2 = [AN]*N
 
import numpy as np
AN = np.array([AN])
AN2 = np.array(AN2)
AN = AN.reshape(N,-1)
pro = AN * AN2
num = []
for i in range(N):
  for l in range(i+1):
      num.append(i*N+l)
pro2 = pro.flatten()
pro2 = np.delete(pro2, num,0)
pro2 = np.sort(pro2, kind='quick_sort')
print(pro2[K-1])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from bisect import bisect_left

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

p = []
m = []
zero = 0
for i in range(N) :
  if A[i] > 0 :
    p.append(A[i])
  elif A[i] < 0 :
    m.append(-A[i])
  else :
    zero += 1

p.sort()
m.sort()

ng, ok = -(10 ** 18)-1, 10 ** 18+1
while ok - ng > 1 :
  mid = (ok + ng) // 2
  s = 0 
  if mid < 0 :
    for i in range(len(m)) :
      x = (-mid+m[i]-1) // (m[i])
      s += len(p) - bisect_left(p, x)
    
  else :
    for i in range(len(p)) :
      x = mid // p[i]
      if x < p[i] : break
      s += max(0, bisect_left(p, x + 1) - 1 - i)
    for i in range(len(m)) :
      x = mid // m[i]
      if x < p[i] : break
      s += max(0, bisect_left(m, x + 1) - 1 - i)
    s += (len(p) + len(m)) * zero
    s += len(p) * len(m)
    s += zero * (zero - 1) // 2
  
  if s < K :
    ng = mid
  else :
    ok = mid
    
print(ok)

Submission status: Runtime Error

Solution code:
import copy
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
cnt=0
if min(a)>=0:
    for i in range(200005):
        if i*(i+1)>2*k:
            cnt=i-1
            break
    print(a[cnt+1]*a[k-cnt*(cnt+1)//2])
else:
    for i in range(n):
        if a[i]>=0:
            cnt=i
            break
    aa=0
    cc=0
    frag=0
    for i in range(n-cnt):
        aa+=n-cnt
        if aa>k:
            cc=i
            frag=1
            break
    if frag==1:
        print(a[cc]*a[k-aa])
    else:
        s=copy.deepcopy(k)
        vv=[]
        for i in range(n):
            for j in range(i+1,n):
                vv.append(a[i]*a[j])
        vv.sort()
        print(vv[s-1])

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
lst = list(map(int, input().split()))

minus = [l for l in lst if l < 0]
zeros = [l for l in lst if l == 0]
plus  = [l for l in lst if l > 0]
minus_num = len(minus)
zeros_num = len(zeros)
plus_num = len(plus)
#print(minus)
#print(plus)
#print(zeros)

d1 = minus_num*plus_num
d2 = zeros_num*minus_num + zeros_num*plus_num + zeros_num*(zeros_num-1)/2
#print(d1)
#print(d2)

if k <= d1:
    values = []
    for m in minus:
        for p in plus:
            values.append(m*p)
    print(sorted(values)[k])
    
elif d1 < k <= (d1+d2):
    print(0)
else:
    resi = int(k - d1 - d2) - 1
    values = []
    for i in range(len(minus)):
        for j in range(i+1, len(minus)):
            values.append(minus[i]*minus[j])
    for i in range(len(plus)):
        for j in range(i+1, len(plus)):
            values.append(plus[i]*plus[j])
    print(sorted(values)[resi])

Submission status: Runtime Error

Solution code:
cnt, tar = list(map(int, input().split()))
tar_list = np.array(map(int, input().split()))
calc_list = [0] * int(((cnt * (cnt -1))/2))
num = 0
for i in range(cnt - 1) :
  for j in range(i + 1, cnt):
    calc_list[num] = tar_list[i] * tar_list[j]
    num += 1
    
calc_list = sorted(calc_list)
print(calc_list[tar -1])

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
c=[]
a.sort()
d=[]
try:
    ind=a.index(0)
    b=a[0:ind]
    a.reverse()
    c=a[0:a.index(0)]
except:
    a.append(0)
    a.sort()
    b=a[0:a.index(0)]
    a.reverse()
    c=a[0:a.index(0)]
    a.remove(0)
minus=len(b)
plus=len(c)
if k<=minus*plus:
    for i in range(len(b)):
        for j in range(len(c)):
            d.append(b[i]*c[j])
    d.sort()
    print(d[k-1])
elif k>=(n*(n-1))//2-minus**2-plus**2:
    l=(n*(n-1))//2-k+1
    for i in range(len(b)):
        for j in range(i+1,len(b)):
            d.append(b[i]*b[j])
    for i in range(len(c)):
        for j in range(i+1,len(c)):
            d.append(c[i]*c[j])
    d.sort()
    d.reverse()
    print(d[l-1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
neg,zer,pos=0,0,0
for a in A:
  if a<0:
    neg+=1
  elif a==0:
    zer+=1
  else:
    pos+=1
N,P=A[:neg],A[neg+zer:]
import bisect

a=neg*pos
b=a+zer*(neg+pos)+zer*(zer-1)//2

if k<=a:
  l,r=N[0]*P[-1],N[-1]*P[0]
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=pos-bisect.bisect_right(P,-x)
    if ct>=k:
      r=mid
    else:
      l=mid
  print(r)
elif k<=b:
  print(0)
else:
  k-=b
  l,r=min(N[-1]**2,P[0]**2),max(N[0]**2,P[-1]**2)
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=neg-bisect.bisect_left(N,-x)
      if nn**2<=mid:
        ct-=1
    for pp in P:
      x=mid//pp
      ct+=bisect.bisect_right(P,x)
      if pp**2<=mid:
        ct-=1
    if ct>=2*k:
      r=mid
    else:
      l=mid
  print(r)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
a = [0] * N
b = [0] * (N * (N - 1) // 2)
a = list(map(int, input().split()))
    
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        b[cnt] = a[i] * a[j]
        cnt += 1
b.sort()

print(b[K-1])

Submission status: Runtime Error

Solution code:
i = list(map(int, input().split()))
j= list(map(int, input().split()))
k=[]
for i in range(i[0]):
  for l in range(1,i[0]-i):
    k.append(j[i]*j[i+l]

k.sort()
print(k[i[1]])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 10) #再帰用
n, k = list(map(int,(input().split())))
a = list(map(int,(input().split())))
#from heapq import heapify, heappop, heappush
import itertools
import bisect

x = []
#heapify(x)
p = itertools.combinations(a, 2)
for i in p:
  bisect.insort(x,int(i[0]*i[1]))
 
#heapify(x)
print(x[k-1])  
#print(x)

Submission status: Runtime Error

Solution code:
n, k = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort()
if 0 in nums:
  index = nums.index(0)
  if index == 0:
    print(nums[1] * nums[k])
  if index == n-1:
    print(nums[-2] * nums[-k - 1])
  else:
      num_neg = index
      num_pos = n - index
      if k < num_neg * num_pos:
          s = k // num_pos
          f = k % num_pos
          if f == 0:
              print(nums[-s] * nums[index+1])
          else:
              print(nums[-s-1] * nums[-f-1])
      else:
          new_list = nums[index:] + [-x for x in nums[:index]]
          new_list.sort()
          print(new_list[1] * new_list[k])
else:
    l, h = 0, n - 1
    while l < h:
        m = (l+h) // 2
        if nums[m] >= 0:
            h = m
        else:
            l = m + 1
    index = l
    num_neg = index
    num_pos = n - index
    if k < num_neg * num_pos:
        s = k // num_pos
        f = k % num_pos
        if f == 0:
            print(nums[-s] * nums[index+1])
        else:
            print(nums[-s-1] * nums[-f-1])
    else:
        new_list = nums[index:] + [-x for x in nums[:index]]
        new_list.sort()
        print(new_list[0] * new_list[k-1])

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

import itertools
times = []
for i in itertools.combinations(A, 2):
    times.append(i[0]* i[1])

times_sort.sort
print(times_sort[K-1])

Submission status: Runtime Error

Solution code:
n,order = map(int, input().split())
nums = [int(str) for str in input().split()]
maxn = int(n * (n-1) /2)
result = list(range(maxn))
bangou = 0
 
for x in range(n-1):
  for y in range(n):
    if y > x:
      result[bangou] = int( nums[x] * nums[y] )
      bangou += 1

result.sort()
print(result[order-1])

Submission status: Runtime Error

Solution code:
from bisect import bisect
from bisect import bisect_left
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

def count(m):
    res = 0
    for i in range(N):
        a = A[i]
        if a==0:
            if m>=0:
                res += N
        elif a>0:
            r = m/a
            j = bisect(A,r)
            res += j
        else:
            r = m/a
            j = bisect_left(A,r)
            res += N-j
        if a**2<=m:
            res -= 1
    res //= 2
    return res,cand

def count1(m):
    res = 0
    cand = -10**19
    for i in range(N):
        a = A[i]
        if a==0:
            if m>=0:
                res += N
        elif a>0:
            r = m/a
            j = bisect(A,r)
            res += j
            if j!= 0:
                cand = max(cand,a*A[j-1])
        else:
            r = m/a
            j = bisect_left(A,r)
            res += N-j
            if j != N:
                cand = max(cand,a*A[j])
        if a**2<=m:
            res -= 1
    res //= 2
    return res,cand


l = -10**18
r = 10**18
m = (l+r)/2
for i in range(60):
    k = count(m)
    if k < K:
        l = m
    else:
        r = m
    m = (l+r)/2
k,ans = count1(r)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations

n, k = [int(x) for x in input().split()]
xs = [int(a) for a in input().split()]

pos = []
neg = []
g = combinations(xs, 2)
for x, y in g:
    if x > 0 and y > 0:
        pos.append((x, y))
    elif x < 0 and y < 0:
        pos.append((x, y))
    else:
        neg.append((x,y))

if len(neg) > k:
    print(sorted([x * y for x, y in neg])[k-1])
else:
    print(sorted([x * y for x, y in pos])[k-1-len(neg)])

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A)
C=[]
import bisect
a=bisect.bisect_left(B,0)
b=bisect.bisect_right(B,0)
x=a
y=b-a
z=N-x-y
if x*z<K<=N-(z*(z-1)+x*(x-1)):
  print(0)
elif K<=x*z:
  for i in range(x):
    for j in range(x+y,N):
      C.append(B[i]*B[j])
  print(sorted(C)[K-1])
else:
  for i in range(x-1):
    for j in range(i+1,x):
      C.append(B[i]*B[j])
  for i in range(x+y,N-1):
    for j in range(i+1,N):
      C.append(B[i]*B[j])
  D=sorted(C)
  e=N*(N-1)//2
  print(D[-1*(e)-1+K])

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
neg,zer,pos=0,0,0
for a in A:
  if a<0:
    neg+=1
  elif a==0:
    zer+=1
  else:
    pos+=1
N,P=A[:neg],A[neg+zer:]
import bisect

a=neg*pos
b=a+zer*(neg+pos)+zer*(zer-1)//2

if k<=a:
  l,r=N[0]*P[-1],N[-1]*P[0]
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=pos-bisect.bisect_right(P,-x)
    if ct>=k:
      r=mid
    else:
      l=mid
  print(r)
elif k<=b:
  print(0)
else:
  k-=b
  l,r=min(N[0]**2,P[0]**2),max(N[-1]**2,P[-1]**2)
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=neg-bisect.bisect_left(N,-x)
      if nn**2<=mid:
        ct-=1
    for pp in P:
      x=mid//pp
      ct+=bisect.bisect_right(P,x)
      if pp**2<=mid:
        ct-=1
    if ct>=2*k:
      r=mid
    else:
      l=mid
  print(r)

Submission status: Runtime Error

Solution code:
while 1:
  list1=[]
  list2=[]
  n,m = input().split()
  n = int(n)
  m = int(m)
  list1 = [int(x) for x in input().split()]
  for i in range(0,n-1):
      for j in range(i+1,n):
          list2.append(list1[i]*list1[j])
  #print(list2)
  print(list2[m-1])

Submission status: Runtime Error

Solution code:
import itertools
n, k = map(int, input().split())
arr = map(int, input().split())

ls = []
for i, j in itertools.combinations(arr, 2):
  ls.append(i * j)
ls.sort()
print(ls[k])

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
import itertools
a=list(map(int,input().split()))
a_pos = [i for i in a if i>0]
a_pos.sort()
pos = len(a_pos)
a_zero = len([i for i in a if i==0])
a_neg = [i for i in a if i<0]
a_neg.sort()
neg = len(a_neg)
if k<= neg*pos:
  i_n=0
  i_p=pos-1
  c=1
  #print(a_pos)
  #print(a_neg)
  #print(a_pos[i_p]*a_neg[i_n])
  while c<k:
    if i_n==neg-1:
      i_p-=1
      c+=1
      continue
    if i_p==0:
      i_n+=1
      c+=1
      continue
    P = a_pos[i_p-1]*a_neg[i_n]
    N = a_pos[i_p]*a_neg[i_n+1]
    if P <= N:
      i_p-=1
    else:
      i_n+=1
    c+=1
    #print(a_pos[i_p]*a_neg[i_n])
  print(a_pos[i_p]*a_neg[i_n])
  #li = [i*j for i in a_pos for j in a_neg]
  #li.sort()
  #print(li[k-1])
elif neg*pos < k <= (n*(n-1)//2) - (pos*pos + neg*neg):
  print(0)
else:
  pp = list(itertools.combinations(a_pos, 2))
  nn = list(itertools.combinations(a_neg, 2))
  li = [i[0]*i[1] for i in pp] + [i[0]*i[1] for i in nn]
  li.sort(reverse=True)
  # 後ろから数えて n*(n-1)//2 - k + 1 番目
  l = n*(n-1)//2 - k + 1
  #print(li,l)
  print(li[l-1])

Submission status: Runtime Error

Solution code:
A = input()
B = input()
arr1 = [int(i) for i in A.split(' ')]
arr2 = [int(i) for i in B.split(' ')]
arr3 = []
for i in range(len(arr2)-1):
	for j in range(i+1,len(arr2)):
		arr3.append(arr2[i]*arr2[j])
arr3.sort()
print(arr3[arr1[1]])

Submission status: Runtime Error

Solution code:
import numpy as np

N, K = np.fromstring(input(), int, sep=" ")
As = np.fromstring(input(), np.int64, sep=" ")

# i, j = np.tril_indices(N, -1)
# print(sorted(As[i] * As[j])[K-1])


def count_combination(n):
    return n * (n - 1) // 2


pos = As[As > 0]
neg = As[As < 0]

n_pos = count_combination(len(pos)) + count_combination(len(neg))
n_neg = len(pos) * len(neg)
n_zero = count_combination(N) - (n_pos + n_neg)


if K <= n_neg:
    n, m = max(n_pos, n_neg), min(n_pos, n_neg)
    i, j = np.tril_indices(n, -1, m)
    print(sorted(As[i] * As[j])[K - 1])

elif K <= n_neg + n_zero:
    print(0)

else:
    i, j = np.tril_indices(len(pos), -1)
    mul_pos = pos[i] * pos[j]

    i, j = np.tril_indices(len(neg), -1)
    mul_neg = neg[i] * neg[j]

    cat = np.concatenate((mul_pos, mul_neg))
    cat.sort()

    print(cat[K - 1 - n_neg - n_zero])

Submission status: Runtime Error

Solution code:
cnt, tar = list(map(int, input().split()))
tar_list = list(map(int, input().split()))
calc_list = [0] * int(((cnt * (cnt -1))/2))
num = 0
for i in range(cnt - 1) :
  for j in range(i + 1, cnt):
    calc_list[num] = tar_list[i] * tar_list[j]
    num += 1
    
calc_list = sorted(calc_list)
print(calc_list[tar -1])

Submission status: Runtime Error

Solution code:
line = input('')
n = int(line.split(' ')[0])
k = int(line.split(' ')[1])
ary = input('').split(' ')

list = []
for n1 in range(0,n):
  for n2 in range(0,n):
    if n1 != n2 and int(n1) > int(n2):
      list.append(int(ary[n1]) * int(ary[n2]) )

list2 = sorted(list)
print(list2[k])

Submission status: Runtime Error

Solution code:
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
#B=list(reversed(A))
A=np.array(A)
Aneg=A[A<0]
Azero=A[A==0]
Apos=A[A>0]

n_neg=len(Aneg)*len(Apos)
n_zero=len(Azero)*(len(Azero)-1)//2+len(Azero)*(len(Aneg)+len(Apos))
n_pos=(len(Apos)*(len(Apos)-1)+len(Aneg)*(len(Aneg)-1))//2

if K <=n_neg:
    n=K-n_neg
    B=sorted(Aneg)[:n+1]
    C=sorted(Apos)[:n+1]
    ans=[]
    for i in range(min(len(B),n-1)):
        for j in range(min(len(C),n-1)):
            ans.append(B[i]*C[j])
    ans=sorted(ans)
    print(ans[n-1])
    
elif K>n_neg+n_zero:
    n=K-(n_neg+n_zero)
    B=sorted(Aneg)
    B=list(reversed(B))
    C=sorted(Apos)
    ans=[]
    if len(B)>2:
        for i in range(len(B)-1):
            for j in range(i+1,len(B)):
                ans.append(B[i]*B[j])
    if len(C)>2:
#         k=min(len(C),n-1)
        for i in range(len(C)-1):
            for j in range(i+1,len(C)):
                ans.append(C[i]*C[j])
    ans=sorted(ans)
    print(ans[n-1])
    
else:
    print(0)

Submission status: Runtime Error

Solution code:
import itertools

N,K = map(int, input().split())
AN = list(map(int, input().split()))

P = itertools.permutations(AN, 2)

l = []

for p in P:
    l.append(p[0]*p[1])

      l.sort()
      print(l[K+1])

Submission status: Runtime Error

Solution code:
import itertools
N,K = [int(e) for e in input().split()]
A = [int(e) for e in input().split()]
L = list(itertools.combinations(A, 2))
L1 = []
for i in range(len(L)):
    L1.append(L[i][0]*L[i][1])
L1.sort()
print(L1[K])

Submission status: Runtime Error

Solution code:
import numpy as np

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

Aarray = np.matrix([A], dtype=int)
mulA = Aarray.T * Aarray

mul_list = []
for i in range(len(mulA)):
    mul_list += mulA[i,(i+1):].tolist()[0]
    
ans = sorted(mul_list)[K-1]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N, K = np.fromstring(input(), int, sep=" ")
As = np.fromstring(input(), np.int64, sep=" ")

# i, j = np.tril_indices(N, -1)
# print(sorted(As[i] * As[j])[K-1])


def count_combination(n):
    return n * (n - 1) // 2


pos = As[As > 0]
neg = As[As < 0]

n_pos = count_combination(len(pos)) + count_combination(len(neg))
n_neg = len(pos) * len(neg)
n_zero = count_combination(N) - (n_pos + n_neg)

print(n_pos, n_neg, n_zero)


if K <= n_neg:
    n, m = max(n_pos, n_neg), min(n_pos, n_neg)
    i, j = np.tril_indices(n, -1, m)
    print(sorted(As[i] * As[j])[K - 1])

elif K <= n_neg + n_zero:
    print(0)

else:
    i, j = np.tril_indices(len(pos), -1)
    mul_pos = pos[i] * pos[j]

    i, j = np.tril_indices(len(neg), -1)
    mul_neg = neg[i] * neg[j]

    cat = np.concatenate((mul_pos, mul_neg))
    cat.sort()

    print(cat[K - 1 - n_neg - n_zero])

Submission status: Runtime Error

Solution code:
import itertools
import bisect
import numpy as np

def numpy_combinations(arr):
  r, c = np.triu_indices(len(arr), 1)
  return np.stack((arr[r], arr[c]), 1)
 
n,k = [int(i) for i in input().split()]

l = [int(i) for i in input().split()]
p = numpy_combinations(np.array(l))

ans = []
for x,y in p:
    bisect.insort(ans,x*y)
    
print(ans[k-1])

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
S = list(map(int,input().split()))
A = []
B = []
C = []
for s in S:
    if s>0:A.append(s)
    elif s==0:B.append(s)
    else:C.append(s)
a,b,c = len(A),len(B),len(C)
k = 0
if K<=a*c:k = 1
elif K<=(b*(2*N-1-b)//2):k=2
else:k=3
H = []
if k==1:
    for i in range(a):
        for j in range(c):
            H.append(A[i]*C[j])
    H.sort()
    print(H[K-1])
elif k==2:
    print(0)
elif k==3:
    for i in range(a-1):
        for j in range(i+1,a):
            H.append(A[i]*A[j])
    for i in range(c-1):
        for j in range(i+1,c):
            H.append(C[i]*C[j])
    H.sort()
    K = (N*(N-1)//2)-K
    print(H[-K-1])

Submission status: Runtime Error

Solution code:
n, k = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort()
if 0 in nums:
  index = nums.index(0)
  if index == 0:
    print(nums[1] * nums[k]
  if index == n-1:
    print(nums[-2] * nums[-k - 1]
  else:
      num_neg = index
      num_pos = n - index
      if k < num_neg * num_pos:
          s = k // num_pos
          f = k % num_pos
          if f == 0:
              print(nums[-s] * nums[index+1])
          else:
              print(nums[-s-1] * nums[-f-1])
      else:
          new_list = nums[index:] + [-x for x in nums[:inedex]]
          new_list.sort()
          print(new_list[1] * new_list[k]
else:
    l, h = 0, n - 1
    while l < h:
    m = (l+h) // 2
    if nums[m] >= 0:
        h = m
    else:
        l = m + 1
    index = l
    num_neg = index
    num_pos = n - index
    if k < num_neg * num_pos:
        s = k // num_pos
        f = k % num_pos
        if f == 0:
            print(nums[-s] * nums[index+1])
        else:
            print(nums[-s-1] * nums[-f-1])
    else:
        new_list = nums[index:] + [-x for x in nums[:inedex]]
        new_list.sort()
        print(new_list[0] * new_list[k-1]

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
neg,zer,pos=0,0,0
for a in A:
  if a<0:
    neg+=1
  elif a==0:
    zer+=1
  else:
    pos+=1
N,P=A[:neg],A[neg+zer:]
import bisect

a=neg*pos
b=a+zer*(neg+pos)+zer*(zer-1)//2

if k<=a:
  l,r=N[0]*P[-1],N[-1]*P[0]
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-n
      x=mid//nn
      ct+=pos-bisect.bisect_right(P,x)
    if ct>=k:
      r=mid
    else:
      l=mid
  print(r)
elif k<=b:
  print(0)
else:
  k-=b
  l,r=min(N[0]**2,P[0]**2),max(N[-1]**2,P[-1]**2)
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=neg-bisect.bisect_left(N,-x)
      if nn**2<=mid:
        ct-=1
    for pp in P:
      x=mid//pp
      ct+=bisect.bisect_right(P,x)
      if pp**2<=mid:
        ct-=1
    if ct>=2*k:
      r=mid
    else:
      l=mid
  print(r)

Submission status: Runtime Error

Solution code:
import collections

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

nums = list(map(int, input().split()))


negaCnt = 0
zeroCnt = 0
posiCnt = 0

for num in nums:
    if num == 0:
        zeroCnt += 1
    elif num > 0:
        posiCnt += 1
    else:
        negaCnt += 1

negaResult = negaCnt * posiCnt

if negaResult >= k:
    # 答えは負の組み合わせのいずれか
    negaIdx = (k-1) // posiCnt
    posiIdx = (k-1) % posiCnt

    snums = sorted(nums)
    negaLst = snums[:negaCnt]
    posiLst = snums[negaCnt+zeroCnt:]

    negaNum = negaLst[negaIdx]
    posiNum = posiLst[posiIdx]

    print(negaNum*posiNum)
    
elif negaResult+zeroCnt >= k:
    # 答えはぜろ
    print(0)
else:
    # 答えは正
    
    # 絶対値の小さい順に並べる

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
M = [i for i in A if i < 0]
m = len(M)
Z = [i for i in A if i == 0]
z = len(Z)
P = [i for i in A if i > 0]
p = len(P)

B = []

if (K > m*p) and (K <= m*p + m + p):
  print(0)
  
if K < m*p:
  for i in range(len(M)):
    for j in range(len(P)):
   		 B.append(M[i]*P[j])
b = sorted(B)
print(b[K-1])

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,k = nm()
l = nl()
f = list(filter(lambda x:x>0, l))
g = list(filter(lambda x:x<0, l))
f.sort(); g.sort(reverse=True)
pl = len(f); mi = len(g)
ze = n - pl - mi
tomi = pl*mi
if tomi >= k:
    def jud(z):
        ret = 0
        i = mi
        for x in f:
            while i and x*g[i-1] <= z: i -= 1
            ret += mi - i
        return ret
    ok,ng = 0,max(f)*min(g)-1
    while ok - ng > 1:
        mid = (ok+ng)//2
        if jud(mid) < k:
            ng = mid
        else:
            ok = mid
    print(ok)
    exit(0)

tomi += ze*(n-ze) + (ze-1)*ze//2
if tomi >= k:
    print(0); exit(0)

else:
    k -= tomi
    def jud2(z):
        ret = 0
        i = pl
        for e,x in enumerate(f):
            while i and f[i-1]*x > z: i -= 1
            ret += i - (e<=i-1)
        i = mi
        for e,x in enumerate(g):
            while i and g[i-1]*x > z: i -= 1
            ret += i - (e<=i-1)
        return ret//2
    ok,ng = 0,max(max(f)**2, min(g)**2)
    while ng - ok > 1:
        mid = (ok+ng)//2
        if jud2(mid) < k:
            ok = mid
        else:
            ng = mid
    print(ng)

Submission status: Runtime Error

Solution code:
import itertools
N, K= map(int,input().split())
num_list = list(map(int,input().split()))
ans_list = [0]*(int(N*(N-1)/2))
count = 0
for i,j in itertools.combinations(num_list,2):
  ans_list[count] = i*j
  count += 1
ans_list.sort()
print(ans_list[K-1])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import numpy as np


N, K = [int(str) for str in input().strip().split()]
A = [int(str) for str in input().strip().split()]

AA = np.array(A).reshape(1, -1).repeat(N, axis=0)
timess = (AA * AA.T)[np.where(np.tri(N, k=-1) == 1)]
timess.sort()
print(timess[K - 1])

Submission status: Runtime Error

Solution code:
cnt, tar = list(map(int, input().splirt()))
tar_list = list(map(int, input().splirt()))
calc_list = [] * ((cnt * (cnt -1))/2)
cnt = 0
for i in range(cnt) - 1:
  for j in range(i, cnt):
    calc_list[cnt] = tar_list[i] * tar_list[j]
    cnt += 1

calc_list = sorted(calc_list)
print(calc_list[tar -1])

Submission status: Runtime Error

Solution code:
import collections

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

nums = list(map(int, input().split()))


negaCnt = 0
zeroCnt = 0
posiCnt = 0

for num in nums:
    if num == 0:
        zeroCnt += 1
    elif num > 0:
        posiCnt += 1
    else:
        negaCnt += 1

negaResult = negaCnt * posiCnt

if negaResult >= k:
    # 答えは負の組み合わせのいずれか
    negaIdx = (k-1) // posiCnt
    posiIdx = (k-1) % posiCnt

    snums = sorted(nums)
    negaLst = snums[:negaCnt]
    posiLst = snums[negaCnt+zeroCnt:]

    print(negaLst, posiLst, negaIdx, posiIdx)

    negaNum = negaLst[negaIdx]
    posiNum = posiLst[posiIdx]

    print(negaNum*posiNum)
    
elif negaResult+zeroCnt >= k:
    # 答えはぜろ
    print("0")
else:
    # 答えは正
    
    # 絶対値の小さい順に並べる

Submission status: Runtime Error

Solution code:
def main():
    n,k=map(int,input().split())
    A=tuple(map(int,input().split()))
    L=[0]*(n*(n-1)//2)
    s=0
    for i in range(n-1):
        for j in range(i+1,n):
            L[s]= A[i]*A[j]
            s += 1
    print(sorted(L)[k-1])
main()

Submission status: Runtime Error

Solution code:
import math
import numpy as np
n,k=(int(x) for x in input().split())
a=list(map(int, input().split()))
m=int(n*(n-1)/2)
b=np.zeros(m)

for i in range(0,n-1):
    for j in range (i+1,n):
        l=int((2*n-1-i)/2*i+j-i-1)
        b[l]=a[i]*a[j]
b_sort=np.sort(b)
print(int(b_sort[k-1]),b)

Submission status: Runtime Error

Solution code:
import itertools
N, K= map(int,input().split())
num_list = list(map(int,input().split()))
ans_list = [0]*(N*(N-1)//2)

count = 0
for i,j in itertools.combinations(num_list,2):
  ans_list[count] = i*j
  count += 1
ans_list.sort()
print(ans_list[K-1])

Submission status: Runtime Error

Solution code:
import itertools
N, K = map(int, input().split())
L = list(set(list(map(int, input().split()))))
combis=list(itertools.permutations(L, 2))
sekis=[]
for i in combis:
    sekis.append(i[0]*i[1])
ans=sorted(sekis)
print(ans[K-1])

Submission status: Runtime Error

Solution code:
for b in range(n):
    a[b]=int(a[b])

mulli=[]
p=n
for i in range(n-1):
    p=p-1
    for j in range(p):
        mulli.append(a[i]*a[j+i+1])
        mulli=sorted(mulli)

print(mulli[k-1])

Submission status: Runtime Error

Solution code:
def pairs(n , k , a):

    kakelist = []
    for i,q in a:
        for w in range(1 + i , n):
            kakelist.append(q * a[w])

    kakelist.sort()

    return kakelist[k - 1]

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
neg,zer,pos=0,0,0
for a in A:
  if a<0:
    neg+=1
  elif a==0:
    zer+=1
  else:
    pos+=1
N,P=A[:neg],A[neg+zer:]
import bisect

a=neg*pos
b=a+zer*(neg+pos)+zer*(zer-1)//2

if k<=a:
  l,r=N[0]*P[-1],N[-1]*P[0]
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-n
      x=mid//nn
      ct+=bisect.bisect_right(P,x)
    if ct>=k:
      r=mid
    else:
      l=mid
  print(r)
elif k<=b:
  print(0)
else:
  k-=b
  l,r=min(N[0]**2,P[0]**2),max(N[-1]**2,P[-1]**2)
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=neg-bisect.bisect_left(N,-x)
      if nn**2<=mid:
        ct-=1
    for pp in P:
      x=mid//pp
      ct+=bisect.bisect_right(P,x)
      if pp**2<=mid:
        ct-=1
    if ct>=2*k:
      r=mid
    else:
      l=mid
  print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
n, k = map(int, input().split())

ss = int(n * (n - 1) / 2)

numbers = np.array(list(map(int, input().split())), dtype=np.int64)

res = np.zeros(ss, dtype=np.int64)
s = 1
test = 0
for i in range(n):
    for j in range(s, n):
        res[test] = numbers[i] * numbers[j]
        test += 1
    s += 1

res.sort()

print(res[k - 1])

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
inf = float("inf")
b = [inf]*(n*(n-1)//2)
c = 0

for i in range(n):
  for j in range(i+1,n):
    b[c] =a[i]*a[j]
    c += 1
d = sorted(b)
print(d[k])

Submission status: Runtime Error

Solution code:
import bisect
n,k = map(int,input().split( ))
a = list(map(int, input().split( )))

a.sort()

#2分探索
#負の数あるぞ

j = bisect.bisect_left(a,-0,1)
l = bisect.bisect_right(a,0.1)
a1 = a[:j]
a2 = a[l:]
if (j+1)*(n-l)>=k:##負の数で揃う
    mx = 0
    mn = -max(a1[0]*a1[0],a2[0]*a2[0])-1
    while mx-mn>1:
        md = (mx+mn)//2
        cnt = 0
        for t in range(j):
            tmp = bisect.bisect_left(a2,md/a1[t])
            cnt += n-l-tmp 
        if cnt >=k:
            mx = md
        else:
            mn = md
        print(mx)
        exit()
k -= j*(n-l)

if k<=(l-j)*(l-j-1)//2+(n-l+j)*(l-j):
    print(0)
    exit()
#print(k,(n-l+j)*(l-j)+(l-j)*(l-j-1)//2)
k-=(l-j)*(l-j-1)//2+(n-l+j)*(l-j)
#print(k,k)
mx = max(a1[0]*a1[0],a2[-1]*a2[-1])+1
mn = -1
a1 = [-a1[j-i-1] for i in range(j)]
while mx-mn>1:
    md = (mx+mn)//2
    cnt = 0
    for t in range(j):
        tmp = bisect.bisect_right(a1,md//a1[t])
        cnt += tmp
        if tmp >=t+1:
            cnt-=1
    for t in range(n-l):
        tmp = bisect.bisect_right(a2,md//a2[t])
        cnt += tmp
        if tmp>=t+1:
            tmp-=1
    if cnt >= 2*k:
        mx = md
    else:
        mn = md
print(mx)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split))
a=[]
for i in range(n):
    for j in range(i+1,n):
        a.append(l[i]*l[j])
a.sort()
print(a[k-1])

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
p = [0]*(n*(n-1)//2)
c=0
for i in range(n-1):
  for j in range(i+1, n):
    p[c]=a[i]*a[j]
    c+=1
p.sort()
print(p[k-1])

Submission status: Runtime Error

Solution code:
import math

n=int(input())
m=int(math.log(n))
p=int(math.pow(10,m))
num=int(math.pow(10,m))
if m==num:
    m+=1
pp=int(math.pow(10,m))
t=int(n-m)
sum=0
if t>=p/2:
    sum+=(p-t)
    sum+=int(n/pp)
    sum+=1
else:
    sum+=int(n/pp)
    sum+=t
    
print(sum)