A group of wizards must join forces to fight the forces of evil. The wizard resides on the real line at coordinate and has units of experience accumulated from their previous "mathemagical" encounters. The coordinates of the wizards are pairwise distinct.
To join forces, wizards must share their experience with each other: the wizard will choose another wizard as their mentor. If the wizard chooses the mentor, the wizard will gain units of experience in the process. Note that wizards cannot choose to mentor themselves. Compute for each wizard the maximum experience they can gain by choosing the best mentor for themselves. Note that a wizard can be a mentor for multiple other wizards.
Input
The first line contains the number of wizards .
Each of the following lines contains a pair of two integers. The of these lines contains the coordinate and the experience of the wizard: and .
Output
The output contains lines, one line for each wizard. The line represents the maximum possible experience hain for the wizard. The experience gain is represented by two integers and such that is the answer written as an irreductible fraction.
Constraints
Subtasks
# | Points | Restrictions |
---|---|---|
1 | 8 | |
2 | 13 | |
3 | 19 | |
4 | 35 | |
5 | 25 | No further constraints |
Example
stdin
4
1 2
2 1
4 3
6 2
stdout
1 1
2 1
1 1
3 2
Explanation
The first wizard is mentored by the third wizard. The experience gained is .
The second wizard is mentored by the first wizard. The experience gained is .
The third wizard is mentored by the fourth wizard. The experience gained is
The fourth wizard is mentored by the third wizard. The experience gained is .