Problem (Combinatorics):
On some planet, there are $2^{N}$ countries $(N \geq 4)$. Each country has a flag $N$ units wide and one unit high composed of $N$ fields of size $1 \times 1$, each field being either yellow or blue. No two countries have the same flag.

We say that a set of $N$ flags is diverse if these flags can be arranged into an $N \times N$ square so that all $N$ fields on its main diagonal will have the same color. Determine the smallest positive integer $M$ such that among any $M$ distinct flags, there exist $N$ flags forming a diverse set.

Solution:
When speaking about the diagonal of a square, we will always mean the main diagonal.

Let $M_{N}$ be the smallest positive integer satisfying the problem condition. First, we show that $M_{N}>2^{N-2}$. Consider the collection of all $2^{N-2}$ flags having yellow first squares and blue second ones. Obviously, both colors appear on the diagonal of each $N \times N$ square formed by these flags.

We are left to show that $M_{N} \leq 2^{N-2}+1$, thus obtaining the desired answer. We start with establishing this statement for $N=4$.

Suppose that we have 5 flags of length 4 . We decompose each flag into two parts of 2 squares each; thereby, we denote each flag as $L R$, where the $2 \times 1$ flags $L, R \in \mathcal{S}=\{\mathrm{BB}, \mathrm{BY}, \mathrm{YB}, \mathrm{YY}\}$ are its left and right parts, respectively. First, we make two easy observations on the flags $2 \times 1$ which can be checked manually.

(i) For each $A \in \mathcal{S}$, there exists only one $2 \times 1$ flag $C \in \mathcal{S}$ (possibly $C=A$ ) such that $A$ and $C$ cannot form a $2 \times 2$ square with monochrome diagonal (for part $\mathrm{BB}$, that is $\mathrm{YY}$, and for $\mathrm{BY}$ that is $\mathrm{YB)}$.

(ii) Let $A_{1}, A_{2}, A_{3} \in \mathcal{S}$ be three distinct elements; then two of them can form a $2 \times 2$ square with yellow diagonal, and two of them can form a $2 \times 2$ square with blue diagonal (for all parts but $\mathrm{BB}$, a pair (BY, YB) fits for both statements, while for all parts but BY, these pairs are $(\mathrm{YB}, \mathrm{YY})$ and $(\mathrm{BB}, \mathrm{YB}))$.

Now, let $\ell$ and $r$ be the numbers of distinct left and right parts of our 5 flags, respectively. The total number of flags is $5 \leq r \ell$, hence one of the factors (say, $r$ ) should be at least 3 . On the other hand, $\ell, r \leq 4$, so there are two flags with coinciding right part; let them be $L_{1} R_{1}$ and $L_{2} R_{1}\left(L_{1} \neq L_{2}\right)$.

Next, since $r \geq 3$, there exist some flags $L_{3} R_{3}$ and $L_{4} R_{4}$ such that $R_{1}, R_{3}, R_{4}$ are distinct. Let $L^{\prime} R^{\prime}$ be the remaining flag. By (i), one of the pairs $\left(L^{\prime}, L_{1}\right)$ and $\left(L^{\prime}, L_{2}\right)$ can form a $2 \times 2$ square with monochrome diagonal; we can assume that $L^{\prime}, L_{2}$ form a square with a blue diagonal. Finally, the right parts of two of the flags $L_{1} R_{1}, L_{3} R_{3}, L_{4} R_{4}$ can also form a $2 \times 2$ square with a blue diagonal by (ii). Putting these $2 \times 2$ squares on the diagonal of a $4 \times 4$ square, we find a desired arrangement of four flags.

We are ready to prove the problem statement by induction on $N$; actually, above we have proved the base case $N=4$. For the induction step, assume that $N>4$, consider any $2^{N-2}+1$ flags of length $N$, and arrange them into a large flag of size $\left(2^{N-2}+1\right) \times N$. This flag contains a non-monochrome column since the flags are distinct; we may assume that this column is the first one. By the pigeonhole principle, this column contains at least $\left\lceil\frac{2^{N-2}+1}{2}\right\rceil=2^{N-3}+1$ squares of one color (say, blue). We call the flags with a blue first square good.

Consider all the good flags and remove the first square from each of them. We obtain at least $2^{N-3}+1 \geq M_{N-1}$ flags of length $N-1$; by the induction hypothesis, $N-1$ of them



can form a square $Q$ with the monochrome diagonal. Now, returning the removed squares, we obtain a rectangle $(N-1) \times N$, and our aim is to supplement it on the top by one more flag.

