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:
import itertools
import sys
input = sys.stdin.readline

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

P = A[:K]

nums = [i for i in range(len(P))]
seki = sorted([P[i[0]] * P[i[1]] for i in itertools.combinations(nums, 2)])

print(seki[K - 1])

Submission status: Runtime Error

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

A.sort()

minus=[]
zero=[]
plus=[]

for i in range(N):
    tem=A[i]
    if tem<0:
        minus.append(tem)
    elif tem==0:
        zero.append(tem)
    else:
        plus.append(tem)

Lminus=len(minus)
Lplus=len(plus)
minus_No=Lminus*Lplus
plus_No=(Lminus*(Lminus-1))//2+(Lplus*(Lplus-1))//2
zero_No=(N*(N-1))//2-minus_No-plus_No


ans=[]
if K<=minus_No:
    for i in range(Lminus):
        for j in range(Lplus):
            temp=minus[i]*plus[j]
            ans.append(temp)
    ans.sort()
    print(ans[K-1])
elif K>(minus_No+plus_No):
    for i in range(Lminus-1):
        for j in range(i+1,Lminus):
            temp=minus[i]*minus[j]
            ans.append(temp)
    for i in range(Lplus-1):
        for j in range(i+1,Lplus):
            temp=plus[i]*plus[j]
            ans.append(temp)
    ans.sort()
    print(ans[K-(minus_No+zero_No)-1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin

def get_result(data):
    N, K = data[0]
    A = data[1]
    output_lens = int(N * (N-1) / 2)
    output = np.zeros(output_lens)
    idx = 0
    for i in range(N):
        for j in range(i+1, N):
            output[idx] = A[i] * A[j]
            idx += 1
    output = sorted(output)
    return output[K-1]

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# ABC155 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict as dd
from operator import itemgetter
n,K=nm()
a=nl()
ans=0
pl=dd(int)
mi=dd(int)
pp,mm=[],[]
for aa in a:
    if aa<0:
        mm.append(aa)
    else:
        pp.append(aa)
mm.sort()
pp.sort(reverse=True)
for aa in a:
    if aa<0:
        mi[aa]+=1
    else:
        pl[aa]+=1
mi_s=0
pl_s=0
if len(mi)>0:
    mi=sorted(mi.items(),key=lambda x:x[0])
    for mii in mi:
        mi_s+=mii[1]
    # for k,v in mi.items():
    #     mi_s+=v
if len(pl)>0:
    pl=sorted(pl.items(),key=lambda x:x[0],reverse=True)
    for pll in pl:
        pl_s+=pll[1]
    # for k,v in pl.items():
    #     pl_s+=v
if len(mi)>0 and len(pl)>0:
    print(mi)
    print(pl)
    pl_idx=0
    t1=0
    for pll in pl:
        t1+=mi_s*pll[1]
        if t1<=K:
            # pl_idxを更新する
            break
        pl_idx+=1
    for i,mii in enumerate(mm):
        if K-t1==0:
            ans=pl[pl_idx][1]*mii[0]
            print(ans)
            exit()

        ans=pl[pl_idx][1]*mii[K-t1]
        print(ans)
        exit()
elif len(mi)==0:# plusだけ
    for i in range(len(pp)-1):
        if i==K-1:
            ans=pp[i]*pp[i+1]
            print(ans)
            exit()
elif len(pl)==0:# minusだけ
    for i in range(len(mm)-1):
        if i==K-1:
            ans=mm[i]*mm[i+1]
            print(ans)
            exit()

Submission status: Runtime Error

Solution code:
L = [int(i*j) for i,j in itertools.combinations(A,2)]
L.sort()
print(L)

Submission status: Runtime Error

Solution code:
def main():
    N,K = map(int, input().split())
    a = list(map(int, input().split()))
    c = []
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            c.append(a[i]*a[j])
            c.sort()
            print(c[K-1])
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
n, k = map(int,input().split())
b = np.array(list(map(int,input().split())))
         
def onecold(a):
    n = len(a)
    s = a.strides[0]
    strided = np.lib.stride_tricks.as_strided
    b = np.concatenate((a,a[:-1]))
    return strided(b[1:],shape=(n-1,n),strides=(s,s))

def numpy_permutations(a):
    n = len(a)
    out = np.empty((n,n-1,2),dtype=a.dtype)
    out[:,:,0] = np.broadcast_to(a[:,None],(n,n-1))
    out.shape = (n-1,n,2)
    out[:,:,1] = onecold(a)
    out.shape = (-1,2)
    return out

ans = numpy_permutations(b)

ans = np.prod(ans, axis = 1)
ans = np.sorted(ans)

print(ans[2k-1])

Submission status: Runtime Error

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

for i in A:
    if i >= 0:
        P.append(i)
    else:
        M.append(i)
P.sort()
M.sort()

def solve(l,r):
    if l == r:
        return l
    mid = (l+r)//2
    count = 0
    for i in range(len(P)):
        count += max(0,funcPP(0,len(P)-1,P[i],mid)-i)
    for i in range(len(M)):
        count += max(0,funcM(0,len(M)-1,M[i],mid)-i)
    for i in range(len(P)):
        count += max(0,funcPM(0,len(M)-1,P[i],mid))
    print(mid,count,l,r)
    if count >= K:
        return solve(l,mid)
    else:
        return solve(mid+1,r)

def funcM(l,r,p,thre,key=lambda x,y:x>y): # 負の数
    if l >= r:
        return l
    mid = (l+1+r)//2
    if key(P[mid]*p,thre):
        return funcM(mid+1,r,p,thre)
    else:
        return funcM(l,mid,p,thre)

def funcPM(l,r,p,thre):
    if l >= r:
        return l
    mid = (l+1+r)//2
    if M[mid]*p > thre:
        return funcPM(mid+1,r,p,thre)
    else:
        return funcPM(l,mid,p,thre)

def funcPP(l,r,p,thre): # 正の数
    if l >= r:
        return l
    mid = (l+1+r)//2
    if P[mid]*p>thre:
        return funcPP(l,mid-1,p,thre)
    else:
        return funcPP(mid,r,p,thre)

print(solve(-(10**20),10**20))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
cn=0
pl=[]
nl=[]
for i in l:
    if i>0:
        pl.append(abs(i))
    else:
        nl.append(abs(i))
pn=n-cn
total=pn*cn
if(k<=total):
    for j in range(cn):
        if k<=pn:
            print(j)
            print(j+k)
            print(l[j]*l[j+k])
            break
        else:
            k-=pn
        print(k)
else:
    k=k-total
    pl=sorted(pl)
    nl=sorted(nl)
    ss=[]
    for i in range(len(pl)):
        for j in range(i+1,len(pl)):
            ss.append(pl[i]*pl[j])
    for i in range(len(nl)):
        for j in range(i+1,len(nl)):
            ss.append(nl[i]*nl[j])  
    ss=sorted(ss)
    print(ss[k])

Submission status: Runtime Error

Solution code:
from bisect import bisect_right, bisect_left

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

t0 = bisect_left(A,0)
t1 = bisect_right(A,0)
pos = A[t1:]
neg = [-v for v in reversed(A[:t0])]
zeros = t1-t0
offset_negative = len(pos)*len(neg)
offset_zero = zeros*(N-zeros) + zeros*(zeros-1)//2
offset = offset_zero + offset_negative

def bisect2(ng, ok, judge):
    while abs(ng-ok) > 1:
        m = (ng+ok)//2
        if judge(m):
            ok = m
        else:
            ng = m
    return ok

def count1(l,n):
    j = len(l)
    cnt = 0
    for i,a in enumerate(l):
        v = n//a
        while j > i and l[j-1] > v:
            j -= 1
        if j <= i:
            break
        else:
            cnt += j-i-1
    return cnt

def count2(l1,l2,n):
    j = len(l2)
    cnt = 0
    for i,a in enumerate(l1):
        v = n//a
        while j > 0 and l2[j-1] > v:
            j -= 1
        cnt += j
    return cnt


def cnt(n):
    if n > 0:
        cnt = count1(pos,n-1) + count1(neg,n-1) + offset
    else:
        cnt = offset_negative - count2(pos,neg,-n)
    return cnt


if offset_negative <= K < offset:
    print(0)
else:
    temp = max(pos[-1],neg[-1])**2
    print(bisect2(temp, -temp, lambda n: cnt(n) <= K-1))

# from itertools import combinations
# s = sorted(a*b for a,b in combinations(A,2))
# for i,v in enumerate(s):
#     print(cnt(v),i,v)

Submission status: Runtime Error

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

A=list(map(int, input().split()))
B=np.zeros(N(N-1)/2)
i=0
for i in range(1, N):
  for j in range(i):
    B[i]=A[i]*A[j]
    i+=1
B=np.sort(B)

print(B[K-1])

Submission status: Runtime Error

Solution code:
first = [int(k) for k in input().split()]
secound = [int(k) for k in input().split()]
secound.sort()
zero_number = len([n for n in secound if n == 0])
non_zero_number = len([n for n in secound if not n == 0])
minus_number = len([n for n in secound if n <  0])
plus_number = len([n for n in secound if  n >  0])

minus = minus_number*plus_number
zero  = zero_number*non_zero_number

line = []
first1 = first[1]
if first1 > minus:
  first1 = first1 - minus
  if first1 > zero:
    first1 = first1 - zero
    for k in range(minus_number):
      for t in range(minus_number):
        if t == k:
          pass
        else:
          line.append(secound[k]*secound[t])
    for k in range(plus_number):
      for t in range(plus_number):
        if t == k:
        else:
          line.append(secound[k+zero_number+minus_number]*secound[t+zero_number+minus_number])
    print(line.sort()[first1-1])
    break
  else:
    print(0)
    break
else:
  for k in range(minus_number):
    for t in range(plus_number):
      line.append(secound[k]*secound[t+zero_number+minus_number])
  print(line.sort()[first1-1])

Submission status: Runtime Error

Solution code:
import bisect
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
A = np.sort(A)

Aneg = A[A < 0]
Azero = A[A == 0]
Apos = A[A > 0]

neg = len(Aneg)
zero = len(Azero)
pos = len(Apos)

Nneg = neg * pos
Npos = 0
if neg > 0:
    Npos += neg * (neg - 1) // 2
if pos > 0:
    Npos += pos * (pos - 1) // 2
Nzero = N * (N - 1) // 2 - Npos - Nneg
print(Nneg, Npos, Nzero)


def C(N, ar):
    if len(ar) <= 1:
        return 0
    tmp = np.arange(len(ar))+1
    n = np.searchsorted(ar, N / ar, side="left")
    return (len(ar)-np.maximum(n, tmp)).sum()


def C1(N, ar1, ar2):
    tmp = np.arange(len(ar1))+1
    n = np.searchsorted(ar1, N / ar2, side="left")
    return (len(ar1)-np.maximum(n, tmp)).sum()


def bs_Neg():
    l, r = -10 ** 20, 0
    while r - l > 1:
        m = (r - l) // 2
        num = C1(m, Apos, Aneg)
        if num < K:
            r = m
        else:
            l = m
    return l


def bs_Pos(K):
    l, r = 0, 10 ** 20
    while r - l > 1:
        m = (r - l) // 2
        num = C(m, Apos) + C(m, Aneg)
        if num < K:
            r = m
        else:
            l = m
    return l


if K <= Nneg:
    ans = bs_Neg()
elif K <= Nneg + Nzero:
    ans = 0
else:
    K = K-Nneg-Nzero
    ans = bs_Pos(K)

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))
Am = [i for i in A if i < 0]
Ap = [i for i in A if i > 0]
Az = [i for i in A if i == 0]
cnt = 0
flg = 0
ans = 0
for i in sorted(Am):
  for j in sorted(Ap, reverse=True):
    if cnt == K: flg = 1; ans = i*j; break
    cnt += 1
