using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Linq;
class
GFG1 {
public
static
int
lowerbound(List<
int
> arr,
int
target)
{
int
N = arr.Count;
int
low=0;
for
(
int
i=0;i<N-1;i++)
{
if
(arr[i]<target && arr[i+1]>=target)
{
low = i+1;
break
;
}
}
if
(arr[0]>target)
return
0;
return
low;
}
public
static
int
upperbound(List<
int
> arr,
int
target)
{
int
N = arr.Count;
int
high=N;
for
(
int
i=N-1;i>=0;i--)
{
if
(arr[i]>=target && arr[i-1]<target)
{
high = i;
break
;
}
}
if
(high == N)
return
N;
return
high;
}
class
GFG : IComparer<
int
>
{
public
int
Compare(
int
x,
int
y)
{
if
(x == 0 || y == 0)
{
return
0;
}
return
x.CompareTo(y);
}
}
public
static
void
solveQueries(
int
Q, List<KeyValuePair<
int
, KeyValuePair<
int
,
int
>>> A)
{
int
ans;
List<
int
> s =
new
List<
int
>();
for
(
int
i = 0; i < Q; i++) {
int
t, a, b;
t = A[i].Key;
a = A[i].Value.Key;
b = A[i].Value.Value;
if
(t == 1) {
s.Add(a);
s.Add(b);
continue
;
}
GFG gg =
new
GFG();
s.Sort(gg);
if
(t == 2) {
ans = 0;
int
it = upperbound(s, a);
for
(
int
j = 0; j < b; j++) {
if
(it == 0) {
ans = -1;
break
;
}
it--;
ans = s[it];
}
}
else
{
ans = 0;
int
it = lowerbound(s, a);
for
(
int
j = 0; j < b; j++) {
if
(it == s.Count) {
ans = -1;
break
;
}
ans = s[it];
it++;
}
}
Console.Write(ans +
" "
);
}
}
static
void
Main() {
int
Q = 7;
var
A =
new
List<KeyValuePair<
int
, KeyValuePair<
int
,
int
>>>();
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(1,
new
KeyValuePair<
int
,
int
>(20, 10)));
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(1,
new
KeyValuePair<
int
,
int
>(30, 20)));
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(3,
new
KeyValuePair<
int
,
int
>(15, 1)));
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(3,
new
KeyValuePair<
int
,
int
>(15, 2)));
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(3,
new
KeyValuePair<
int
,
int
>(15, 3)));
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(3,
new
KeyValuePair<
int
,
int
>(15, 4)));
A.Add(
new
KeyValuePair<
int
, KeyValuePair<
int
,
int
>>(2,
new
KeyValuePair<
int
,
int
>(100, 5)));
solveQueries(Q, A);
}
}