Solution (source code)

= Solution

An adiabatic invariant remains constant to leading order when a system parameter changes on a timescale much longer than one period. For a periodic one-degree-of-freedom system, the <adiabatic invariance of the action> supplies such an invariant.

The momentum magnitude between collisions is $p_0=\sqrt{2mE}$. A complete orbit crosses the gap once in each direction, so the unnormalized action used in the question is
$$
\boxed{I=\oint p\,dq=2Lp_0=2L\sqrt{2mE}.}
$$
Consequently
$$
\frac{dI}{dE}=\frac{2Lm}{\sqrt{2mE}}
=\frac{2L}{\sqrt{2E/m}}=T,
$$
because the speed is $\sqrt{2E/m}$ and the round-trip distance is $2L$.

When $L(t)$ varies adiabatically, conservation of the <adiabatic particle between moving parallel walls> action gives
$$
\boxed{E(t)=E(0)\left(\frac{L(0)}{L(t)}\right)^2.}
$$
A moving wall does work at each collision: an approaching wall raises the particle's energy and a receding wall lowers it. Elasticity holds in the instantaneous rest frame of the wall.