In triangle $ABC$, the lengths of sides $AC$ and $BC$ are fixed, while the angle at $C$ varies. The midpoint of side $AC$ is $M$, the midpoint of side $BC$ is $N$, and the center of the square constructed outward on side $AB$ is $O$. How should the angle $ACB$ be chosen so that the sum of the distances $OM$ and $ON$ is as large as possible?
Solution. Let the sides of triangle $ABC$ be denoted by $a, b, c$, and its angles by $\alpha, \beta, \gamma$. Let the midpoint of side $AB$ be denoted by $F$. Construct squares outward on sides $BC$ and $CA$ of the triangle, and let the centers of these squares be denoted by $O_{1}, O_{2}$.

![](https://cdn.mathpix.com/cropped/2024_05_02_0632420c71274e77e064g-1.jpg?height=694&width=596&top_left_y=274&top_left_x=754)

We use the fact that the midlines of a triangle are parallel to the sides and half as long, and that connecting the midpoint of one side of a square to its center results in a segment perpendicular to that side and half as long. Therefore,

\[
\begin{aligned}
& \angle NFB = \angle CMN = \angle CAB = \alpha, \\
& \angle AFM = \angle MNC = \angle ABC = \beta, \\
& \angle NFO = \angle O_{2}MN = 90^\circ + \alpha, \\
& \angle MFO = \angle O_{1}NM = 90^\circ + \beta.
\end{aligned}
\]

Thus, triangles $ONF$ and $NO_{2}M$, as well as triangles $OFM$ and $O_{1}NM$, are congruent because two sides and the included angle of each pair are equal.

As a result of the congruence, $ON = NO_{2} = x$ and $OM = MO_{1} = y$. The diagonal of a square forms a $45^\circ$ angle with the side, so for $0^\circ < \gamma \leq 135^\circ$,

\[
\angle NCO_{2} = \angle MCO_{1} = \gamma + 45^\circ,
\]

and for $135^\circ < \gamma < 180^\circ$,

\[
\angle NCO_{2} = \angle MCO_{1} = 360^\circ - (\gamma + 45^\circ).
\]

Using the fact that half the diagonal of a square is $\frac{\sqrt{2}}{2}$ times the side length:

\[
CN = \frac{a}{2}, \quad CM = \frac{b}{2}, \quad CO_{1} = \frac{a \sqrt{2}}{2}, \quad CO_{2} = \frac{b \sqrt{2}}{2}
\]

Furthermore, by the identity $\cos \gamma = \cos (360^\circ - \gamma)$, the cosine rule can be uniformly written for triangles $CMO_{1}$ and $CNO_{2}$, or degenerate triangles, as follows:

\[
\begin{aligned}
& y^{2} = \left(\frac{b}{2}\right)^{2} + \left(\frac{a \sqrt{2}}{2}\right)^{2} - 2 \cdot \frac{b}{2} \cdot \frac{a \sqrt{2}}{2} \cos (\gamma - 45^\circ) \\
& x^{2} = \left(\frac{a}{2}\right)^{2} + \left(\frac{b \sqrt{2}}{2}\right)^{2} - 2 \cdot \frac{a}{2} \cdot \frac{b \sqrt{2}}{2} \cos (\gamma - 45^\circ)
\end{aligned}
\]

Given that $a$ and $b$ are constants, the condition for the maximum of $x^{2}$ and $y^{2}$, and consequently of $x$ and $y$, is that $\cos (\gamma + 45^\circ) = -1$, i.e., $\gamma + 45^\circ = 180^\circ$, or $\gamma = 135^\circ$.

In this case,

\[
x^{2} = \left(\frac{a}{2} + \frac{b \sqrt{2}}{2}\right)^{2}, \quad y^{2} = \left(\frac{b}{2} + \frac{a \sqrt{2}}{2}\right)^{2}
\]

Thus,

\[
x = \frac{a}{2} + \frac{b \sqrt{2}}{2} \quad \text{and} \quad y = \frac{b}{2} + \frac{a \sqrt{2}}{2}.
\]

Their sum is:

\[
x + y = \frac{(a + b)(1 + \sqrt{2})}{2}
\]

Therefore, choosing $\angle ACB = 135^\circ$, the maximum of the sum of distances $OM$ and $ON$ is

\[
\frac{(AC + BC)(1 + \sqrt{2})}{2}
\]