How is this a number theoretical problem? It should belong to either the Algebra or the Inequalities forum.
Fixed. Sorry about that.
Consider $\sum_{i=1}^n \left(x_i+4\right)\left(x_i-2\right)\left(x_i-1\right)^2$. This sum has to be nonpositive (according to to the condition that all the $x_i$'s belong to $[-4,2]$). Therefore, we have \[34n+18n \leq \sum_{i=1}^n x_i^4 + 18 \sum_{i=1}^nx_i \leq 11\sum_{i=1}^n x_i^2 + 8n \leq 11(4n)+8n\,.\] However, the above expression is indeed an equality. Therefore,
(1) $\sum_{i=1}^n x_i = n$,
(2) $\sum_{i=1}^n x_i^2 = 4n$,
(3) $\sum_{i=1}^n x_i^4 = 34n$, and
(4) $x_i \in \{-4,1,2\}$ for every $i=1,2,\ldots,n$.
If there are $p$ terms equaling $-4$, $q$ terms equaling $1$, and $r$ terms equaling $2$, then
(A) $-4p+q+2r=n$,
(B) $16p+q+4r=4n$, and
(C) $256p+q+16r=34n$.
Solving this system of equations, we obtain $p=\frac{n}{10}$, $q=\frac{2n}{5}$, and $r=\frac{n}{2}$. Consequently, $10 \mid n$ is the necessary and sufficient condition.