If $Q$ has a yellow diagonal, then we can take each flag with a yellow first square (it exists by a choice of the first column; moreover, it is not used in $Q$ ). Conversely, if the diagonal of $Q$ is blue then we can take any of the $\geq 2^{N-3}+1-(N-1)>0$ remaining good flags. So, in both cases we get a desired $N \times N$ square.

We present a different proof of the estimate $M_{N} \leq 2^{N-2}+1$. We do not use the induction, involving Hall's lemma on matchings instead.

Consider arbitrary $2^{N-2}+1$ distinct flags and arrange them into a large $\left(2^{N-2}+1\right) \times N$ flag. Construct two bipartite graphs $G_{\mathrm{y}}=\left(V \cup V^{\prime}, E_{\mathrm{y}}\right)$ and $G_{\mathrm{b}}=\left(V \cup V^{\prime}, E_{\mathrm{b}}\right)$ with the common set of vertices as follows. Let $V$ and $V^{\prime}$ be the set of columns and the set of flags under consideration, respectively. Next, let the edge $(c, f)$ appear in $E_{\mathrm{y}}$ if the intersection of column $c$ and flag $f$ is yellow, and $(c, f) \in E_{\mathrm{b}}$ otherwise. Then we have to prove exactly that one of the graphs $G_{\mathrm{y}}$ and $G_{\mathrm{b}}$ contains a matching with all the vertices of $V$ involved.

Assume that these matchings do not exist. By Hall's lemma, it means that there exist two sets of columns $S_{\mathrm{y}}, S_{\mathrm{b}} \subset V$ such that $\left|E_{\mathrm{y}}\left(S_{\mathrm{y}}\right)\right| \leq\left|S_{\mathrm{y}}\right|-1$ and $\left|E_{\mathrm{b}}\left(S_{\mathrm{b}}\right)\right| \leq\left|S_{\mathrm{b}}\right|-1$ (in the left-hand sides, $E_{\mathrm{y}}\left(S_{\mathrm{y}}\right)$ and $E_{\mathrm{b}}\left(S_{\mathrm{b}}\right)$ denote respectively the sets of all vertices connected to $S_{\mathrm{y}}$ and $S_{\mathrm{b}}$ in the corresponding graphs). Our aim is to prove that this is impossible. Note that $S_{\mathrm{y}}, S_{\mathrm{b}} \neq V$ since $N \leq 2^{N-2}+1$.

First, suppose that $S_{\mathrm{y}} \cap S_{\mathrm{b}} \neq \varnothing$, so there exists some $c \in S_{\mathrm{y}} \cap S_{\mathrm{b}}$. Note that each flag is connected to $c$ either in $G_{\mathrm{y}}$ or in $G_{\mathrm{b}}$, hence $E_{\mathrm{y}}\left(S_{\mathrm{y}}\right) \cup E_{\mathrm{b}}\left(S_{\mathrm{b}}\right)=V^{\prime}$. Hence we have $2^{N-2}+1=\left|V^{\prime}\right| \leq\left|E_{\mathrm{y}}\left(S_{\mathrm{y}}\right)\right|+\left|E_{\mathrm{b}}\left(S_{\mathrm{b}}\right)\right| \leq\left|S_{\mathrm{y}}\right|+\left|S_{\mathrm{b}}\right|-2 \leq 2 N-4$; this is impossible for $N \geq 4$.

So, we have $S_{\mathrm{y}} \cap S_{\mathrm{b}}=\varnothing$. Let $y=\left|S_{\mathrm{y}}\right|, b=\left|S_{\mathrm{b}}\right|$. From the construction of our graph, we have that all the flags in the set $V^{\prime \prime}=V^{\prime} \backslash\left(E_{\mathrm{y}}\left(S_{\mathrm{y}}\right) \cup E_{\mathrm{b}}\left(S_{\mathrm{b}}\right)\right)$ have blue squares in the columns of $S_{\mathrm{y}}$ and yellow squares in the columns of $S_{\mathrm{b}}$. Hence the only undetermined positions in these flags are the remaining $N-y-b$ ones, so $2^{N-y-b} \geq\left|V^{\prime \prime}\right| \geq\left|V^{\prime}\right|-\left|E_{\mathrm{y}}\left(S_{\mathrm{y}}\right)\right|-\left|E_{\mathrm{b}}\left(S_{\mathrm{b}}\right)\right| \geq$ $2^{N-2}+1-(y-1)-(b-1)$, or, denoting $c=y+b, 2^{N-c}+c>2^{N-2}+2$. This is impossible since $N \geq c \geq 2$.

Final answer: $M=2^{N-2}+1$