Racetrack

Given ordered lap times and lap counts and the rule that passes happen only at the finish line, compute when each runner finishes the race.

Hard8SimulationImplementationSortingMathNo attempts yetTime limit2sMemory limit512 MB

Problem

On a circular racetrack, nn players run a fixed number of laps. Every player has her own maximum speed. Player ii needs tit_i units of time for one lap at maximum speed and has to complete cic_i laps.

On this track a player can pass another player only at the finish line. When a player catches up with a slower player during a lap, she stays right behind him until the end of that lap, so the two cross the finish line at the same moment.

Every player who crosses the finish line at the same moment starts again from there at her own maximum speed, so faster players move ahead of slower ones.

At the start all players stand together at the finish line. A player who completes her last lap leaves the track at once and blocks nobody after that.

Given the lap time and the number of laps of every player, compute the moment each player completes the race.

Input

The first line contains the number of players nn (1n50001 \le n \le 5000).

Each of the next nn lines describes one player: the ii-th of them contains the lap time tit_i and the number of laps cic_i of player ii (1ti1061 \le t_i \le 10^6, 1ci10001 \le c_i \le 1000).

The players are given in order of decreasing speed, that is t1t2tnt_1 \le t_2 \le \dots \le t_n.

Output

Print nn lines. The ii-th line contains the moment player ii completes the race.