I just wanted to know how we get from the first step to the next. I spent too much time on this but could not get to the next step. This seems a simple sum of squares of odd numbers but was not able to get the next step.
$$ \frac{2 \mathcal{E}_p}{M} \left(1^2 + 3^2 + 5^2 + \dots + (M-1)^2\right) $$ $$ \frac{2 \mathcal{E}_p}{M} \times \frac{M(M^2-1)}{6} $$