Hide

Problem G
Climbing Fall

Languages en is
/problems/klifurfall/file/statement/en/img-0001.jpg
Picture by Nothere, taken from commons.wikimedia.org

Elvar and Samuel took their lead climbing licenses last year and have gotten hooked on the sport. They have now been going at least two times a weak, but there are just some routes that they can not figure out. So, like many climbers do, they start looking at how other climbers climb the route and start noting down on which hold each one is falling on. They hope that knowing the holds where most climbers fell, will help them slowly learn how to read the route in a better way.

Of course the number one rule in climbing is to never climb and compute. Now they have written down all this data, but have no way of knowing where most climbers are falling. Since they live by this rule, they ask you for help. Can you help them figure out which holds seem to be causing the most amount of climbers to fall.

Input

The first line in the input contains an integer $1 \leq n \leq 100\, 000$, the amount of attempts that were made at the wall. The next $n$ lines each contain the name $r_i$ of the sent route, where $1 \leq |r_i| \leq 10$ and $|r_i|$ denotes the length of the name, followed by an integer $1 \leq h_i \leq 10^9$ representing the hold on which the climber fell.

Output

For each route, write one line that includes the name of the route and the number of the hold on which the most climbers fell, separated by a space. The routes should written in lexicographical order and in case of any holds being tied, the hold that comes earlier in the route should be written.

Scoring

Groups

Points

Constraints

1

20

$1 \leq n \leq 1\, 000$

2

20

$1 \leq n \leq 100\, 000$ and only one route was climbed.

3

60

No further constraints.

Sample Input 1 Sample Output 1
5
snakurinn 3
snakurinn 2
snakurinn 3
katla 5
katla 1
katla 1
snakurinn 3
Sample Input 2 Sample Output 2
4
hellirinn 10
hellirinn 21
hellirinn 67
hellirinn 67
hellirinn 67

Please log in to submit a solution to this problem

Log in