PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000059. Tích nhỏ thứ K của các cặp (Pairs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Tích nhỏ thứ K của các cặp (Pairs)

Pairs

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn integers A1,A2,…,AnA_1,A_2,\ldots,A_n. For every pair of indices 1≤i<j≤n1\le i<j\le n, compute the product AiAjA_iA_j. There are exactly n(n−1)/2n(n-1)/2 products, and equal products are retained with their multiplicities.

Sort all products in nondecreasing order. Find the value at 1-based position KK in this sorted list. Input elements may be negative, zero, or positive.

Input

  • The first line contains integers n,Kn,K: the number of elements and desired 1-based rank.
  • The second line contains exactly nn integers A1,…,AnA_1,\ldots,A_n.

Output

Print one integer: the KK-th smallest product over all distinct-index pairs.

Subtasks

  • Subtask 1 (20 points): 2≤n≤162\le n\le 16; 1≤K≤n(n−1)/21\le K\le n(n-1)/2; −109≤Ai≤109-10^9\le A_i\le10^9 for every ii.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; 1≤K≤n(n−1)/21\le K\le n(n-1)/2; −109≤Ai≤109-10^9\le A_i\le10^9 for every ii.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le 200000; 1≤K≤n(n−1)/21\le K\le n(n-1)/2; −109≤Ai≤109-10^9\le A_i\le10^9 for every ii.

Examples

Input

4 3
3 3 -4 -2

Output

-6

Explanation

For [3,3,−4,−2][3,3,-4,-2], the six index-pair products are 9,−12,−6,−12,−6,89,-12,-6,-12,-6,8. Sorting yields [−12,−12,−6,−6,8,9][-12,-12,-6,-6,8,9]. The K=3K=3-rd value is −6-6. Equal products appear as many times as their index pairs.