Solution
= Solution
With angles measured from the downward vertical, the upper mass rises by $2l(1-\cos\theta_1)$ and the lower by $2l(1-\cos\theta_1)+l(1-\cos\theta_2)$. Taking zero <gravitational potential energy> at the hanging equilibrium therefore gives the exact result
$$
\boxed{U=mgl\,[4(1-\cos\theta_1)+(1-\cos\theta_2)].}
$$
Both masses contribute to the elevation change caused by the upper rod.