if flg == 0: cnt += len(Az)*(len(Am)+len(Ap))
if cnt > K: flg = 1; ans = 0; 
if flg == 0:
  ansl = []
  for i,j in combinations(Am, 2):
    ansl += [i*j]
  for i,j in combinations(Ap, 2):
    ansl += [i*j]
  ans = sorted(ansl)[K-cnt]
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
a = int(input().split())
a.sort()
cnt = 0
for i in range(len(a)):
    for j in range(len(a) - i):
        num = a[j]*a[i]
        if cnt == K:
            print(num)
            if a[i] < 0 and num > 0:
                pass
            else:
                cnt += 1

Submission status: Runtime Error

Solution code:
def myfunc(j):
	if i+j+1 == N:
		return 0;
	for i in range(N):
		if i+j+1 < N:
			seki.append(A[i]*A[i+j+1])
	myfunc(j+1)

N, K = map(int,input().split())
A = list(map(int,input().split()))
seki = []
myfunc(j)
seki_new = sorted(seki)
print(seki_new[K-1])

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split()) 
A = list(map(int, input().split()))
U = []
def fun(X, Y):
  while X < Y:
    U.append(A[X]*A[Y])
    X = X +1
  return U

for i in range(N):
  fun(i-1,N)
U.sort()
print(U[K])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(key=lambda x: abs(x))
    print(N*(N - 1) // 2)
    # ２つしかなければそれで終わりなので、答えを表示
    if N == 2:
        print(A[0] * A[1])
        quit()

    # 答えが負数か正数か確認
    minus_count = len(list(filter(lambda x:x < 0, A)))
    minus_pair_count = minus_count * (N - minus_count)
    target_is_negative = True if K <= minus_pair_count else False

    ans = []
    end_flag = False

    # 対象が負の数であれば
    if target_is_negative:
        # 負の数の大きい方と小さい方どちらよりか確認
        t_is_smaller = True if K < (minus_pair_count // 2) else False

        if t_is_smaller:
            # 絶対値が大きい方から負数を計算していく
            for i in range(N - 1, 0, -1):
                for j in range(i -1, -1, -1):
                    t = A[i] * A[j]
                    if t < 0:
                        ans.append(t)
                        if len(ans) == K:
                            end_flag = True
                            ans.sort()
                            break
                if end_flag:
                    break
        else:
            # 計算結果が負の数のうち大きい方から何番目か計算
            newK = minus_pair_count - K
            for i in range(N - 1):
                for j in range(i + 1, N):
                    t = A[i] * A[j]
                    if t < 0:
                        ans.append(t)
                        if len(ans) == newK + 1:
                            end_flag = True
                            ans.sort(reverse=True)
                            break
                if end_flag:
                    break
    else:
        # 対象が正の数であれば
        plus_pair_count = ((N * (N - 1)) // 2) - minus_pair_count
        newK = K - minus_pair_count
        t_is_smaller = True if newK < (plus_pair_count // 2) else False

        if t_is_smaller:
            for i in range(N - 1):
                for j in range(i + 1, N):
                    t = A[i] * A[j]
                    if t >= 0:
                        ans.append(t)
                        if len(ans) == newK:
                            end_flag = True
                            ans.sort()
                            break
                if end_flag:
                    break
        else:
            newK = plus_pair_count - newK
            for i in range(N - 1, 0, -1):
                for j in range(i - 1, -1, -1):
                    t = A[i] * A[j]
                    if t > 0:
                        ans.append(t)
                        if len(ans) == newK + 1:
                            end_flag = True
                            ans.sort(reverse=True)
                            break
                if end_flag:
                    break

    print(ans[-1])

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
r = []
tmp = 0

p = [i for i in a if i >= 0]
m = [i for i in a if i < 0]

for i in range(len(m)):
    for j in range(len(p)):
            r.append(m[i]*p[j])

r.sort()

if len(r) >= k:
    print(r[k-1])
    tmp = 1

for i in range(k):
    for j in range(k):
        if i < len(m) and j < len(m) and i < j:
            r.append(m[i]*m[j])
        if i < len(p) and j < len(p) and i < j: 
            r.append(p[i]*p[j])

if tmp == 0:
    r.sort()
    print(r[k-1])

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
neg,pos = [],[]
for i in a:
  if i < 0:
    neg.append(i)
  else:
    pos.append(i)
neg.sort()
pos.sort()

if len(neg)*len(pos) <= k:
  print(neg[k//len(pos)]*pos[k%len(pos)])
else:
  neg_ind = 1
  pos_ind = 1
  now = 1
  while(1):
    if pos[pos_ind] > abs(neg_ind):
      tmp = len(pos)-pos_ind
      num = 1
      pos_ind += 1
    elif neg[pos_ind] < abs(neg_ind):
      tmp = len(neg)-neg_ind
      num = -1
      neg_ind += 1
    else:
      tmp = len(neg)-neg_ind + len(pos)-pos_ind
      num = 1
      pos_ind += 1
      neg_ind += 1
    if now+tmp > k:
      break
    else:
      now += tmp
    print(pos[pos_ind-1]*pos[k-(len(pos)-pos_ind)] if num==1 else neg[neg_ind-1]*neg[k-(len(pos)-pos_ind)])

Submission status: Runtime Error

Solution code:
import itertools
import functools
import operator
n,k = map(int, input().split())
a = list(map(int, input().split()))
tmp = []
for i in itertools.combinations(a, 2):
    v = functools.reduce(operator.mul, list(i))
    tmp.append(v)
sorted(tmp)
print(tmp[k+1])

Submission status: Runtime Error

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

a_li.sort()

rem_k = k
for i in range(1, n + 1):
    if rem_k - (n - i) < 0:
        round_index = i - 1
        break
    rem_k -= (n - i)
min_index = rem_k + 1
round_num = a_li[round_index]
del a_li[round_index]

# マイナスの値がある
if a_li[0] < 0:
    ans = round_num * a_li[-1 * (min_index + 1)]
# マイナスの値がない
else:
    ans = round_num * a_li[min_index]

print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
po = []
ng = []
zr = 0
for i in range(n):
  if a[i]>0:
    po.append(a[i])
  elif a[i]<0:
    ng.append(a[i])
  elif a[i]==0:
    zr += 1
lp=len(po)
ln=len(ng)
negn=lp*ln
zern=zr*(n-zr)

if k <= negn:
  p=[0]*negn
  c=0
  for i in range(lp):
    for j in range(ln):
      p[c]=po[i]*ng[j]
      c+=1
  p.sort()
  print(p[k-1])
elif negn < k <= negn+zern:
  print(0)
else:
  p=[0]*(n*(n-1)//2-negn-zern)
  c=0
  for i in range(lp-1):
    for j in range(i+1, lp):
      p[c]=po[i]*po[j]
      c+=1
  for i in range(ln-1):
    for j in range(i+1, ln):
      p[c]=ng[i]*ng[j]
      c+=1
  p.sort()
  print(p[k-1-negn-zern])

Submission status: Runtime Error

Solution code:
N, K = input().split()
N = int(N)
K = int(K)
A_list = input().split()
A_array = np.array([int(Ai) for Ai in A_list])

A_minus_array = A_array[A_array < 0]
A_plus_array = A_array[A_array >= 0]

A_minus_num = len(A_minus_array)
if A_minus_num*(N-A_minus_num) > K:
    multi_A = []
    for A_minus in A_minus_array:
        for A_plus in A_plus_array:
            multi_A.append(A_minus*A_plus)
    print(sorted(multi_A)[K])
else:
    K_ = K - A_minus_num*(N-A_minus_num)
    print(K_)
    A_abs_sorted_array = sorted(abs(A_array))
    row = int((2*N-1 - np.sqrt((2*N-1)**2-8*K_))/2)
    print(row)
    col = K_ - int(row*(2*N-row-1)/2)
    print(col)
    if col == 0:
        print(A_abs_sorted_array[row-1]*A_abs_sorted_array[row+col])
    else:
        print(A_abs_sorted_array[col]*A_abs_sorted_array[row+col])

Submission status: Runtime Error

Solution code:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
bottom = 0
top = len(A)-1
search = math.ceil(math.sqrt(N))
if N%2 == 0:
    middle = len(A)//2
else:
    middle = len(A)//2+1
for i in range(100):
    if middle < search:
        middle = (top+middle)//2
    elif middle > search:
        middle = middle//2
    else:
        print(A[middle]*A[middle**2-K])
        break

Submission status: Runtime Error

Solution code:
import math

count, index = input().split()
ary = (int(x) for x in input().split())
ary1 = []
ary2 = []
for i in ary:
    ary1.append(i)
    ary2.append(i)
seki = []

cnt1 = 0
cnt2 = 0
for i in ary1:
    #半分行ったら終了
    if cnt1 >= math.ceil(int(count)/2):
        break
    for j in ary2:
        if cnt1 != cnt2:
            seki.append(i * j)
        cnt2 = cnt2 + 1
    cnt2 = 0
    cnt1 += 1
seki.sort()
print(seki[int(index)])
#print(seki[count[1]])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


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

result = [tem for i in range(0,n-1) for j in range(i,n-1)]


result.sort()

print(result[k-1])

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
A = input().split()
Alist = []
for i in A :
    Alist += [int(i)] 

print(Alist)
result = []
count = 1
for j in Alist :
    for k in Alist[count:] :
        result += [j*k]
    count += 1

ans = sorted(result)
print(ans[1-k])

Submission status: Runtime Error

Solution code:
import numpy as np
n,k = [int(i) for i in input().split()]
l = np.array([int(i) for i in input().split()])
r, c = np.triu_indices(n, 1)
ans = l[r] * l[c]
p = np.sort(ans)
print(p[k-1])

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A,B,C,X=[],[],[],[]
a=map(int,input().split())
for i in (a):
    if i==0:
        B.append(i)
    elif i<0:
        A.append(i)
    else:
        C.append(i)
D=len(A)*len(C)
if D>=K:
    for a in (A):
        for c in (C):
            d=a*c
            X.append(d)
    X.sort()
    print(X[K])
elif D+len(B)*(len(B)-1)/2>=K:
    print(0)
else:
    E=K-D-len(B)*(len(B)-1)/2
    for a in (A):
        for c in (A):
            d=a*c
            X.append(d)
    for a in (C):
        for c in (C):
            d=a*c
            X.append(d)
    X.sort()
    print(X[E])

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
seki = []
myfunc(j)
seki_new = sorted(seki)
print(seki_new[K-1])

def myfunc(j):
	if i+j+1 == N:
		return 0;
	for i in range(N):
		if i+j+1 < N:
			seki.append(A[i]*A[i+j+1])
	myfunc(j+1)

Submission status: Runtime Error

Solution code:
nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]

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

a_posi = []
a_nega = []
a_zero = []

for aa in a:
    if aa > 0:
        a_posi.append(aa)
    elif aa == 0:
        a_zero.append(aa)
    else:
        a_nega.append(aa)

a_posi.sort()
a_nega.sort()

num_a_posi = len(a_posi)
num_a_nega = len(a_nega)
num_a_zero = len(a_zero)

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

num_posi_result = combination(num_a_posi) + combination(num_a_nega)
num_nega_result = num_a_posi * num_a_nega
num_zero_result = combination(n) - num_posi_result - num_nega_result

nega_posi = 0

if k <= num_nega_result:
    nega_posi = -1
else:
    k -= num_nega_result
    if k <= num_zero_result:
        nega_posi = 0
    else:
        k -= num_zero_result
        nega_posi = 1

target_list = []
if nega_posi == -1:
    for ap in a_posi:
        target_list_ = []
        for an in a_nega:
            target_list_.append(ap*an)
        target_list.append(target_list_)
elif nega_posi == 0:
    target_list.append(0)
else:
    for i in range(len(a_posi)):
        target_list_ = []
        for j in range(i+1, len(a_posi)):
            target_list_.append(a_posi[i] * a_posi[j])
        target_list.append(target_list_)
    
    for i in range(len(a_nega)):
        target_list_ = []
        for j in range(i+1, len(a_nega)):
            target_list.append(a_nega[i] * a_nega[j])  
        target_list.append(target_list_)
    


index = 0
r = 0
while(index < k):
    b = [x[0] for x in target_list]
    min_index = b.index(min(b))
    r = min(b)

    target_list[min_index].pop(0)

    index += 1

print(r)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
list = list(map(int, input().split()))
len = len(list)
rlist = []

while(i<len):
  while(j<len):
    rlist.append(list[i] * list[i+j])
    j+=1
  i+=1

rlist.sort()
print(rlist[k])

Submission status: Runtime Error

Solution code:
import itertools
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
num_list = list(itertools.combinations(a_list,2))
print(num_list)

a = []
for i in range(len(num_list)):
    seki = num_list[i][0] * num_list[i][1]
    a.append(seki)
    
print(sorted(a)[k])

Submission status: Runtime Error

Solution code:
import sys
import heapq
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
A = sorted([int(x) for x in input().strip().split()])
minus = [x for x in A if x < 0]
zeros = [x for x in A if x == 0]
plus = [x for x in A if x > 0]

len_minus = len(minus)
len_zeros = len(zeros)
len_plus = len(plus)
if len_minus * len_plus >= K:
    cnt = 0
    mi = 0
    pi = 0
    q = [(minus[0]*plus[-1], mi, pi)]
    while cnt < K:
        cnt += 1
        v, mi, pi = heapq.heappop(q)
        if mi < len_minus - 1:
            heapq.heappush(q, (minus[mi+1]*plus[-1-pi], mi+1, pi))
        if pi < len_plus - 1:
            heapq.heappush(q, (minus[mi]*plus[-1-(pi+1)], mi, pi+1))
    print(minus[mi]*plus[-1-pi])
else:
    K -= len_minus * len_plus
    if len_zeros * (len_zeros - 1) // 2 + len_zeros * (len_minus + len_plus) >= K:
        print(0)
    else:
        K -= len_zeros * (len_zeros - 1) // 2 + len_zeros * (len_minus + len_plus)
        cnt = 0
        pi1 = 0
        pi2 = 0
        if len_plus > 1:
            pi2 = 1
        mi1 = 0
        mi2 = 0
        if len_minus > 1:
            mi2 = 1
        if plus[pi1]*plus[pi2] <= minus[-1-mi1]*minus[-1-mi2]:
            q = [(plus[pi1]*plus[pi2], pi1, pi2, 1)]
        else:
            q = [(minus[-1-mi1]*minus[-1-mi2], mi1, mi2, 0)]
        while cnt < K:
            cnt += 1
            v, i1, i2, f = heapq.heappop(q)
            if f == 1:
                if i1 + 1 < i2:
                    heapq.heappush(q, (plus[i1+1]*plus[i2], i1+1, i2, f))
                if i2 < len_plus - 1:
                    heapq.heappush(q, (plus[i1]*plus[i2+1], i1, i2+1, f))
            else:
                if i1 + 1 < i2:
                    heapq.heappush(q, (minus[-1-(i1+1)]*minus[-1-i2], i1+1, i2, f))
                if i2 < len_minus - 1:
                    heapq.heappush(q, (minus[-1-i1]*minus[-1-(i2+1)], i1, i2+1, f))
        if f == 1:
            print(plus[i1]*plus[i2])
        elif f == 0:
            print(minus[-1-i1]*minus[-1-i2])

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split())
s = []
for i in range(n):
    for j in range(i:):
        s.append(a[i]*a[j])

s.sort()
print(s[k])

Submission status: Runtime Error

Solution code:
import numpy as np

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

a_array = np.ones((n+1, n+1), dtype=np.int)
a_array_t = np.zeros((n, n), dtype=np.int)
ans_array = np.zeros(int(n*(n-1)/2), dtype=np.int)

for i in range(n):
  a_array[i+1,0]=a[i]
  a_array[0,i+1]=a[i]

for i in range(n+1):
  a_array[i,1:] = a_array[0,1:]*a_array[i,0]

a_array_t[:,:] = a_array[1:, 1:]
# print(a_array_t)

j=0
for i in range(1, n):
  ans_array[j:j+i] = a_array_t[-i-1, -i:]
  j += i

ans_sort = np.sort(ans_array)

print(ans_sort[k])

Submission status: Runtime Error

Solution code:
n = str(input())
l = len(n)
c = 0
n = "00"+ n
dnow = int(n[l+1])
for i in range(l+1):
  dnext = int(n[l-i])
  if  dnow <= 4:
    c += dnow
  elif dnow == 5:
    if dnext <= 4:
      c += 5
    else:
      dnext += 1
      c += 5
  elif dnow == 10:
    dnext += 1
  else:
    c += 10 - dnow
    dnext += 1
  dnow = dnext
print(c)

Submission status: Runtime Error

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

A=list(map(int, input().split()))
B=np.zeros(N(N-1)/2)
i=0
for i in range(1, N):
  for j in range(i):
    B[i]=A[i]*A[j]
    i+=1
B=sorted(B)

print(B[K-1])

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n,k=map(int,input().split())
a=list(map(int,input().split()))
a_pos=sorted(a)
a_nega=sorted(a,reverse=True)
def check(mid):
  sum_num=0
  for i in a_pos:
    if i>0:
      sum_num+=bisect_left(a_pos,mid//i)
    else:
      sum_num+=bisect_left(a_nega,mid//i)
    if i<mid//i:
      sum_num-=1
  sum_num//=2
  if sum_num>=k:
    return True
  return False
left=-10**9
right=10**9
while right-left>1:
  mid=(right+left)//2
  if check(mid):
    right=mid
  else:
    left=mid
if check(left):
  print(left)
else:
  print(right)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(key=lambda x: abs(x))
    # ２つしかなければそれで終わりなので、答えを表示
    if N == 2:
        print(A[0] * A[1])
        quit()


    maxK = N * (N - 1) // 2

    t_is_bigger = True if K > (maxK // 2) else False

    ans = []
    end_flag = False
    if t_is_bigger:
        for i in range(N - 1, 0 , -1):
            for j in range(i - 1, -1, -1):
                ans.append(A[i] * A[j])
                if len(ans) >= (maxK // 2):
                    end_flag = True
                    break
            if end_flag:
                break
        ans.sort(reverse=True)
        newk = K - (maxK // 2)
        print(ans[-newk + 1])
    else:
        for i in range(N - 1):
            for j in range(i + 1, N):
                ans.append(A[i] * A[j])
                if len(ans) >= (maxK // 2):
                    end_flag = True
                    break
            if end_flag:
                break
        ans.sort()
        print(ans[K])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n, k = input().split()
nums = input().split()

a = []
for i in range(n):
  for j in range(n-1):
    if (nums[i] * nums[j] in a) == False:
      a.append(nums[i] * nums[j])

a.sort()
print(a[k-1])

Submission status: Runtime Error

Solution code:
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = 10 ** 19

def check(mid):
    ret = 0
    for ai in a:
        ret += bisect.bisect_right(a, mid // ai)
    return ret

while True:
    if r - l < 1:
        print(mid)
        break
    mid = (l + r) //2
    if check(mid) < k:
        l = mid
    else:
        r = mid

Submission status: Runtime Error

Solution code:
N, K= map(int,input().split())
num_list = list(map(int,input().split()))
set_list = list(set(num_list))
count = 0
ans_list = []
for i in range(len(set_list)):
  num_a = set_list[i]
  count = num_list.count(num_a)
  if count >= 2:
    ans_list += [num_a**2] * int(count*(count-1)/2)
  for j in range(i+1,len(set_list)):
    num_b = set_list[j]
    count = num_list.count(num_a) * num_list.count(num_b)
    ans_list += [num_a*num_b] * count
ans_list.sort()
print(ans_list[K-1])