Source: CMO-2018-P5
Category: Operations and Strategies

Problem: Given a positive integer $n$, fill each cell of an $n \\times n$ grid with an integer. The following operation is performed on the grid: select a cell, and add $1$ to each of the $2n-1$ numbers in the row and column containing that cell. Find the largest positive integer $N$ such that, regardless of the initial numbers in the grid, it is always possible to perform a finite sequence of the above operations so that at least $N$ numbers in the grid are even.

Answer: When $n$ is even, it is $n^2$, and when $n$ is odd, it is $n^2-n+1$

Reference solution:
Let $(i,j)$ denote the cell in row $i$ and column $j$.

**Case 1: $n$ is even.**
To flip the parity of a specific cell $(i,j)$ without changing the parity of any other cell, we perform one operation on each of the $2n-1$ cells $(p,q)$ that lie in row $i$ or column $j$ (i.e., $p=i$ or $q=j$).
These operations affect the cell $(i,j)$ exactly $2n-1$ times, each of the other cells in row $i$ and column $j$ exactly $n$ times, and each cell neither in row $i$ nor in column $j$ exactly $2$ times.
Since $n$ is even, $2n-1$ is odd, while $n$ and $2$ are even. Thus, the result of these operations is to flip the parity of the number in cell $(i,j)$ while leaving the parity of the numbers in all other cells unchanged.
Hence, by a sequence of such operations, we can independently adjust the parity of every cell, making all numbers in the grid even.
Clearly $N \le n^2$, so in this case the maximum value of $N$ is $n^2$.

**Case 2: $n$ is odd.**
When $n$ is odd, $n-1$ is even. By restricting our chosen operation cells to the upper-left $(n-1) \times (n-1)$ subgrid, the previous analysis shows that we can flip the parity of any target cell in this subgrid without altering the parity of any other cell within the subgrid. Thus, by a sequence of operations, we can make the numbers in the upper-left $(n-1)^2$ cells all even.

If at this point the number of even entries in row $n$ and column $n$ is less than $n$, then performing one operation on cell $(n,n)$ can increase the number of evens in row $n$ and column $n$ to at least $n$. (Note that row $n$ and column $n$ contain exactly $2n-1$ cells in total. If fewer than $n$ are even, then at least $n$ are odd. The operation on $(n,n)$ flips the parities of all these $2n-1$ cells without affecting the upper-left $(n-1) \times (n-1)$ subgrid.)
Thus, by a sequence of operations we can ensure that the grid contains at least $(n-1)^2+n = n^2-n+1$ even numbers.

On the other hand, consider an initial grid where the cells $(1,1),(1,2),\dots,(1,n-1)$ contain $1$ and all other cells contain $0$.
In this grid, the row sums of the first $n-1$ rows are even (the first row sum is $n-1$, which is even since $n$ is odd, and the others are $0$), and the column sums of the first $n-1$ columns are odd (each is $1$).

Note that a single operation flips the parity of every row sum and column sum. Indeed, an operation on cell $(i,j)$ adds $1$ to the $2n-1$ cells in row $i$ and column $j$; the sum of any row $x$ increases by $n$ if $x=i$ and by $1$ if $x \neq i$. Since $n$ is odd, the sum of every row increases by an odd amount, flipping its parity. By symmetry, the parity of every column sum also flips.

Therefore, after an odd number of operations, the row sums of the first $n-1$ rows become odd; after an even number of operations, the column sums of the first $n-1$ columns become odd.
In either case, either the first $n-1$ rows all have an odd sum, or the first $n-1$ columns all have an odd sum. An odd sum requires at least one odd number in that row or column. Since the rows (or columns) are disjoint, the grid always contains at least $n-1$ odd numbers, implying $N \le n^2 - (n-1) = n^2-n+1$.
Thus, in this case the maximum value of $N$ is $n^2-n+1$.

