Time limit
1s
Memory limit
128 MB
Medal tables are usually sorted strictly by the number of gold medals, then silver medals, then bronze medals. Under that rule, a team with many silver and bronze medals can still rank far behind a team with only a few gold medals.
Instead, suppose each medal type is assigned an integer value and a team's score is the weighted sum of its medals. The value of a gold medal must be greater than the value of a silver medal, the value of a silver medal must be greater than the value of a bronze medal, and all three values must be between 1 and 99 inclusive.
For several medal tables, determine for each team which gold, silver, and bronze values give that team its best possible placing. A team's placing is the number of rival teams with a larger score, plus 1.
The input consists of several games. Each game starts with one line containing the host city name. It is followed by one line per team: the team name and three integers giving the numbers of gold, silver, and bronze medals won by that team. A line containing only # ends the team list for that game.
A line containing only # ends the entire input. Each game has at most 100 teams, and no team wins more than 1000 medals.
For each game, print a header line followed by one line for each team in the same order as the input. The header is Olympic Games in followed by the city name.
Each team line contains the team name followed by four integers separated by single spaces: the gold, silver, and bronze values that give the team its best possible placing, and that placing. The values must be between 1 and 99 inclusive and must satisfy gold > silver > bronze.
If several value assignments give the same best placing, choose the assignment with the smallest six-digit number ggssbb, where gg, ss, and bb are the two-digit gold, silver, and bronze values, including leading zeroes when needed. Print one blank line between games.