407070: GYM102697 041 World Cup (Harder Version)
Description
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.
InputThe 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)
OutputOutput $$$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.
ExampleInput6 Germany Portugal W UnitedStates Ghana W Germany Ghana T UnitedStates Portugal T Germany UnitedStates W Portugal Ghana WOutput
Germany 7 Portugal 4 UnitedStates 4 Ghana 1