#ABC241D. [ABC241D] Sequence Query

[ABC241D] Sequence Query

Score : 400400 points

Problem Statement

We have an empty sequence AA. Given QQ queries, process them in order. Each query is of one of the following three types.

  • 1 x : Insert xx to AA.
  • 2 x k : Among the elements of AA that are less than or equal to xx, print the kk-th largest value. (kk is no more than 5\bf{5}) If there are less than kk elements of AA that are less than or equal to xx, then print -1.
  • 3 x k : Among the elements of AA that are greater than or equal to xx, print the kk-th smallest value. (kk is no more than 5\bf{5}) If there are less than kk elements of AA that are greater than or equal to xx, then print -1.

Constraints

  • 1Q2×1051\leq Q \leq 2\times 10^5
  • 1x10181\leq x\leq 10^{18}
  • 1k51\leq k\leq 5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ

query1\text{query}_1

query2\text{query}_2

\vdots

queryQ\text{query}_Q

In the ii-th query queryi\text{query}_i, the type of query cic_i (which is either 1,21, 2, or 33) is given first. If ci=1c_i=1, then xx is additionally given; if ci=2,3c_i=2, 3, then xx and kk are additionally given.

In other words, each query is given in one of the following three formats:

11 xx

22 xx kk

33 xx kk

Output

Print qq lines, where qq is the number of queries such that ci=2,3c_i=2,3. The jj-th line (1jq)(1\leq j\leq q) should contain the answer for the jj-th such query.

11
1 20
1 10
1 30
1 20
3 15 1
3 15 2
3 15 3
3 15 4
2 100 5
1 1
2 100 5
20
20
30
-1
-1
1

After query1,2,3,4\text{query}_{1,2,3,4} have been processed, we have A=(20,10,30,20)A=(20,10,30,20).

For query5,6,7\text{query}_{5,6,7}, the elements of AA greater than or equal to 1515 are (20,30,20)(20,30,20). The 11-st smallest value of them is 2020; the 22-nd is 2020; the 33-rd is 3030.