Zuzka built a square of dimensions $4 \times 4$ using sixteen equally large cubes. With $\mathrm{S}$ additional identical cubes, she continued building. She placed the cubes on top of each other so that any two adjacent cubes shared a whole face. The resulting structure looked from two different sides as shown in the following image.

Determine the maximum and minimum number of cubes Zuzka could have used for her construction.

(E. Novotná)
![](https://cdn.mathpix.com/cropped/2024_04_17_96587d6cc949a3c812fag-1.jpg?height=280&width=898&top_left_y=1856&top_left_x=585)
In the first layer, there were 16 cubes. From the given views, it follows that in the third layer, there were 2 cubes. The number of cubes in the second layer cannot be uniquely determined, but the maximum number could be $3 \cdot 3=9$. This possibility is illustrated in the following image, where the two given projections correspond to the front and side views:

![](https://cdn.mathpix.com/cropped/2024_04_17_96587d6cc949a3c812fag-2.jpg?height=371&width=462&top_left_y=186&top_left_x=800)

Indeed, it is not possible to add a single cube without changing one of the given projections. Zuzka used the maximum of $16+9+2=27$ cubes.

To find the minimum possible number of cubes, one can proceed by removing as many cubes as possible from the second layer without changing any of the given projections. One such possibility looks like this:

![](https://cdn.mathpix.com/cropped/2024_04_17_96587d6cc949a3c812fag-2.jpg?height=371&width=466&top_left_y=1002&top_left_x=795)

There cannot be fewer than four cubes in the second layer. The two cubes on which the cubes from the third layer stand are hidden in the side view. Therefore, two additional cubes must be used to match the given projection. Zuzka used the minimum of $16+4+2=22$ cubes.

Note. For the option with the minimum number of cubes, the cubes in the second layer can be arranged differently, but not arbitrarily. Another possible arrangement is this:

![](https://cdn.mathpix.com/cropped/2024_04_17_96587d6cc949a3c812fag-2.jpg?height=374&width=466&top_left_y=1863&top_left_x=795)

By making adjustments in the second layer, a structure with any number of cubes in the range from 22 to 27 can be achieved. Here is one possibility built with 23 cubes:

![](https://cdn.mathpix.com/cropped/2024_04_17_96587d6cc949a3c812fag-3.jpg?height=371&width=462&top_left_y=186&top_left_x=800)

#