Source: CTST-2018-P20
Category: Extremal Problems

Problem: A class has $32$ students. There are $10$ interest groups in the class, and each interest group has exactly $16$ students from the class. For any two students, the square of the number of interest groups in which exactly one of them participates is called the interest difference of the two students. Let $S$ be the sum of the interest differences over all $\\binom{32}{2}$ pairs of students. Find the smallest possible value of $S$.

Answer: The answer is $14080$.

Reference solution:
First, we restate the problem in terms of sets. Let $A_1, A_2, \dots, A_{10}$ be $16$-element subsets of the set $\{1, 2, \dots, 32\}$.  
For $1 \le i \le 32$, denote  
\[
D_i = \{k \in \{1, 2, \dots, 10\} \mid i \in A_k\}.
\]  
We want to find the minimum possible value of  
\[
S = \sum_{1 \le i < j \le 32} \bigl|D_i \triangle D_j\bigr|^2.
\]  

For $1 \le i \le 32$ and $1 \le k \le 10$, define the indicator variables  
\[
c_{ki} =
\begin{cases}
1, & i \in A_k, \\
0, & i \notin A_k.
\end{cases}
\]  
Then the size of the symmetric difference can be written as  
\[
\bigl|D_i \triangle D_j\bigr| = \sum_{k=1}^{10} (c_{ki} - c_{kj})^2.
\]  
Hence, we can expand the total sum $S$ as follows:  
\[
\begin{aligned}
\sum_{1 \le i < j \le 32} \bigl|D_i \triangle D_j\bigr|^2
&= \sum_{1 \le i < j \le 32} \left( \sum_{k=1}^{10} (c_{ki} - c_{kj})^2 \right)^2 \\
&= \sum_{1 \le i < j \le 32} \sum_{k=1}^{10} (c_{ki} - c_{kj})^4 + 2 \sum_{1 \le i < j \le 32} \sum_{1 \le k < l \le 10} (c_{ki} - c_{kj})^2 (c_{li} - c_{lj})^2 \\
&= \sum_{k=1}^{10} \sum_{1 \le i < j \le 32} (c_{ki} - c_{kj})^4 + 2 \sum_{1 \le k < l \le 10} \sum_{1 \le i < j \le 32} (c_{ki} - c_{kj})^2 (c_{li} - c_{lj})^2.
\end{aligned}
\]  

Because for each $1 \le k \le 10$, among the $32$ values of $c_{ki}$ there are exactly $16$ ones and $16$ zeros, we have  
\[
\sum_{1 \le i < j \le 32} (c_{ki} - c_{kj})^4 = 16 \times 16 = 256,
\]  
so the first part of the sum is  
\[
\sum_{k=1}^{10} \sum_{1 \le i < j \le 32} (c_{ki} - c_{kj})^4 = 10 \times 256 = 2560.
\]  

For any fixed pair $1 \le k < l \le 10$, let $t$ be the number of indices $i$ for which $(c_{ki}, c_{li}) = (1, 1)$. Since both groups have exactly $16$ members, there are $16 - t$ indices with $(c_{ki}, c_{li}) = (1, 0)$, $16 - t$ indices with $(0, 1)$, and the remaining $32 - t - 2(16 - t) = t$ indices with $(0, 0)$. 

The term $(c_{ki} - c_{kj})^2 (c_{li} - c_{lj})^2$ equals $1$ if and only if one of the indices $i, j$ corresponds to the pair of values $(1, 1)$ and the other to $(0, 0)$, or one corresponds to $(1, 0)$ and the other to $(0, 1)$. Consequently,  
\[
\sum_{1 \le i < j \le 32} (c_{ki} - c_{kj})^2 (c_{li} - c_{lj})^2 = t^2 + (16 - t)^2 \ge 2\left(\frac{16}{2}\right)^2 = 128.
\]  
Summing this over all $\binom{10}{2}$ pairs of groups $k < l$, we obtain  
\[
\sum_{1 \le k < l \le 10} \sum_{1 \le i < j \le 32} (c_{ki} - c_{kj})^2 (c_{li} - c_{lj})^2 \ge \binom{10}{2} \times 128 = 45 \times 128 = 5760.
\]  

Thus, the total sum is bounded by  
\[
S \ge 2560 + 2 \times 5760 = 14080.
\]  

To show that this minimum is attainable, we can construct a configuration where $t = 8$ for every pair of groups. It is easy to verify that each row of the following table contains $16$ ones and $16$ zeros, and any two rows have exactly $8$ positions where both are $1$ and $8$ positions where both are $0$, meaning equality holds:

