Problem: Consider an $n$-by-$n$ board of unit squares for some odd positive integer $n$.
We say that a collection $C$ of identical dominoes is a
maximal grid-aligned configuration on the board if $C$ consists of $(n^2-1)/2$
dominoes where each domino covers exactly two neighboring squares
and the dominoes don't overlap: $C$ then covers all but one square on the board.
We are allowed to slide (but not rotate) a domino on the board to
cover the uncovered square, resulting in a new maximal grid-aligned configuration
with another square uncovered. Let $k(C)$ be the number of distinct maximal
grid-aligned configurations obtainable from $C$ by repeatedly sliding dominoes.

Find all possible values of $k(C)$ as a function of $n$.

Solution: The answer is that
\[ k(C) \in \left\{ 1, 2, \dots, \left( \frac{n-1}{2} \right)^2 \right\}
  \cup \left\{ \left( \frac{n+1}{2} \right)^2 \right\}. \]

Index the squares by coordinates $(x,y) \in \{1,2,\dots,n\}^2$.
We say a square is \emph{special} if it is empty or
it has the same parity in both coordinates as the empty square.

We now proceed in two cases:

\paragraph{The special squares have both odd coordinates.}
We construct a directed graph $G = G(C)$ whose
vertices are special squares as follows:
for each domino on a special square $s$, we draw a directed edge
from $s$ to the special square that domino points to.
Thus all special squares have an outgoing edge except the empty cell.
\begin{center}
\begin{asy}
size(6cm);

pen border = gray+1.5;

filldraw(box((0, 1), (1, 3)), lightgreen, border);
filldraw(box((0, 3), (2, 4)), lightcyan, border);
filldraw(box((0, 4), (2, 5)), lightgreen, border);
filldraw(box((1, 0), (2, 3)), lightred, border);
filldraw(box((1, 2), (3, 3)), lightblue, border);
filldraw(box((2, 3), (3, 5)), palered, border);
filldraw(box((2, 0), (4, 1)), lightcyan, border);
filldraw(box((2, 1), (4, 2)), lightgreen, border);
filldraw(box((4, 0), (5, 2)), lightred, border);
filldraw(box((3, 3), (5, 4)), lightblue, border);
filldraw(box((3, 2), (5, 3)), palered, border);
filldraw(box((3, 4), (5, 5)), lightcyan, border);
filldraw(box((0, 0), (1, 1)), gray, border);

pair A = (0.5, 4.5);
pair B = (2.5, 4.5);
pair C = (4.5, 4.5);
pair D = (0.5, 2.5);
pair E = (2.5, 2.5);
pair F = (4.5, 2.5);
pair X = (0.5, 0.5);
pair Y = (2.5, 0.5);
pair Z = (4.5, 0.5);

dotfactor *= 2;
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);

draw(A--B, EndArrow, Margin(3,3));
draw(C--B, EndArrow, Margin(3,3));
draw(B--E, EndArrow, Margin(3,3));
draw(E--D, EndArrow, Margin(3,3));
draw(F--E, EndArrow, Margin(3,3));
draw(Z--F, EndArrow, Margin(3,3));
draw(Y--Z, EndArrow, Margin(3,3));
draw(D--X, EndArrow, Margin(3,3));
\end{asy}
\end{center}

\begin{claim*}
  Any undirected connected component of $G$ is acyclic unless the cycle
  contains the empty square inside it.
