Problem (Geometry):
Three non-overlapping squares of positive integer side lengths each have one vertex at the origin and sides parallel to the coordinate axes. Together, the three squares enclose a region whose area is 41 . Compute the largest possible perimeter of the region.

Solution:
Proceed in two steps: first, determine the possible sets of side lengths for the squares; then determine which arrangement of squares produces the largest perimeter. Let the side lengths of the squares be positive integers $m \geq n \geq p$. Then $m^{2}+n^{2}+p^{2}=41$, so $m \leq 6$, and because $3^{2}+3^{2}+3^{2}<41$, it follows that $m>3$. If $m=6$, then $n^{2}+p^{2}=5$, so $n=2$ and $p=1$. If $m=5$, then $n^{2}+p^{2}=16$, which has no positive integral solutions. If $m=4$, then $n^{2}+p^{2}=25$, which is possible if $n=4$ and $p=3$. So the two possible sets of values are $m=6, n=2, p=1$ or $m=4, n=4, p=3$.

First consider $m=6, n=2, p=1$. Moving counterclockwise around the origin, one square is between the other two; by symmetry, it suffices to consider only the three possibilities for this "middle" square. If the middle square is the 6-square, then each of the other two squares has a side that is a subset of a side of the 6 -square. To compute the total perimeter, add the perimeters of the three squares and subtract twice the lengths of the shared segments (because they contribute 0 to the perimeter). Thus the total perimeter is $4 \cdot 6+4 \cdot 2+4 \cdot 1-2 \cdot 2-2 \cdot 1=30$. If the middle square is the 2 -square, then one of its sides is a subset of the 6 -square's side, and one of its sides is a superset of the 1 -square's side, for a total perimeter of $4 \cdot 6+4 \cdot 2+4 \cdot 1-2 \cdot 2-2 \cdot 1=$ 30. But if the middle square is the 1-square, then two of its sides are subsets of the other squares' sides, and the total perimeter is $4 \cdot 6+4 \cdot 2+4 \cdot 1-2 \cdot 1-2 \cdot 1=32$.

If $m=4, n=4$, and $p=3$, similar logic to the foregoing suggests that the maximal perimeter is obtained when the smallest square is between the other two, yielding a total perimeter of $4 \cdot 4+4 \cdot 4+4 \cdot 3-2 \cdot 3-2 \cdot 3=32$. Either of the other two arrangements yields a total perimeter of $4 \cdot 4+4 \cdot 4+4 \cdot 3-2 \cdot 3-2 \cdot 4=30$. So the maximum perimeter is $\mathbf{3 2}$.

Let the side lengths be $a, b$, and $c$, and let $P$ be the perimeter. If the $a \times a$ square is placed in between the other two (going either clockwise or counterclockwise around the origin), then

$$
P=3 b+|b-a|+2 a+|c-a|+3 c \text {. }
$$

To obtain a more symmetric expression, note that for any real numbers $x$ and $y$,

$$
|x-y|=\max \{x, y\}-\min \{x, y\}=x+y-2 \min \{x, y\}
$$

Using this identity,

$$
P=4 a+4 b+4 c-2 \min \{a, b\}-2 \min \{a, c\} .
$$

Thus $P$ is the sum of the perimeters of the three, less twice the overlaps. To maximize $P$, choose $a$ to be the smallest of the three, which leads to $P=4 b+4 c$.



As in the first solution, the two possible sets of values are $c=6, b=2, a=1$ and $c=b=4$, $a=3$.

In the first case, the maximum length of the boundary is $P=4 \cdot 2+4 \cdot 6=32$, and in the second case it is $P=4 \cdot 4+4 \cdot 4=32$. So the maximum perimeter is $\mathbf{3 2}$.

Final answer: 32