#SGM0000024. Tập hợp thứ tự (Order statistic set)
Tập hợp thứ tự (Order statistic set)
Order statistic set
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a dynamic set of integers, initially empty. There are operations:
I x: insert if .D x: delete if .K k: print the -th smallest element of .C x: print the number of elements of smaller than .
If K k has , print invalid.
Input
The first line contains .
Each of the next lines contains one operation. For a value parameter , . For a rank parameter , .
Output
Print the answer to every K or C query on its own line.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: .
Examples
Input
8
I -1
I -1
I 2
C 0
K 2
D -1
K 1
K 2
Output
1
2
2
invalid
Explanation
The sample is processed in order; every printed item/line corresponds to an operation that requires output.