Solution (source code)

= Solution

For column $j$, let $N_j$ of the $M$ codewords have a one. A pair contributes a one in that column exactly when one word is chosen from those $N_j$ words and the other from the remaining $M-N_j$. Hence column $j$ contains
$$
N_j(M-N_j)
$$
ones among all pairwise sums. Part (i), summed over the $n$ columns, gives the upper bound
$$
\#1(A)\le
\begin{cases}
nM^2/4,&M\text{ even},\\
n(M^2-1)/4,&M\text{ odd}.
\end{cases}
$$
There are $\binom M2$ rows, one for each unordered pair of codewords. By part (ii), every row has weight equal to that pair's distance, which is at least $d$. Therefore
$$
\boxed{\#1(A)\ge d\binom M2=\frac{dM(M-1)}2}.
$$