{"problem":{"name":"041. World Cup (Harder Version)","description":{"content":"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 po","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269041"},"statements":[{"statement_type":"Markdown","content":"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.\n\nThe 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)\n\nOutput $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.\n\n## Input\n\nThe 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)\n\n## Output\n\nOutput $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.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of games.  \nLet $ G = \\{ (T_{i,1}, T_{i,2}, r_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of game results, where:  \n- $ T_{i,1}, T_{i,2} $ are team identifiers (strings),  \n- $ r_i \\in \\{ \\text{W}, \\text{T} \\} $ is the result:  \n  - If $ r_i = \\text{W} $, then $ T_{i,1} $ wins and $ T_{i,2} $ loses.  \n  - If $ r_i = \\text{T} $, then both teams tie.  \n\nLet $ \\mathcal{S} $ be the set of all unique teams appearing in $ G $.  \n\n**Constraints**  \n1. $ n \\geq 1 $  \n2. For each game $ i $, $ r_i \\neq \\text{L} $  \n\n**Objective**  \nFor each team $ s \\in \\mathcal{S} $, compute its total points $ p_s $:  \n$$\np_s = 3 \\cdot w_s + 1 \\cdot t_s\n$$  \nwhere:  \n- $ w_s $ = number of games in which $ s $ is the first team and $ r_i = \\text{W} $,  \n- $ t_s $ = number of games in which $ s $ appears (as either team) and $ r_i = \\text{T} $.  \n\nOutput the teams sorted by $ p_s $ descending; for ties, sort alphabetically by team name.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269041","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}