#arc155b. [arc155_b]Abs Abs Function
[arc155_b]Abs Abs Function
Problem Statement
For a set of pairs of non-negative integers, and a non-negative integer , let defined as $\\displaystyle f_S(x)=\\min_{(a, b) \\in S} \\left| \\left| x-a \\right| - b \\right|$.
We have a set of pairs of non-negative integers. Initially, .
Process queries. The -th query gives you three non-negative integers , , and , and asks you to do the following.
- If , add to the pair of non-negative integers.
- If , print the minimum value of for a non-negative integer such that .
Constraints
- is or .
- If , then .
- There is at least one query with .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
For each query with in the given order, print the answer in its own line.
Sample Input 1
4 0 5
1 3 11
2 7 8
1 8 2
2 8 9
Sample Output 1
2
1
In the second query, . For , we have $f_T(7)=\\min \\lbrace \\left| \\left|7-0\\right|-5\\right|, \\left| \\left|7-3\\right|-11\\right| \\rbrace=\\min \\lbrace 2, 7 \\rbrace=2$. Similarly, . Thus, the answer is .
In the fourth query, . In , takes the minimum value at .
Sample Input 2
2 1 2
1 2 3
2 2 6
Sample Output 2
0
Sample Input 3
20 795629912 123625148
2 860243184 892786970
2 645778367 668513124
1 531411849 174630323
1 635062977 195695960
2 382061637 411843651
1 585964296 589553566
1 310118888 68936560
1 525351160 858166280
2 395304415 429823333
2 583145399 703645715
2 97768492 218377432
1 707220749 459967102
1 210842017 363390878
2 489541834 553583525
2 731279777 811513313
1 549864943 493384741
1 815378318 826084592
2 369622093 374205455
1 78240781 821999998
2 241667193 243982581
Sample Output 3
26468090
3491640
25280111
9543684
0
22804896
20649370
19245624
4849993
484865