Section: 2, Score: 19, Time limit per test: 30 seconds, Memory limit per test: 512MB, Input: stdin, Output: stdout
Since the big bang, the universe has been expanding at an accelerating rate. There are many objects in the universe, some are small, and some are big. Sometimes these objects collide with each other, and when they collide, they create new objects. The new object's mass is the sum of the mass of objects that collided. The new object is created at the location of the smaller object. The smaller objects are destroyed in the process. The total momentum, i.e., product of mass and velocity, of the system is conserved in the process.
You are given the initial state of the universe, and you are asked to find the final state of the universe after all the possible collisions are over.
In this problem there are
Please note that there could be multiple collisions at the same time but in different parts of the universe and more than two objects could collide at once to form a new object.
The first line contains an integer
The next line contains
The next line contains
The first line contains an integer
The next
5
1 2 3 4 5
1 2 3 4 5
5
1 1
2 4
3 9
4 16
5 25
In the testcase above there are
5
1 2 3 4 5
5 4 3 2 1
1
15 35
In the testcase above there are