eolymp
bolt
Try our new interface for solving problems
Problems

К-th maximum

К-th maximum

Write a program that implements a data structure that allows to add and remove items, and also to find the k-th maximum.

Input

The first line contains the number of commands n (n105). Each of the next n lines contains one command. The command is given in the form of two numbers ci and ki - the type and the argument of the command respectively (|ki| ≤ 109). Supported commands are:

  • +1: Add element with key ki;
  • 0: Find and print the ki-th maximum;
  • -1: Delete the element with a key ki.

It is guaranteed that during simulation it is not required to store in structure the items with equal keys, or to remove non-existent elements. It is also guaranteed that at the request of ki-th maximum, it exists.

Output

For each command of zero type print a string with a single number - the ki-th maximum.

Time limit 1 second
Memory limit 128 MiB
Input example #1
8
+1 5
+1 3
+1 7
0 2
-1 3
0 1
+1 10
0 3
Output example #1
5
7
5
Author В.Гольдштейн
Source Зимние сборы в Харькове 2010 День 2