\end{claim*}
\begin{proof}
  Consider a cycle of $G$; we are going to prove
  that the number of chessboard cells enclosed is always odd.

  This can be proven directly by induction,
  but for theatrical effect, we use Pick's theorem.
  Mark the center of every chessboard cell on or inside the cycle
  to get a lattice.
  The dominoes of the cycle then enclose a polyominoe which
  actually consists of $2 \times 2$ squares,
  meaning its area is a multiple of $4$.
  \begin{center}
  \begin{asy}
    unitsize(0.9cm);
    filldraw(box((-0.5,1.5), (0.5,3.5)), paleyellow, gray+1.4);
    filldraw(box((-0.5,3.5), (1.5,4.5)), paleyellow, gray+1.4);
    filldraw(box((1.5,3.5), (3.5,4.5)), paleyellow, gray+1.4);
    filldraw(box((3.5,2.5), (4.5,4.5)), paleyellow, gray+1.4);
    filldraw(box((3.5,0.5), (4.5,2.5)), paleyellow, gray+1.4);
    filldraw(box((2.5,-0.5), (4.5,0.5)), paleyellow, gray+1.4);
    filldraw(box((1.5,-0.5), (2.5,1.5)), paleyellow, gray+1.4);
    filldraw(box((0.5,1.5), (2.5,2.5)), paleyellow, gray+1.4);
    draw((0,2)--(0,4), blue+1.2, EndArrow(TeXHead), Margins);
    draw((0,4)--(2,4), blue+1.2, EndArrow(TeXHead), Margins);
    draw((2,4)--(4,4), blue+1.2, EndArrow(TeXHead), Margins);
    draw((4,4)--(4,2), blue+1.2, EndArrow(TeXHead), Margins);
    draw((4,2)--(4,0), blue+1.2, EndArrow(TeXHead), Margins);
    draw((4,0)--(2,0), blue+1.2, EndArrow(TeXHead), Margins);
    draw((2,0)--(2,2), blue+1.2, EndArrow(TeXHead), Margins);
    draw((2,2)--(0,2), blue+1.2, EndArrow(TeXHead), Margins);
    draw((2,2)--(2,4), blue+dashed, Margins);
    draw((2,2)--(4,2), blue+dashed, Margins);
    dotfactor *= 1.8;
    dot((2,0), blue);
    dot((4,0), blue);
    dot((0,2), blue);
    dot((2,2), blue);
    dot((4,2), blue);
    dot((0,4), blue);
    dot((2,4), blue);
    dot((4,4), blue);
    dot((0,3), black);
    dot((1,4), black);
    dot((3,4), black);
    dot((4,3), black);
    dot((4,1), black);
    dot((3,0), black);
    dot((2,1), black);
    dot((1,2), black);
    dot((1,3), red);
    dot((2,3), red);
    dot((3,3), red);
    dot((3,2), red);
    dot((3,1), red);
  \end{asy}
  \end{center}
  Hence $B/2+I-1$ is a multiple of $4$, in the notation of Pick's theorem.
  As $B$ is twice the number of dominoes,
  and a parity argument on the special squares shows that number is even,
  it follows that $B$ is also a multiple of $4$
  (these correspond to blue and black in the figure above).
  This means $I$ is odd (the red dots in the figure above), as desired.
\end{proof}

Let $T$ be the connected component containing the empty cell.
By the claim, $T$ is acyclic, so it's a tree.
Now, notice that all the arrows point along $T$ towards the empty cell,
and moving a domino corresponds to flipping an arrow.
Therefore:
\begin{claim*}
$k(C)$ is exactly the number of vertices of $T$.
\end{claim*}
\begin{proof}
Starting with the underlying tree,
the set of possible graphs is described by picking one vertex to be the sink
(the empty cell) and then directing all arrows towards it.
\end{proof}

This implies that $k(C) \le \left( \frac{n+1}{2} \right)^2$ in this case.
Equality is achieved if $T$ is a spanning tree of $G$.
One example of a way to achieve this is using the snake configuration below.

\begin{center}
\begin{asy}
unitsize(0.9cm);
dotfactor *= 2;
pen border = gray+1.5;
pair A = (0.5, 4.5);
pair B = (2.5, 4.5);
pair C = (4.5, 4.5);
pair D = (0.5, 2.5);
pair E = (2.5, 2.5);
pair F = (4.5, 2.5);
pair X = (0.5, 0.5);
pair Y = (2.5, 0.5);
pair Z = (4.5, 0.5);

