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

#CC0000034. Tập số có truy vấn thứ hạng (ORDERSET - Order statistic set)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tập số có truy vấn thứ hạng (ORDERSET - Order statistic set)

ORDERSET - Order statistic set

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Maintain a dynamic set SS of distinct integers, initially empty. I x inserts xx if absent, D x removes xx if present, C x counts elements strictly smaller than xx, and K kreturns the $k$-th smallest element. If there is no such element, printinvalid` exactly.

Input

The first line contains QQ. Each of the next QQ lines contains I, D, C, or K followed by its integer argument.

Output

For each C or K operation, print its answer. Print invalid for an invalid K request.

Subtasks

  • Subtask 1 (20 points): 1≤Q≤201\le Q\le 20; for I, D, C: −109≤x≤109-10^9\le x\le10^9; for K: 1≤k≤1091\le k\le10^9.
  • Subtask 2 (30 points): 1≤Q≤8501\le Q\le 850; for I, D, C: −109≤x≤109-10^9\le x\le10^9; for K: 1≤k≤1091\le k\le10^9.
  • Subtask 3 (50 points): 1≤Q≤2000001\le Q\le 200000; for I, D, C: −109≤x≤109-10^9\le x\le10^9; for K: 1≤k≤1091\le k\le10^9.

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

Inserting -1 twice keeps one copy. After removing -1, only 2 remains, so K 2 is invalid.