Solution (source code)

= Solution

The <Lagrangian> is
$$
L=\frac m2(\dot y_1^2+\dot y_3^2)+\frac M2\dot y_2^2
-\frac k2\left[(y_1-y_2)^2+(y_2-y_3)^2\right]
-g(my_1+M y_2+my_3).
$$
Writing $T=2m+M$, the center of mass is
$$
Y=\frac{my_1+M y_2+my_3}{T}.
$$
All internal forces cancel, so $\ddot Y=-g$ and
$$
Y(t)=A+\dot Y(0)t-\frac12gt^2.
$$
If the molecule is released from rest, the middle term vanishes.