Under construction

Still being built. Things may change

Ducks and Sharks

Interview

Time limit2sMemory limit2048 MB

Summary
Given every match result in a round-robin tournament, print the five teams with the most points, with ties broken alphabetically.
Level

Easy3 of 10

Topics
Hash map, Sorting, String, Implementation
Solved
No attempts yet

Problem

The Ducks and the Sharks have had many adventures in the past year. Because the weather has been so nice lately, they want to organise a water polo tournament. After forming the teams, every team plays one match against every other team. Being caught up in the fun of playing the matches, they don't feel like figuring out who won, so they turn to you for help.

You receive a list of matches and the number of goals made by both teams in a match. For each match, the winner gets 3 points, the loser gets 0 points, and in case of a draw both teams get 1 point. It is your job to figure out which teams got the most points, and provide a top five of the best teams.

Input

One line with one integer: 2≤n≤4002 \leq n \leq 400, the number of teams.

n⋅(n−1)2\frac{n \cdot (n - 1)}2 lines (one for each match), containing the names of the two teams and the number of goals both teams made during that match (all separated by one space).

The name of each team consists of at most 20 characters from the English alphabet (A-Z and a-z). The scores are between 0 and 100 (inclusive).

Note that every team plays exactly once against every other team.

Output

The names of the top five teams in the water polo competition, followed by their total obtained score. Each team name should be written on a separate line. Each team name and score should be separated by exactly one space.

If there are less than five teams participating, simply list all participants. If there are two teams with the same score, order them alphabetically.

Examples2

  1. Example 1

    Input
    4
    Splashers Sharks 4 2
    Ducks Fins 5 2
    Fins Splashers 3 5
    Ducks Sharks 0 5
    Splashers Ducks 8 1
    Fins Sharks 1 1
    
    Expected output
    Splashers 9
    Sharks 4
    Ducks 3
    Fins 1
    
  2. Example 2

    Input
    5
    A B 5 3
    C D 2 9
    A E 0 0
    C B 1 1
    A C 2 5
    B E 2 5
    D A 1 6
    C E 4 2
    B D 0 2
    E D 5 2
    
    Expected output
    A 7
    C 7
    E 7
    D 6
    B 1