Under construction

Still being built. Things may change

Magic Rods

Interview

Time limit2sMemory limit1024 MB

Summary
Choose positive integer ignition times at both ends of each rod so that every rod's last point is lit at distance d_i and all rods finish at the same earliest moment.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Statement

Bella has nn numbered magic rods. To get magic energy, Bella lights each rod at both ends, possibly at different moments. The fire spreads at one centimeter per second. The energy of a rod is released at the moment the fire covers the whole rod.

The length of rod ii is lil_i centimeters. Help Bella choose the ignition times of the ends of each rod so that the energy of all rods is released at the same moment. Bella also wants the last point of rod ii to catch fire at distance did_i from the first end of that rod.

All ignition times must be positive integers. Among all valid answers, choose the one that minimizes the moment when all the energy is released.

Input

The first line contains one integer nn (1≤n≤10,0001 \le n \le 10,000), the number of rods. Each of the next nn lines contains two integers lil_i and did_i (2≤li≤1,000,0002 \le l_i \le 1,000,000, 0<di<li0 < d_i < l_i): the length of rod ii and the distance from its first end to the point that must be lit last.

Output

On the ii-th line, print two positive integers ti1t_{i1} and ti2t_{i2}: the moments to ignite the first and the second end of rod ii.

Examples1

  1. Example 1

    Input
    2
    2 1
    3 1
    
    Expected output
    2 2
    2 1