Let $PABCD$ be a regular quadrilateral pyramid with vertex $P$; $M$ and $N$ are the midpoints of the sides $AD$ and $BC$ of the base $ABCD$, respectively. The section of the pyramid by the plane passing through points $P, M$, and $N$ is an isosceles triangle $PMN$, with the base $MN$ equal to the side of the square $ABCD$. The centers $O_1$ and $O_2$ of the tangent circles of radius $r$ are located on the height $PQ$. The circle with center $O_1$ is inscribed in the angle $MPN$, and the circle with center $O_2$ touches the base $MN$ at its midpoint $Q$. Let the side of the square $ABCD$ be $a$, the height of the pyramid be $x$, and the circle with center $O$ touches $PN$ at point $F$. From the similarity of the right triangles $PFO_1$ and $PQN$, it follows that

$$
\frac{PO_1}{PN} = \frac{O_1F'}{QN}, \quad \sqrt{\frac{x-3\varphi}{x^2 + \frac{a^2}{1}}} = \frac{2\varphi}{a}
$$

From this equation, we find that

$$
a^2 = \frac{4r^2 x^2}{x^2 - 6rx + br^2}
$$

If $V(x)$ is the volume of the pyramid $PABCD$, then

$$
V(x) = \frac{1}{3} S_{ABCD} \cdot PQ = \frac{1}{3} a^2 x = \frac{1}{3} \cdot \frac{4r^2 x^3}{x^2 - 6rx + br^2}
$$

Since $x > 4r$, the problem reduces to finding the value of $x$ on the interval $(4r; +\infty)$ for which the function $V(x)$ attains its minimum value on this interval. Solving the equation $V'(x) = 0$, we find the critical points of the function $V(x)$. We consider only those that belong to the interval $(4r; +\infty)$.

$$
\begin{gathered}
V'(x) = \frac{4}{3} r \cdot \frac{3x^2(x^2 - 6rx + 8r^2) - x^3(2x - 6r)}{(x^2 - 6rx + 8r^2)^2} = \\
= \frac{4}{3} r \cdot \frac{x^2(3x^2 - 18rx + 24r^2 - 2x^2 + 6rx)}{(x^2 - 6rx + 8r^2)^2} = \frac{4}{3} r \cdot \frac{x^2(x^2 - 12rx + 24r^2)}{(x^2 - 6rx + 8r^2)^2} = 0
\end{gathered}
$$

The interval $(4r; +\infty)$ contains the only root of this equation $x = (6 + 2\sqrt{3})r$. As we pass through the point $x = (6 + 2\sqrt{3})r$, the derivative changes sign from negative to positive. Therefore, on the interval $(4r; (6 + 2\sqrt{3})r)$, the function $V(x)$ decreases, and on the interval $((6 + 2\sqrt{3})r; +\infty)$, it increases. Thus, at $x = (6 + 2\sqrt{3})r$, the volume of the pyramid $PABCD$ is the smallest.

## Answer

$(6 + 2\sqrt{3})r$
In a regular quadrilateral pyramid, two identical spheres of radius $r$ are placed, with their centers located on the axis of symmetry of the pyramid. One of the spheres touches all the lateral faces of the pyramid, while the second touches the base of the pyramid and the first sphere. Find the height of the pyramid for which the volume of the pyramid is the smallest.