Below is a part of a square grid consisting of 4 rows and 2023 columns.

Determine the number of squares, all of whose vertices are grid points of the square grid.

(K. Pazourek)

![](https://cdn.mathpix.com/cropped/2024_04_17_096aded327f4b802fe92g-7.jpg?height=337&width=1422&top_left_y=1214&top_left_x=317)
The smallest square $\mathrm{s}$ with vertices at grid points has dimensions $1 \times 1$, and the largest has dimensions $4 \times 4$. Within these constraints, we will find additional cases, which we will distinguish as follows.

- Squares with sides parallel to the grid:

![](https://cdn.mathpix.com/cropped/2024_04_17_096aded327f4b802fe92g-7.jpg?height=371&width=1422&top_left_y=1939&top_left_x=317)

- Squares with sides diagonal to the grid:

![](https://cdn.mathpix.com/cropped/2024_04_17_096aded327f4b802fe92g-8.jpg?height=380&width=1424&top_left_y=187&top_left_x=316)

- Other squares:

![](https://cdn.mathpix.com/cropped/2024_04_17_096aded327f4b802fe92g-8.jpg?height=374&width=1422&top_left_y=675&top_left_x=317)

For counting squares of a certain type, the orientation is not important, but only how many units they occupy in the horizontal and vertical directions. Thus, the number of squares of type $B$ is the same as the number of squares of type $E$. The number of squares of type $C$ is the same as the number of squares of type $G$, or $H$. The number of squares of type $D$ is the same as the number of squares of type $F$, which is the same as the number of squares of type $I$, or $J$.

Therefore, it is sufficient to count squares of four types:

- A square of type $A$ can be placed in four ways vertically and 2023 ways horizontally. The number of such squares is

$$
4 \cdot 2023=8092 \text {. }
$$

- A square of type $B$ (or $E$) can be placed in three ways vertically and 2022 ways horizontally. The number of such squares is

$$
3 \cdot 2022=6066
$$

- A square of type $C$ (or $G, H$) can be placed in two ways vertically and 2021 ways horizontally. The number of such squares is

$$
2 \cdot 2021=4042 \text {. }
$$

- A square of type $D$ (or $F, I, J$) can be placed in one way vertically and 2020 ways horizontally. The number of such squares is

$$
1 \cdot 2020=2020 \text {. }
$$

The number of squares whose all vertices are grid points is

$$
1 \cdot 8092 + 2 \cdot 6066 + 3 \cdot 4042 + 4 \cdot 2020 = 40430 .
$$