filldraw(box((3, 4), (5, 5)), palecyan, border);
filldraw(box((1, 4), (3, 5)), palecyan, border);
filldraw(box((0, 3), (1, 5)), palecyan, border);
filldraw(box((0, 2), (2, 3)), palecyan, border);
filldraw(box((2, 2), (4, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((0, 1), (2, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);

draw(C--B, EndArrow, Margin(3,3));
draw(B--A, EndArrow, Margin(3,3));
draw(A--D, EndArrow, Margin(3,3));
draw(D--E, EndArrow, Margin(3,3));
draw(E--F, EndArrow, Margin(3,3));
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
\end{asy}
\end{center}

\begin{remark*}
  In Russia 1997/11.8 it's shown that as long as the missing square is a corner,
  we have $G = T$.
  The proof is given implicitly from our work here:
  when the empty cell is in a corner, it cannot be surrounded,
  ergo the resulting graph has no cycles at all.
  And since the overall graph has one fewer edge than vertex, it's a tree.
\end{remark*}

Conversely, suppose $T$ was \emph{not} a spanning tree, i.e.\ $T \neq G$.
Since in this odd-odd case, $G$ has one fewer edge than vertex,
if $G$ is not a tree, then it must contain at least one cycle.
That cycle encloses every special square of $T$.
In particular, this means that $T$ can't contain any special squares
from the outermost row or column of the $n \times n$ grid.
In this situation, we therefore have $k(C) \le \left( \frac{n-3}{2} \right)^2$.

\paragraph{The special squares have both even coordinates.}
We construct the analogous graph $G$ on the same special squares.
However, in this case, some of the points may not have outgoing edges,
because their domino may ``point'' outside the grid.

\begin{center}
\begin{asy}
size(8cm);

pen border = gray+1.5;

filldraw(box((0, 1), (1, 3)), lightgreen, border);
filldraw(box((0, 3), (2, 4)), lightcyan, border);
filldraw(box((0, 4), (2, 5)), lightgreen, border);
filldraw(box((1, 0), (2, 3)), lightred, border);
filldraw(box((1, 2), (3, 3)), lightblue, border);
filldraw(box((2, 3), (3, 5)), palered, border);
filldraw(box((2, 0), (4, 1)), lightcyan, border);
filldraw(box((2, 1), (4, 2)), lightgreen, border);
filldraw(box((4, 0), (5, 2)), lightred, border);
filldraw(box((0, 0), (1, 1)), gray, border);

filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 4), (6, 6)), brown, border);
filldraw(box((1, 5), (3, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((-1, 1), (0, 3)), yellow, border);
filldraw(box((-1, 3), (0, 5)), brown, border);

filldraw(box((3, 4), (4, 6)), purple, border);
filldraw(box((4, 4), (5, 6)), magenta, border);

filldraw(box((4, 3), (6, 4)), lightblue, border);
filldraw(box((4, 2), (6, 3)), palered, border);
filldraw(box((3, 2), (4, 4)), yellow, border);

pair A = (0.5, 4.5);
pair B = (2.5, 4.5);
pair C = (4.5, 4.5);
pair D = (0.5, 2.5);
pair E = (2.5, 2.5);
pair F = (4.5, 2.5);
pair X = (0.5, 0.5);
pair Y = (2.5, 0.5);
pair Z = (4.5, 0.5);

dotfactor *= 2;
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);

draw(A--B, EndArrow, Margin(3,3));
draw(B--E, EndArrow, Margin(3,3));
draw(E--D, EndArrow, Margin(3,3));
draw(Z--F, EndArrow, Margin(3,3));
draw(Y--Z, EndArrow, Margin(3,3));
draw(D--X, EndArrow, Margin(3,3));
\end{asy}
\end{center}

As before, the connected component $T$ containing the empty square is a tree,
and $k(C)$ is exactly the number of vertices of $T$.
Thus to finish the problem we need to give,
for each $k \in \{1,2,\dots,\left( \frac{n-1}{2} \right)^2\}$,
an example of a configuration where $G$ has exactly $k$ vertices.

The construction starts with a ``snake'' picture for
$k = \left( \frac{n-1}{2} \right)^2$,
then decreases $k$ by one by perturbing a suitable set of dominoes.
Rather than write out the procedure in words,
we show the sequence of nine pictures for $n=7$ (where $k=9,8,\dots,1$);
the generalization to larger $n$ is straightforward.

\begin{center}
\begin{asy}
unitsize(0.6cm);
dotfactor *= 2;
pen border = gray+1.5;
pair A = (0.5, 4.5);
pair B = (2.5, 4.5);
pair C = (4.5, 4.5);
pair D = (0.5, 2.5);
pair E = (2.5, 2.5);
pair F = (4.5, 2.5);
pair X = (0.5, 0.5);
pair Y = (2.5, 0.5);
pair Z = (4.5, 0.5);

/* Picture 0 */
filldraw(box((3, 4), (5, 5)), palecyan, border);
filldraw(box((1, 4), (3, 5)), palecyan, border);
filldraw(box((0, 3), (1, 5)), palecyan, border);
filldraw(box((0, 2), (2, 3)), palecyan, border);
filldraw(box((2, 2), (4, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((0, 1), (2, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((5, 4), (6, 6)), brown, border);
filldraw(box((3, 5), (5, 6)), yellow, border);
filldraw(box((1, 5), (3, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((-1, 1), (0, 3)), yellow, border);
filldraw(box((-1, 3), (0, 5)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);

draw(C--B, EndArrow, Margin(3,3));
draw(B--A, EndArrow, Margin(3,3));
draw(A--D, EndArrow, Margin(3,3));
draw(D--E, EndArrow, Margin(3,3));
draw(E--F, EndArrow, Margin(3,3));
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p0 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 1 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((1, 4), (3, 5)), palecyan, border);
filldraw(box((0, 3), (1, 5)), palecyan, border);
filldraw(box((0, 2), (2, 3)), palecyan, border);
filldraw(box((2, 2), (4, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((0, 1), (2, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((3, 4), (4, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((1, 5), (3, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((-1, 1), (0, 3)), yellow, border);
filldraw(box((-1, 3), (0, 5)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(B--A, EndArrow, Margin(3,3));
draw(A--D, EndArrow, Margin(3,3));
draw(D--E, EndArrow, Margin(3,3));
draw(E--F, EndArrow, Margin(3,3));
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p1 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 2 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((0, 3), (1, 5)), palecyan, border);
filldraw(box((0, 2), (2, 3)), palecyan, border);
filldraw(box((2, 2), (4, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((0, 1), (2, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((-1, 1), (0, 3)), yellow, border);
filldraw(box((-1, 3), (0, 5)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(A--D, EndArrow, Margin(3,3));
draw(D--E, EndArrow, Margin(3,3));
draw(E--F, EndArrow, Margin(3,3));
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p2 = rotate(0)*currentpicture;
currentpicture.erase();


/* Picture 3 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((-1, 4), (1, 5)), palecyan, border);
filldraw(box((0, 2), (2, 3)), palecyan, border);
filldraw(box((2, 2), (4, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((0, 1), (2, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((-1, 1), (0, 3)), yellow, border);
filldraw(box((-1, 3), (1, 4)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(D--E, EndArrow, Margin(3,3));
draw(E--F, EndArrow, Margin(3,3));
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p3 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 4 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((-1, 4), (1, 5)), palecyan, border);
filldraw(box((-1, 2), (1, 3)), palecyan, border);
filldraw(box((2, 2), (4, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((-1, 1), (1, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((1, 1), (2, 3)), yellow, border);
filldraw(box((-1, 3), (1, 4)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(E--F, EndArrow, Margin(3,3));
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p4 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 5 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((-1, 4), (1, 5)), palecyan, border);
filldraw(box((-1, 2), (1, 3)), palecyan, border);
filldraw(box((1, 2), (3, 3)), palecyan, border);
filldraw(box((4, 1), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((-1, 1), (1, 2)), lightred, border);
filldraw(box((1, 1), (3, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((3, 1), (4, 3)), yellow, border);
filldraw(box((-1, 3), (1, 4)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(F--Z, EndArrow, Margin(3,3));
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p5 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 6 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((-1, 4), (1, 5)), palecyan, border);
filldraw(box((-1, 2), (1, 3)), palecyan, border);
filldraw(box((1, 2), (3, 3)), palecyan, border);
filldraw(box((3, 2), (5, 3)), palecyan, border);
filldraw(box((3, 0), (5, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((-1, 1), (1, 2)), lightred, border);
filldraw(box((1, 1), (3, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((5, 0), (6, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((3, 1), (5, 2)), yellow, border);
filldraw(box((-1, 3), (1, 4)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(Z--Y, EndArrow, Margin(3,3));
draw(Y--X, EndArrow, Margin(3,3));
picture p6 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 7 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((-1, 4), (1, 5)), palecyan, border);
filldraw(box((-1, 2), (1, 3)), palecyan, border);
filldraw(box((1, 2), (3, 3)), palecyan, border);
filldraw(box((3, 2), (5, 3)), palecyan, border);
filldraw(box((4, 0), (6, 1)), palecyan, border);
filldraw(box((1, 0), (3, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((-1, 1), (1, 2)), lightred, border);
filldraw(box((1, 1), (3, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((3, 0), (4, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((4, 1), (6, 2)), yellow, border);
filldraw(box((-1, 3), (1, 4)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
draw(Y--X, EndArrow, Margin(3,3));
picture p7 = rotate(0)*currentpicture;
currentpicture.erase();

/* Picture 8 */
filldraw(box((4, 4), (6, 5)), palecyan, border);
filldraw(box((2, 4), (4, 5)), palecyan, border);
filldraw(box((-1, 4), (1, 5)), palecyan, border);
filldraw(box((-1, 2), (1, 3)), palecyan, border);
filldraw(box((1, 2), (3, 3)), palecyan, border);
filldraw(box((3, 2), (5, 3)), palecyan, border);
filldraw(box((4, 0), (6, 1)), palecyan, border);
filldraw(box((2, 0), (4, 1)), palecyan, border);
fill(unitsquare, mediumgray);
filldraw(box((3, 3), (5, 4)), lightred, border);
filldraw(box((1, 3), (3, 4)), lightred, border);
filldraw(box((-1, 1), (1, 2)), lightred, border);
filldraw(box((2, 1), (4, 2)), lightred, border);
filldraw(box((0, -1), (2, 0)), yellow, border);
filldraw(box((2, -1), (4, 0)), brown, border);
filldraw(box((4, -1), (6, 0)), yellow, border);
filldraw(box((1, 0), (2, 2)), brown, border);
filldraw(box((5, 2), (6, 4)), yellow, border);
filldraw(box((1, 4), (2, 6)), brown, border);
filldraw(box((4, 5), (6, 6)), yellow, border);
filldraw(box((2, 5), (4, 6)), brown, border);
filldraw(box((-1, 5), (1, 6)), yellow, border);
filldraw(box((-1, -1), (0, 1)), brown, border);
filldraw(box((4, 1), (6, 2)), yellow, border);
filldraw(box((-1, 3), (1, 4)), brown, border);
dot(A); dot(B); dot(C);
dot(D); dot(E); dot(F);
dot(X); dot(Y); dot(Z);
picture p8 = rotate(0)*currentpicture;
currentpicture.erase();

add(shift(0,0)*p0);
add(shift(8,0)*p1);
add(shift(16,0)*p2);
add(shift(0,-8)*p3);
add(shift(8,-8)*p4);
add(shift(16,-8)*p5);
add(shift(0,-16)*p6);
add(shift(8,-16)*p7);
add(shift(16,-16)*p8);
\end{asy}
\end{center}