A lot of queries - MarisaOJ: Marisa Online Judge

A lot of queries

Time limit: 1000 ms
Memory limit: 256 MB
For an empty set $S$, given $q$ queries, where each query is an integer $x$: - `1 x a`: Insert $a$ elements with value $x$ into the set. - `2 x b`: Remove $b$ elements with value $x$ from the set. If the number of elements with value $x$ in the set is less than $b$, remove all elements with value $x$. - `3`: Find the minimum value in the set. - `4`: Find the maximum value in the set. - `5 y`: Let $x$ be the maximum value less than $y$ in the set, and $z$ be the minimum value greater than $y$ in the set. Calculate the sum of elements with values $x$ or $y$ or $z$. If there is no satisfied $x,y$ or $z$, you can ignore them. The set $S$ may contain multiple elements with the same value. ### Input - The first line contains an integer $q$. - The next $q$ lines, each containing a query in the specified format. ### Output - For each query of types $3,4,5$, print an integer as the answer. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le x, a, b, y \le 10^6$. ### Example Input ``` 8 1 1 3 1 2 2 5 1 3 2 1 2 1 3 4 4 5 2 ``` Output: ``` 7 1 3 17 ```