Grading guidelines:
(Partial) 1. For even n, gave an explicit operation pattern that flips the parity of exactly one chosen cell while leaving all other cells’ parities unchanged (e.g., operating on all cells in its row and column), and correctly concluded that all n^2 cells can be made even. 2. For odd n, correctly reduced to controlling parities inside an (n−1)×(n−1) subgrid (using that n−1 is even) and showed one can make all entries in that subgrid even. 3. For odd n, established a valid invariant/obstruction using parities of row sums and column sums (e.g., each move flips the parity of every row sum and every column sum), and derived that at least n−1 entries must remain odd for a specific initial configuration. (Almost) 1. Correctly obtained the bound N=n^2 for even n and N=n^2−n+1 for odd n, but left a small gap in the parity-count of the “single-cell flip” construction (e.g., not fully justifying why all other cells are affected an even number of times). 2. For odd n, completed the construction achieving (n−1)^2+n even entries, but did not fully justify the step that an operation at (n,n) increases the number of evens in row n ∪ column n to at least n (i.e., the counting argument among 2n−1 parities). 3. For odd n, proved the row/column-sum invariant and set up the extremal initial configuration, but made a localized mistake in concluding that this forces at least n−1 odd cells in every reachable state (e.g., missing the disjointness argument or mixing the two cases of move parity).

Construction task:
Consider the specific case where $n = 101$. Construct a $101 \times 101$ grid where each cell contains either 0 or 1.
Let $M$ be the maximum number of even numbers that can be achieved in the grid after applying any finite sequence of the described operations. Your objective is to design the initial grid such that $M$ is minimized.

Construction format requirements:
- Output a single Python expression (e.g., a list comprehension) that evaluates to a list of lists of integers (0s and 1s) representing the $101 \times 101$ matrix.
- The expression must be self-contained and evaluate directly to the matrix when passed to Python's `eval()`.
- Do not include any explanations, comments, markdown code blocks, print statements, assignments, function definitions, imports, classes, asserts, or statement-level `for` loops.
- Use list comprehensions, conditional expressions, and integer constants to generate the grid compactly.
- Put ONLY the raw Python expression inside the construction block.

Reference construction:
[[1 if i == 0 and j < 100 else 0 for j in range(101)] for i in range(101)]

Verifier code:
import sys

def verify():
    payload = sys.stdin.read().strip()
    if not payload:
        print("Validation error: Empty input.")
        return
    
    try:
        # Use eval to evaluate the Python expression (e.g., list comprehensions)
        A = eval(payload)
    except Exception as e:
        print(f"Parse error: Failed to evaluate payload: {e}")
        return

    if type(A) is not list:
        print(f"Validation error: Matrix A must be a list, got {type(A).__name__}.")
        return
    
    if len(A) != 101:
        print(f"Validation error: Matrix A must have exactly 101 rows, got {len(A)}.")
        return
    
    for i, row in enumerate(A):
        if type(row) is not list:
            print(f"Validation error: Row {i} is not a list, got {type(row).__name__}.")
            return
        if len(row) != 101:
            print(f"Validation error: Row {i} must have exactly 101 elements, got {len(row)}.")
            return
        for j, val in enumerate(row):
            # Strictly check for integer 0 or 1 (rejecting booleans like False/True)
            if type(val) is not int or val not in (0, 1):
                print(f"Validation error: Element at ({i}, {j}) must be the integer 0 or 1, got {repr(val)}.")
                return

    # Compute row sums mod 2 and column sums mod 2
    row_sums = [sum(row) % 2 for row in A]
    col_sums = [sum(A[i][j] for i in range(101)) % 2 for j in range(101)]

    # Count the number of odd row sums (R0) and odd column sums (C0)
    R0 = sum(row_sums)
    C0 = sum(col_sums)

    # Compute the number of even row sums (R1) and even column sums (C1)
    R1 = 101 - R0
    C1 = 101 - C0

    # Calculate the minimum number of odd cells present in any reachable configuration
    min_odd_cells = min(max(R0, C0), max(R1, C1))
    
    # Subtract this from total cells to determine maximum guaranteed even numbers M
    M = 101**2 - min_odd_cells

    # Assert that M is exactly 10101
    if M != 10101:
        print(f"Validation error: Expected maximum guaranteed even numbers M to be 10101, but got {M}.")
        return

    print("True")

if __name__ == "__main__":
    verify()