#K76027. Debris Collision Simulation

    ID: 34551 Type: Default 1000ms 256MiB

Debris Collision Simulation

Debris Collision Simulation

In deep space, pieces of debris are moving with different masses and velocities. When two pieces collide, they merge into one piece. The new mass is the sum of the two masses, and the new velocity is calculated as (v = \left\lfloor \frac{m_1 v_1 + m_2 v_2}{m_1+m_2} \right\rfloor) (using floor division). The collisions occur sequentially by always combining the first two pieces in the list until only one remains. Your task is to simulate the collision process and output the final state of the debris.

inputFormat

The input is read from standard input. The first line contains an integer (n), the number of debris pieces. Each of the following (n) lines contains two space-separated integers (m) and (v) representing the mass and velocity of a piece of debris.

outputFormat

Output to standard output. The first line should contain the final number of debris pieces (which will always be 1). The second line should contain two integers separated by a space: the mass and velocity of the final debris after all collisions have been processed.## sample

1
50 10
1

50 10

</p>