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$.
Think of the case that all of $a_i$ are 1. Then obviously $S=n$.
Then change the sign of $a_i$ one by one and examine the change of $S$.
Because each $a_i$ affects 4 terms in $S$, which are from $a_{i-3}a_{i-2}a_{i-1}a_i$ to $a_i a_{i+1}a_{i+2}a_{i+3}$ so sum to even, and the sum of these 4 terms are changed to became the negative of original sum, we know that each change of sign of $a_i$ changes the value of $S$ by a multiple of 4.
So, $n$, the original $S$, experiences sequences of addition with multiples of 4 to become 0, which means $n \equiv 0 $ mod 4.