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

#CC0000032. Lấy phần tử nhỏ thứ k rồi xóa (Data Structure)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Lấy phần tử nhỏ thứ k rồi xóa (Data Structure)

Data Structure

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Maintain a set SS of positive integers, initially empty. Operation 1 x inserts xx; operation 2 k outputs the kk-th smallest element currently in SS and removes it. Every inserted value is guaranteed to be absent beforehand. Every extraction is guaranteed to have at least kk elements available.

Input

The first line contains QQ. Each of the following QQ lines contains t,xt,x. For type 2, the argument xx is the requested rank kk.

Output

For each type 2 operation, print the extracted value.

Subtasks

  • Subtask 1 (20 points): 1≤Q≤201\le Q\le 20; t∈{1,2}t\in\{1,2\}; 1≤x≤2000001\le x\le200000; insertion values are absent, and extraction ranks do not exceed the current set size.
  • Subtask 2 (30 points): 1≤Q≤9001\le Q\le 900; t∈{1,2}t\in\{1,2\}; 1≤x≤2000001\le x\le200000; insertion values are absent, and extraction ranks do not exceed the current set size.
  • Subtask 3 (50 points): 1≤Q≤2000001\le Q\le 200000; t∈{1,2}t\in\{1,2\}; 1≤x≤2000001\le x\le200000; insertion values are absent, and extraction ranks do not exceed the current set size.

Examples

Input

5
1 11
1 29
1 89
2 2
2 2

Output

29
89

Explanation

The set is {11,29,89}; extracting the second smallest removes 29 and then 89.