Find the number of permutations $x_1, x_2, x_3, x_4, x_5$ of numbers $1, 2, 3, 4, 5$ such that the sum of five products \[ x_1x_2x_3 + x_2x_3x_4 + x_3x_4x_5 + x_4x_5x_1 + x_5x_1x_2 \] is divisible by $3$.
Mod $3$, every product containing $3$ vanishes. If $3$ is at position $i$, the two remaining products are $x_{i+1}x_{i+2}x_{i+3}+x_{i+2}x_{i+3}x_{i+4}=x_{i+2}x_{i+3}(x_{i+1}+x_{i+4})$.
Since $x_{i+2}x_{i+3}\not\equiv0$, we need $x_{i+1}+x_{i+4}\equiv0$: one of them from $\{1,4\}$ and one from $\{2,5\}$, giving $2\cdot2\cdot2=8$ ways, and the other two in $2$ ways.
Find the number of permutations $x_1, x_2, x_3, x_4, x_5, x_6$ of numbers $1, 2, 3, 4, 5, 6$ such that the sum of six products \[ x_1x_2x_3 + x_2x_3x_4 + x_3x_4x_5 + x_4x_5x_6 + x_5x_6x_1 + x_6x_1x_2 \] is divisible by $3$.