Under construction

Still being built. Things may change

An Unbroken Heart 1

Time limit1.5sMemory limit1024 MB

Summary
Given N dragons with start heights H[i] and daily growth D[i], find for each k the maximum total cut length when at most one arrow is shot per day from day 1 to k.
Level

Medium6 of 10

Topics
Greedy, Sorting, Heap
Solved
No attempts yet

Problem

"N = 10000 is fine. What matters is a heart that does not break"

Your farm has NN dragons growing on it. Each dragon has a distinct number from 11 to NN. Call today day 1. On day 1, the height of dragon ii is H[i]H[i]. Every time the day changes, the height of every dragon increases by D[i]D[i].

Outside the farm, a thief is trying to steal your dragons with a sharp magic arrow. The thief can shoot at most one magic arrow per day, and a shot arrow hits exactly the dragon the thief aims for. When the arrow hits dragon ii, its height becomes 0, and the thief gets a piece of the dragon equal to the cut length (that is, the height the dragon had before it was hit). The thief may choose not to shoot, and may hit a dragon that was already hit earlier.

The dragons may be cut by the magic arrows, but their hearts do not break. Even if dragon ii has height 0, its height increases by D[i]D[i] again when the next day comes.

For every 1≤k≤N1 \le k \le N, assume the thief can shoot at most one arrow per day from day 1 to day kk. Find the maximum possible total length of dragon pieces the thief can obtain.

Input

The first line contains the number of dragons NN. (1≤N≤10,0001 \le N \le 10{,}000)

The next NN lines each contain two integers D[i]D[i] and H[i]H[i]. (0≤D[i]≤1060 \le D[i] \le 10^6, 0≤H[i]≤10120 \le H[i] \le 10^{12})

Output

Print NN lines. On line ii, print the answer for k=ik = i as a single integer.

Examples1

  1. Example 1

    Input
    3
    7 15
    3 5
    1 5
    
    Expected output
    15
    27
    42