Source: RMO-2009-P22
Category: Extremal Problems

Problem: On a $10\\times10$ chessboard there are $k$ rooks. A square that can be attacked by at least one rook is called dangerous (including the square where a rook is located). If after removing any one rook, at least one dangerous square becomes not dangerous, determine the maximum possible value of $k$.

Answer: 16

Reference solution:
First, we prove that $k \le 16$. 
Suppose that every row contains at least one rook. Then all squares on the board are dangerous. If some row contains at least two rooks, removing one of them leaves every row with at least one rook, meaning all squares are still dangerous, which contradicts the problem condition. Hence, each row must contain exactly one rook, yielding $k=10$. By symmetry, if every column contains at least one rook, we also have $k=10$.

Now assume there is at least one row and at least one column without a rook. 
For each rook, it must be the unique rook in its row or the unique rook in its column; otherwise, removing it would leave at least one rook in its row and at least one rook in its column, meaning no dangerous square would become safe. 
We associate each rook with a row or column in which it is the unique rook. 
Let $R$ be the set of rows containing exactly one rook, and $C$ be the set of columns containing exactly one rook. Since every rook is associated with a row in $R$ or a column in $C$, we have $k \le |R| + |C|$. 

Since there is at least one empty row, $|R| \le 9$. If $|R| = 9$, then exactly 9 rows contain exactly one rook, and the remaining row is empty. This implies the total number of rooks on the board is exactly 9, so $k=9$. By symmetry, if $|C| = 9$, then $k=9$. 
Otherwise, we must have $|R| \le 8$ and $|C| \le 8$. It follows that the total number of rooks is bounded by $k \le |R| + |C| \le 8 + 8 = 16$.

Finally, we construct an example with $k=16$. Let the squares occupied by the 16 rooks be $(1,i)$ and $(i,1)$ for $i=2,3,\dots,9$. 
In this configuration, after removing the rook from square $(1,i)$, the square $(10,i)$ changes from dangerous to safe (since row 10 is empty and the only rook in column $i$ was at $(1,i)$). 
Similarly, after removing the rook from square $(i,1)$, the square $(i,10)$ changes from dangerous to safe. 
This configuration satisfies the problem's requirement. Therefore, the maximum possible value of $k$ is $16$.

Grading guidelines:
(Partial) 1. Observed the key necessity: for every rook, it must be the unique rook in its row or the unique rook in its column (otherwise removing it leaves its whole row and column still dangerous, so nothing changes). 2. Derived an upper bound of the form k ≤ |R|+|C| where R is the set of rows with exactly one rook and C is the set of columns with exactly one rook, by assigning each rook to one such unique row/column. 3. Gave a concrete configuration with 16 rooks (e.g. on (1,i) and (i,1) for i=2,…,9) and correctly argued that removing any rook makes at least one previously dangerous square safe. (Almost) 1. Proved the upper bound k ≤ 16 via the |R|+|C| argument, but did not handle the special subcase “all rows occupied” or “all columns occupied” correctly (or omitted it), leaving a small logical gap. 2. Found the correct extremal configuration with k=16 and checked the condition for most rooks, but missed/incorrectly justified one boundary square becoming safe after deletion (e.g. the need for an empty row/column in the witness square). 3. Solution is almost complete, but made minor mistakes which are not negligible.

Construction task:
Provide an explicit construction for the maximum possible value of $k$.

Construction requirements:
- Output a single Python expression (e.g., a list comprehension) that evaluates to a 10x10 matrix (a list of 10 lists, each containing 10 integers).
- The matrix should contain only 0s and 1s, where 1 represents a rook and 0 represents an empty square.
- The configuration must satisfy the problem constraint: for every rook, there must be at least one square (which could be its own square) that is attacked ONLY by this rook.
- The number of rooks $k$ (i.e., the number of 1s in the matrix) must be exactly the maximum possible value.
- Put ONLY the Python expression inside the construction block, without any additional text, markdown, or code fences.

Reference construction:
[[1 if (r == 1 and c >= 2) or (c == 1 and r >= 2) else 0 for c in range(10)] for r in range(10)]

Verifier code:
import sys

def verify():
    payload = sys.stdin.read().strip()
    if not payload:
        print("Empty input.")
        return
    
    try:
        # Evaluate the payload as a Python expression (e.g., list comprehension)
        matrix = eval(payload)
    except Exception as e:
        print(f"Failed to evaluate python expression: {e}")
        return

    if type(matrix) is not list:
        print("Matrix must be a list.")
        return
    
    if len(matrix) != 10:
        print(f"Matrix must have exactly 10 rows, got {len(matrix)}.")
        return
    
    for i, row in enumerate(matrix):
        if type(row) is not list:
            print(f"Row {i} is not a list.")
            return
        if len(row) != 10:
            print(f"Row {i} must have exactly 10 elements, got {len(row)}.")
            return
        for j, val in enumerate(row):
            if type(val) is not int or val not in (0, 1):
                print(f"Element at ({i}, {j}) is not 0 or 1.")
                return

    rooks = []
    for r in range(10):
        for c in range(10):
            if matrix[r][c] == 1:
                rooks.append((r, c))
    
    if len(rooks) != 16:
        print(f"Expected exactly 16 rooks, got {len(rooks)}.")
        return

    # Count the number of rooks in each row and column
    row_counts = [0] * 10
    col_counts = [0] * 10
    for r, c in rooks:
        row_counts[r] += 1
        col_counts[c] += 1
        
    # Calculate how many rooks attack each square (r, c)
    attack_counts = [[0]*10 for _ in range(10)]
    for r in range(10):
        for c in range(10):
            # A rook at (r, c) would be counted twice (once in row_counts, once in col_counts)
            attack_counts[r][c] = row_counts[r] + col_counts[c] - matrix[r][c]

    # Verify that every rook has at least one uniquely attacked square
    for rr, cc in rooks:
        has_unique = False
        
        # Check all squares in the same column
        for r in range(10):
            if attack_counts[r][cc] == 1:
                has_unique = True
                break
                
        if has_unique:
            continue
            
        # Check all squares in the same row
        for c in range(10):
            if attack_counts[rr][c] == 1:
                has_unique = True
                break
                
        if not has_unique:
            print(f"Rook at ({rr}, {cc}) does not have any uniquely attacked square.")
            return

    print("True")

if __name__ == "__main__":
    verify()