eolymp
bolt
Try our new interface for solving problems
Problems

Mundial

Mundial

Four teams are taking part in football tournament. During this tournament, each team must play one game against every other team. Some of the games have already been played and the results are known. Your task is to determine the possible outcomes of the tournament, assuming that remaining games could have any result (each team can score any non-negative integer number of goals). After each game, the winning team gets three points and the losing team gets zero points. In case of a draw, both teams get one point. The teams are ranked according to the sum of their points. If two teams have the same number of points, they are ranked by the difference between scored goals \textbf{s} and conceded goals \textbf{c} (the more is \textbf{s − c}, the better the rank). If the values of \textbf{s} − c are also the same, teams can be ranked either way due to other tie-breaking factors. In the end, each team gets a distinct rank from \textbf{1} to \textbf{4}. Two outcomes of the tournament are different if there is a team which is ranked differently in these outcomes. \InputFile The first line contains the number \textbf{n }(\textbf{0 }≤ \textbf{n }≤ \textbf{6}) of games already played. Next \textbf{n }lines describe these games. Each game is described by integers \textbf{a}, \textbf{b}, \textbf{c}, \textbf{d} where \textbf{a} and \textbf{b} are the numbers of teams, and \textbf{c}, \textbf{d} are the number of goals scored by team \textbf{a} and team \textbf{b} respectively (\textbf{1} ≤ \textbf{a} < \textbf{b} ≤ \textbf{4}; \textbf{0} ≤ \textbf{c}, \textbf{d} ≤ \textbf{10}). It is guaranteed that no two teams played more than one game against each other. \OutputFile On the first line output the number \textbf{m} of different possible tournament outcomes. Each of the next \textbf{m }lines should contain four integers: the numbers of teams which get ranks \textbf{1}, \textbf{2}, \textbf{3} and \textbf{4} respectively. The outcomes should be listed in lexicographical order.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5
1 2 1 0
1 3 2 1
1 4 3 2
2 3 1 0
2 4 5 4
Output example #1
2
1 2 3 4
1 2 4 3

Example description: The first team got nine points, and the second team got six points. The team that wins the last game gets three points and takes the third place. In case of a draw, teams 3 and 4 can be ranked either as 3-rd and 4-th respectively or vice versa.

Author M.Rubinchik, D.Dublennykh
Source 2013 Petrozavodsk, Winter, Ural FU contest, Kontur Cup, Problem G