Robot Energy Source Order

Reorder n energy sources, each with acceleration a_i and duration s_i, to maximize total distance, and print the gain over the given order.

Medium5SortingGreedyMathPrefix sumInterviewNo attempts yetTime limit0.2sMemory limit128 MB

Problem

You design a robot that explores places people cannot reach, and you want it to travel as far as possible. You have nn energy sources. Source ii accelerates the robot at aia_i m/s2\text{m/s}^2 and keeps doing so for sis_i seconds. The robot starts at rest, so its initial velocity is 0.

Once you pick a source you use it for all of its sis_i seconds, then switch straight to a source you have not used yet. The switch takes no time, and each source can be used only once. You choose the order of the sources so that the distance traveled is as large as possible.

Given the acceleration and the duration of every source, write a program that computes the distance traveled under the best order minus the distance traveled under the order given in the input.

Physics background: if the velocity is vv right before you start a source whose acceleration is aa, then after tt seconds the robot has traveled vt+12at2vt + \frac{1}{2}at^2 more meters and its velocity is v=v+atv' = v + at.

Input

The first line contains the number of energy sources nn (1n1041 \le n \le 10^4). Each of the next nn lines contains the acceleration aia_i and the duration sis_i of one source, separated by a space. Both values are positive integers no greater than 10410^4.

Output

Print the distance traveled under the best order minus the distance traveled under the input order, with exactly one digit after the decimal point. The difference is always an integer, so that digit is always 0.