In the figure below, you see three half-circles. The circle \( C \) is tangent to two of the half-circles and to the line \( P Q \) perpendicular to the diameter \( A B \). The area of the shaded region is \( 39 \pi \), and the area of the circle \( C \) is \( 9 \pi \). Find the length of the diameter \( A B \).

![](https://cdn.mathpix.com/cropped/2024_04_17_e2580b6720254e51741dg-1.jpg?height=288&width=500&top_left_y=1084&top_left_x=824)

Figure 1
Let $r$ and $s$ be the radii of the half-circles with diameters $A P$ and $B P$. Then we have

$$
39 \pi=\frac{\pi}{2}\left((r+s)^{2}-r^{2}-s^{2}\right)-9 \pi
$$

hence $r s=48$. Let $M$ be the midpoint of the diameter $A B$, $N$ be the midpoint of $P B$, $O$ be the centre of the circle $C$, and let $F$ be the orthogonal projection of $O$ on $A B$. Since the radius of $C$ is 3, we have $|M O|=r+s-3$, $|M F|=r-s+3$, $|O N|=s+3$, and $|F N|=s-3$.

Applying the Pythagorean theorem to the triangles $M F O$ and $N F O$ yields

$$
(r+s-3)^{2}-(r-s+3)^{2}=|O F|^{2}=(s+3)^{2}-(s-3)^{2},
$$

which implies $r(s-3)=3 s$, so that $3(r+s)=r s=48$. Hence $|A B|=2(r+s)=32$.