407070: GYM102697 041 World Cup (Harder Version)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

041. World Cup (Harder Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

While watching the world cup, you wonder how many points each team has in the group stage. Recall that during the group stage teams are awarded three points for a win, one point for a tie, and zero points for a loss. For this problem, you're given a history of the games between all of the teams, and you must figure out how many group stage points each team has.

Input

The first line of input contains a single integer $$$n$$$: the number of games played. The next $$$n$$$ lines of input consist of two space-separated integers representing the two teams that played. After the integers on each line, one character will follow (after a space) indicating the result of the game. If the character is "W", the first team beat the second team. If the character is "T", the teams tied. (the character will never be "L", i.e. the first team will never lose)

Output

Output $$$m$$$ lines. On each line, print each team's name, and a single integer $$$p$$$: the number of group stage points that the team has. The teams should be sorted in order of their scores; if there is a tie, the tied teams should be sorted alphabetically.

ExampleInput
6
Germany Portugal W
UnitedStates Ghana W
Germany Ghana T
UnitedStates Portugal T
Germany UnitedStates W
Portugal Ghana W
Output
Germany 7
Portugal 4
UnitedStates 4
Ghana 1

加入题单

上一题 下一题 算法标签: