Artificial Lake#10154

Artificial Lake

1 second
128 megabytes
Hard

The oppressively hot summer days have driven the cows' clamoring to an all-time high. Farmer John has finally decided to build an artificial lake. For his engineering studies, he is modeling the lake as a two-dimensional landscape consisting of a contiguous sequence of soon-to-be-submerged levels, conveniently numbered from left to right.

Each level is described by two integers: its width w_i~(1 \le w_i \le 1000) and its height (representing its relative elevation) h_i~(1 \le h_i \le 10^6). The heights of FJ's levels are all distinct. An infinitely tall barrier encloses the lake model on both the left and right. One example of a lake profile is shown below.

         *             *  :
         *             *  :
         *             *  8
         *    ***      *  7
         *    ***      *  6
         *    ***      *  5
         *    **********  4 <- height
         *    **********  3
         ***************  2
         ***************  1
Level    |  1 |2|  3   |

In FJ's model, he begins filling the lake at sunrise by flowing water into the lowest elevation at a rate of one square unit per minute. The water falls vertically until it hits a surface, after which it flows and spreads as water naturally would. As in all good models, assume that both falling and flowing occur instantaneously.

Determine the time at which each level becomes submerged by a layer of water of height .

WATER              WATER OVERFLOWS                     
       |                       |                           
     * |          *      *     |      *      *            *
     * V          *      *     V      *      *            *
     *            *      *    ....    *      *~~~~~~~~~~~~*
     *    **      *      *~~~~** :    *      *~~~~**~~~~~~*
     *    **      *      *~~~~** :    *      *~~~~**~~~~~~*
     *    **      *      *~~~~**~~~~~~*      *~~~~**~~~~~~*
     *    *********      *~~~~*********      *~~~~*********
     *~~~~*********      *~~~~*********      *~~~~*********
     **************      **************      **************
     **************      **************      **************

     After 4 mins        After 26 mins       After 50 mins
     Lvl 1 submerged     Lvl 3 submerged     Lvl 2 submerged

Warning: The answer will not always fit in a -bit integer.

Input

The first line contains one integer n~(1 \le n \le 10^5). Each of the next lines describes level with two integers w_i and h_i.

Output

Print lines. Line i~(1 \le i \le n) contains one integer representing the number of minutes after sunrise at which level becomes covered by water of height .

Examples

Example 1

Loading
Loading