This page is still under construction.

Parts of this page are still being built. What you see may change.

Racetrack

Time limit2sMemory limit512 MB

Summary
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.
Level

Hard8 of 10

Topics
Simulation, Implementation, Sorting, Math
Solved
No attempts yet

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 (1≤n≤50001 \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 (1≤ti≤1061 \le t_i \le 10^6, 1≤ci≤10001 \le c_i \le 1000).

The players are given in order of decreasing speed, that is t1≤t2≤⋯≤tnt_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.

Examples2

  1. Example 1

    Input
    2
    4 8
    7 6
    
    Expected output
    36
    42
    
  2. Example 2

    Input
    3
    1 4
    3 3
    4 3
    
    Expected output
    8
    9
    12