$A z A(0,0), B(n, 0), C(n, n)$ and $D(0, n)$ points define a square. We color the lattice points on the boundary and inside of this square red or green such that for every unit square within the square, exactly two of its vertices are red. How many ways can we do this?
The lattice points are arranged in $n+1$ rows and $n+1$ columns. Specifically, the $i$-th row $(0 \leq i \leq n)$ contains those lattice points whose second coordinate is $i$. Similarly, the $i$-th column consists of those points whose first coordinate is $i$. Two lattice points will be called adjacent if they are next to each other in the same row or column. Thus, the neighbors of the point $(i, j)$ are the points $(i-1, j),(i+1, j)$, $(i, j-1)$, and $(i, j+1)$, provided that these are also points of the square $A B C D$.

Clearly, we get a good coloring of the points if we color the consecutive points in each row alternately red and green. In this case, we can color each row independently in two ways, so the number of such colorings is $2^{n+1}$. For the same reason, the $2^{n+1}$ colorings are also good, where the points in each column follow each other alternately in red and green. Since the points can be colored in two ways so that no two adjacent points in the rows or columns are the same color, we have thus found

$$
2^{n+1}+2^{n+1}-2=2^{n+2}-2
$$

good colorings.

We will show that apart from the above, there are no other good colorings. For this, let us first assume that the points have been colored in the desired way, and in some column - say the $i$-th one - there are two adjacent points of the same color. Let these be $(i, j)$ and $(i, j+1)$. Then in the $(i-1)$-th and $(i+1)$-th columns, there are also two adjacent points of the same color. Specifically, the points $(i-1, j),(i-1, j+1),(i+1, j),(i+1, j+1)$ are all of the same color, and they must be of a different color from the points $(i, j),(i, j+1)$. It can then be easily verified by induction that the points $(i-k, j),(i-k, j+1),(i+k, j),(i+k, j+1)$ have the same color as the points $(i, j),(i, j+1)$ if $k$ is even, and a different color if $k$ is odd.

Now let us also assume that in some row - say the $j'$-th one - there are two adjacent points of the same color: $\left(i', j'\right)$ and $\left(i'+1, j'\right)$. By a similar line of reasoning (or more simply: by symmetry), we can conclude that for every $k$, the points $\left(i', j'-k\right),\left(i'+1, j'-k\right),\left(i', j'+k\right),\left(i'+1, j'+k\right)$ are of the same color.

According to the above, the color of the point $\left(i', j\right)$ must match both the color of the point $\left(i', j+1\right)$ and the color of the point $\left(i'+1, j\right)$. However, this cannot happen in a good coloring, since the three points listed are precisely three vertices of a unit square. This contradiction proves our claim that in every good coloring, either the points in the columns or the points in the rows follow each other alternately in color. The number of such colorings is therefore $2^{n+2}-2$.