402909: GYM100942 J Liquid

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Liquidtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

In 2316 after successful colonization of XMars people started to colonize another planet – XVenus. First of all, they have sent a space probe to the planet in order to get the place prepared for living modules installation. A small spaceship with special liquid on board leaves the orbital station, heads to the planet and pours the liquid down to the surface, and the places treated like that become liveable. The whole process is organized in the following way: the planet’s surface is divided into many segments. Every segment is given a number starting from zero. The program installed at the Station has n stages of two different types: surface treatment and surface cleaning. If the spaceship treats the surface on i-stage, it carries pi tons of the liquid onboard. One ton of the liquid is enough to treat one segment. The spaceship scans the surface, detects the first untreated segment that has the number greater than xi and from here starts to treat the segments, moving in an increasing order. If the spaceship runs out of the liquid or encounters the segment that has already been treated, it returns to the station, bringing the liquid back to the storage tank. After that, the spaceship loads again the liquid and departs to fulfil the next stage. Surface cleaning as a tool engineered to fix the mistakes in the surface treatment system. If on i-stage the spaceship cleans the surface, it lands on sector xi and if it is flooded by liquid, eliminates it, restoring the surface's initial state. Find out the segments that will be treated at each stage of the first type.

Input

The first line contains positive integer n that doesn't exceed 105. The following n lines describe stages. Two positive integers xi and pi in each, separated by spaces (0 < xi ≤ 5·108, 0 < pi ≤ 1000), describe surface treatment stage. A single negative integer yi ( - 5·108 ≤ yi < 0) describes the cleaning stage, i.e it is necessary to clean the segment xi =  - yi.

Output

In a separate line print two space-separated numbers: the first and the last sector numbers, treated on this stage. Output the results as per order in the input file.

ExamplesInput
6
5 2
6 3
4 7
1 1
-4
2 4
Output
5 6
7 9
4 4
1 1
2 4

加入题单

算法标签: