They just wanted to simplify the summations, so they made all of them go from 3 to n-2,
hence they expanded out whatever terms were left over, so for the first summation, they expanded out k=1 and k=2 which gives the 4 + 2 at the front.
the summations magically cancelled out which was lucky though.
This is just like writing
sum(k^2,k=1..N-1) = 1 + 2^2 + ... + (N-2)^2 + (N-1)^2
= 1 +4+ (N-1)^2 + sum(k^2,k=3..N-2)
As TS said, when you put all the sums to be over the same k's so you can combine them, you get several terms left over.
because it was the biggest range that all of the summations had.
you could choose k=4...N-3, but then you'd be wasting some time expanding out parts that you didn't need to.