Each of the numbers $a_1 ,a_2,\dots,a_n$ is $1$ or $−1$, and we have $$S=a_1a_2a_3a_4+a_2a_3a_4a_5 +\dots+ a_na_1a_2a_3=0$$ Prove that $4 \mid n$.
If we replace any $a_i$ by $−a_i$ , then $S$ does not change $\mod\, 4$ since four cyclically adjacent terms change their sign. Indeed, if two of these terms are positive and two negative, nothing changes. If one or three have the same sign, $S$ changes by $\pm 4$. Finally, if all four are of the same sign, then $S$ changes by $\pm $8. Initially, we have $S_0$ which implies $S \equiv 0 \pmod 4$. Now, step-by-step, we change each negative sign into a positive sign. This does not change $S \mod\, 4$.
At the end, we still have $S \equiv 0 \pmod 4$, but also $S =n$, i.e, $4|n$. This is the solution . Can somebody explain the last part ,where we change sign and how in the end $S=n$.