#abc253c. [abc253_c]Max - Min Query

[abc253_c]Max - Min Query

Problem Statement

We have a multiset of integers SS, which is initially empty.

Given QQ queries, process them in order. Each query is of one of the following types.

  • 1 x: Insert an xx into SS.

  • 2 x c: Remove an xx from SS mm times, where m=mathrmmin(c,(m = \\mathrm{min}(c,( the number of xx's contained in S))S)).

  • 3 : Print (( maximum value of S)(S)-( minimum value of S)S). It is guaranteed that SS is not empty when this query is given.

Constraints

  • 1leqQleq2times1051 \\leq Q \\leq 2\\times 10^5
  • 0leqxleq1090 \\leq x \\leq 10^9
  • 1leqcleqQ1 \\leq c \\leq Q
  • When a query of type 3 is given, SS is not empty.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ mathrmquery1\\mathrm{query}_1 vdots\\vdots mathrmqueryQ\\mathrm{query}_Q

mathrmqueryi\\mathrm{query}_i, which denotes the ii-th query, is in one of the following formats:

11 xx 22 xx cc 33

Output

Print the answers for the queries of type 3 in the given order, separated by newlines.


Sample Input 1

8
1 3
1 2
3
1 2
1 7
3
2 2 3
3

Sample Output 1

1
5
4

The multiset SS transitions as follows.

  • 11-st query: insert 33 into SS. SS is now lbrace3rbrace\\lbrace 3 \\rbrace.
  • 22-nd query: insert 22 into SS. SS is now lbrace2,3rbrace\\lbrace 2, 3 \\rbrace.
  • 33-rd query: the maximum value of S=lbrace2,3rbraceS = \\lbrace 2, 3\\rbrace is 33 and its minimum value is 22, so print 32=13-2=1.
  • 44-th query: insert 22 into SS. SS is now lbrace2,2,3rbrace\\lbrace 2,2,3 \\rbrace.
  • 55-th query: insert 77 into SS. SS is now lbrace2,2,3,7rbrace\\lbrace 2, 2,3, 7\\rbrace.
  • 66-th query: the maximum value of S=lbrace2,2,3,7rbraceS = \\lbrace 2,2,3, 7\\rbrace is 77 and its minimum value is 22, so print 72=57-2=5.
  • 77-th query: since there are two 22's in SS and mathrmmin(2,3)=2\\mathrm{min(2,3)} = 2, remove 22 from SS twice. SS is now lbrace3,7rbrace\\lbrace 3, 7\\rbrace.
  • 88-th query: the maximum value of S=lbrace3,7rbraceS = \\lbrace 3, 7\\rbrace is 77 and its minimum value is 33, so print 73=47-3=4.

Sample Input 2

4
1 10000
1 1000
2 100 3
1 10

Sample Output 2

If the given queries do not contain that of type 33, nothing should be printed.