\[
\begin{array}{c|c}
\hline
A_1 & 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0 \\
A_2 & 1\; 1\; 1\; 1\; 1\; 1\; 1\; 1\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 0\; 1\; 1\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\; 1\; 0\; 1\; 0\; 1\; 0\; 0\; 1\; 0\; 1\; 1\; 0\; 0\; 0\; 1\; 1\; 0\; 1\; 0\; 1\; 0\; 1\; 1\; 0\; 1\; 0\; 0\; 1 \\
\hline
\end{array}
\]

*(Remark: Using Hadamard matrices, one can construct such an optimal configuration for up to $31$ interest groups.)*

Therefore, the smallest possible value of $S$ is $14080$.

Grading guidelines:
(Partial) 1. Reformulated the problem with indicator variables (or vectors) and obtained the identity |Di△Dj|=∑k(c_{ki}−c_{kj})^2, hence S=∑_{i<j}(∑k(c_{ki}−c_{kj})^2)^2. 2. Correctly computed the “diagonal” contribution: for each fixed group k with 16 ones and 16 zeros, proved ∑_{i<j}(c_{ki}−c_{kj})^4=16·16=256, hence the total first term is 10·256=2560. 3. For a fixed pair of groups k<l, introduced t=|Ak∩Al| and correctly derived that the cross-term sum equals t^2+(16−t)^2 (or an equivalent expression), and concluded its minimum is 128 attained at t=8. (Almost) 1. Obtained the bound S≥2560+2·(45·128)=14080 by summing the pairwise inequality t^2+(16−t)^2≥128 over all group-pairs, but did not provide (or only vaguely sketched) a configuration achieving equality. 2. Gave an explicit construction intended to have |Ak|=16 and |Ak∩Al|=8 for all k≠l (e.g. a 10×32 0–1 table / Hadamard-type pattern) but did not fully verify one of: each row has 16 ones, each pair of rows has exactly 8 common ones (equivalently also 8 common zeros), or that this indeed forces equality in the S bound. 3. Solution is almost complete, but made minor mistakes which are not negligible.

Construction task:
Provide an explicit construction for the group assignments that achieves the minimum possible value of $S$.

Construction requirements:
- Output a single Python list of lists of strings.
- The matrix must have exactly 10 rows (representing the 10 interest groups) and 32 columns (representing the 32 students).
- Each string element must be either "0" or "1", where "1" at row `i` and column `j` indicates that student `j` is in group `i`.
- Each group (row) must contain exactly 16 students (i.e., exactly 16 "1"s and 16 "0"s).
- The sum of interest differences $S$ over all $\binom{32}{2}$ pairs of students must be exactly the minimum possible value.
- Put ONLY the Python list of lists inside the construction block.

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

Verifier code:
import sys
import ast

def verify():
    input_str = sys.stdin.read().strip()
    if not input_str:
        print("Empty input.")
        return

    try:
        matrix = ast.literal_eval(input_str)
    except Exception as e:
        print(f"Failed to parse input as Python literal: {e}")
        return

    if not isinstance(matrix, list):
        print("Input must be a list.")
        return
        
    if len(matrix) != 10:
        print(f"Matrix must have exactly 10 rows, found {len(matrix)}.")
        return

    for i, row in enumerate(matrix):
        if not isinstance(row, list):
            print(f"Row {i} is not a list.")
            return
        if len(row) != 32:
            print(f"Row {i} must have exactly 32 columns, found {len(row)}.")
            return
        
        for j, val in enumerate(row):
            if not isinstance(val, str):
                print(f"Element at ({i}, {j}) is not a string.")
                return
            if val not in ["0", "1"]:
                print(f"Element at ({i}, {j}) is '{val}', but must be '0' or '1'.")
                return
        
        num_ones = sum(1 for val in row if val == "1")
        if num_ones != 16:
            print(f"Row {i} has {num_ones} '1's, but must have exactly 16.")
            return

    S = 0
    for u in range(32):
        for v in range(u + 1, 32):
            diff_count = 0
            for k in range(10):
                if matrix[k][u] != matrix[k][v]:
                    diff_count += 1
            S += diff_count ** 2

    if S != 14080:
        print(f"Sum of interest differences S is {S}, but must be exactly 14080.")
        return

    print("True")

if __name__ == "__main__":
    verify()