Source: CSMO-2004-P7
Category: Graph Theory

Problem: "$n$ teams play a double round-robin tournament (i.e., every two teams play two matches, with each team having one home match). It is known that each team can play multiple away matches in one week (from Sunday to Saturday, seven days), but if a team has a home match in a certain week, then no away matches can be scheduled for that team in that week. If all matches can be completed within $4$ weeks, find the maximum value of $n$.
"

Answer: 6

Reference solution:
For $1\le i\le n$, let $A_i$ be the set of weeks in which the $i$-th team plays home games. According to the problem's conditions, the different sets $A_i$ must be mutually non-contained. This is because if $A_i\subseteq A_j$, then a home game of team $i$ against team $j$ could not occur: the week of this match would have to be in $A_i$, and hence in $A_j$, meaning team $j$ would have a home game that week. This violates the condition that a team cannot play an away game in a week it has a home game.

Since $A_1, A_2, \dots, A_n$ are all subsets of the $4$ available weeks, meaning $A_i \subseteq \{1,2,3,4\}$, Sperner's theorem gives the upper bound:
$$ n \le \binom{4}{2} = 6 $$

When $n=6$, the schedule can be arranged as shown in the following table, where rows represent teams, columns represent weeks, and "$*$" indicates that the team has a home game in that week. 

$$
\def\arraystretch{1.5}
\begin{array}{|c|c|c|c|c|}
\hline
\text{Team \textbackslash\ Week} & 1 & 2 & 3 & 4 \\
\hline
1 & * & * & & \\
2 & * & & * & \\
3 & * & & & * \\
4 & & * & * & \\
5 & & * & & * \\
6 & & & * & * \\
\hline
\end{array}
$$

For any two distinct teams $i$ and $j$, team $i$ can schedule its home game against team $j$ in the unique week that is in $A_i$ but not in $A_j$. Since each team has exactly two home weeks and their sets are distinct, there is exactly one such week for each ordered pair, allowing all matches to be successfully scheduled without violating the weekly restrictions. 

Thus, the maximum value of $n$ is $6$.

Grading guidelines:
(Partial) 1. Introduced the sets $A_i\subseteq\{1,2,3,4\}$ of weeks in which team $i$ plays at home, and correctly derived that for any $i\ne j$ one must have $A_i\nsubseteq A_j$ (otherwise the match $i$ at home vs $j$ cannot be scheduled). 2. Obtained a nontrivial upper bound for $n$ from the non-containment property of the $A_i$ (e.g. by noting the family is an antichain and invoking/quoting Sperner for $4$ weeks, or by an equivalent counting argument). 3. Gave a concrete schedule pattern for some $n\ge 5$ consistent with the rule “home week implies no away matches that week”, even if not fully justified for all ordered pairs. (Almost) 1. Correctly proved the upper bound $n\le 6$ via Sperner’s theorem (or an equivalent antichain argument), but did not provide a working construction for $n=6$. 2. Gave the $n=6$ construction (e.g. six distinct 2-element home-week sets) and explained how to place each home match $i$ vs $j$ in a week in $A_i\setminus A_j$, but left a minor gap in justifying existence/uniqueness of such a week for every ordered pair. 3. Presented a full-looking schedule/table for $n=6$ but failed to check a small number of pairwise constraints (e.g. one ordered pair not assigned, or one week-choice accidentally conflicts with the home/away restriction), while the main Sperner/antichain idea is correct.

Construction task:
For the maximum possible number of teams $n$, provide an explicit construction of the schedule matrix.

Construction requirements:
- Output a single Python list of lists representing a $n \times 4$ matrix.
- The rows represent the n teams, and the columns represent the 4 weeks.
- Matrix entry `M[i][j]` should be:
  - `1` if team `i` plays home matches in week `j`.
  - `0` if team `i` does not play home matches in week `j` (meaning it is available to play away).
- The matrix must satisfy the condition that for every pair of distinct teams $(A, B)$, there is at least one week where $A$ is home (`1`) and $B$ is not (`0`), and at least one week where $B$ is home (`1`) and $A$ is not (`0`).
- Put ONLY the Python literal matrix inside the construction block.

Reference construction:
[[1, 1, 0, 0],
 [1, 0, 1, 0],
 [1, 0, 0, 1],
 [0, 1, 1, 0],
 [0, 1, 0, 1],
 [0, 0, 1, 1]]

Verifier code:
import sys
import ast

def verify():
    # Read the full input from stdin
    input_str = sys.stdin.read().strip()
    
    if not input_str:
        print("Error: Input is empty.")
        return

    # 1. Parse the input string as a Python list of lists.
    # We use ast.literal_eval for strict parsing of Python literals.
    try:
        matrix = ast.literal_eval(input_str)
    except Exception as e:
        print(f"Error: Failed to parse input as a Python literal. {e}")
        return

    # 2. Verify that the outer list has length n (teams) and inner lists length 4 (weeks).
    if not isinstance(matrix, list):
        print("Error: Input must be a list.")
        return
    
    n_teams = 6
    n_weeks = 4
    
    if len(matrix) != n_teams:
        print(f"Error: Matrix must have {n_teams} rows (teams), found {len(matrix)}.")
        return
    
    for r_idx, row in enumerate(matrix):
        if not isinstance(row, list):
            print(f"Error: Row {r_idx} must be a list.")
            return
        if len(row) != n_weeks:
            print(f"Error: Row {r_idx} must have {n_weeks} columns (weeks), found {len(row)}.")
            return
        
        # 3. Verify that all entries in the matrix are integers 0 or 1.
        for c_idx, val in enumerate(row):
            if val not in (0, 1):
                print(f"Error: Matrix entry at row {r_idx}, column {c_idx} must be 0 or 1. Found {val}.")
                return

    # 4. Iterate through all unique pairs of row indices (i, j) where i != j.
    # We iterate i from 0 to n-1 and j from i+1 to n-1.
    for i in range(n_teams):
        for j in range(i + 1, n_teams):
            
            # 5. Verify that there exists at least one column c1 such that row[i][c1] == 1 and row[j][c1] == 0
            # This ensures Team i can host Team j.
            i_hosts_j = False
            for w in range(n_weeks):
                if matrix[i][w] == 1 and matrix[j][w] == 0:
                    i_hosts_j = True
                    break
            
            if not i_hosts_j:
                print(f"Error: Condition failed for pair ({i}, {j}). Team {i} never hosts Team {j} "
                      f"(requires a week where Team {i} is home/1 and Team {j} is away/0).")
                return

            # 6. Verify that there exists at least one column c2 such that row[j][c2] == 1 and row[i][c2] == 0
            # This ensures Team j can host Team i.
            j_hosts_i = False
            for w in range(n_weeks):
                if matrix[j][w] == 1 and matrix[i][w] == 0:
                    j_hosts_i = True
                    break
            
            if not j_hosts_i:
                print(f"Error: Condition failed for pair ({i}, {j}). Team {j} never hosts Team {i} "
                      f"(requires a week where Team {j} is home/1 and Team {i} is away/0).")
                return

    # 7. If all checks pass, return True.
    print("True")

if __name__ == "__main__":
    verify()