5. $S=\left(x_{1}+x_{2}+x_{3}+x_{4}\right)^{2}-\sum_{i=1}^{4} x_{i}^{3}-6 \sum_{1 \leqslant i<j<k<4} x_{i} x_{j} x_{k}=3 x_{1}^{2} \left(1-x_{1}\right)+3 x_{2}^{2}\left(1-x_{2}\right)+3 x_{3}^{2}\left(1-x_{3}\right)+3 x_{4}^{2}\left(1-x_{4}\right)$.

Therefore, $S \geqslant 0$, with equality when one of $x_{i} (1 \leqslant i \leqslant 4)$ is 1 and the other three are 0.
Also, $\frac{1}{3} S=x_{1}^{2}\left(1-x_{1}\right)+x_{2}^{2}\left(1-x_{2}\right)+x_{3}^{2}\left(1-x_{3}\right)+x_{4}^{2}\left(1-x_{4}\right)$.
Among $x_{1}+x_{2}$ and $x_{3}+x_{4}$, one must be $\leqslant \frac{2}{3}$, let's assume $x_{1}+x_{2} \leqslant \frac{2}{3}$.
Adjust $S=S\left(x_{1}, x_{2}, x_{3}, x_{4}\right)$ to $S^{\prime}=S\left(x_{1}+x_{2}, 0, x_{3}, x_{4}\right)$.
It is not difficult to prove: $S^{\prime} \geqslant S$, let $S^{\prime}=S\left(x_{1}^{\prime}, x_{2}^{\prime}, x_{3}^{\prime}, 0\right)$. Then $x_{1}^{\prime}+x_{2}^{\prime}+x_{3}^{\prime}=1$. Hence, one of $x_{1}^{\prime}$, $x_{2}^{\prime}, x_{3}^{\prime}$ must be $\geqslant \frac{1}{3}$, let's assume $x_{3}^{\prime} \geqslant \frac{1}{3}$, thus $x_{1}^{\prime}+x_{2}^{\prime} \leqslant \frac{2}{3}$.

Adjust $S^{\prime}=S\left(x_{1}^{\prime}, x_{2}^{\prime}, x_{3}^{\prime}, 0\right)$ to $S^{\prime \prime}=S\left(x_{1}^{\prime}+x_{2}^{\prime}, x_{3}^{\prime}, 0,0\right)$. Similarly, it is easy to prove $S^{\prime \prime} \geqslant S^{\prime}$, where $S^{\prime \prime}=S(a, b, 0,0)$, and $a+b=1$.

Thus, $S^{\prime \prime}=a^{2}(1-a)+b^{2}(1-b)=a b \leqslant \frac{1}{4}$, therefore $S \leqslant 3 S^{\prime \prime} \leqslant \frac{3}{4}$, with equality when $x_{1}=\frac{1}{2}, x_{2}=x_{3}=0, x_{4}=\frac{1}{2}$. Hence, $S \in\left[0, \frac{3}{4}\right]$.
5】 Given $x_{i}$ are non-negative real numbers, $i=1,2,3,4 . x_{1}+x_{2}+x_{3}+x_{4}=1$. Let $S=1-$ $\sum_{i=1}^{4} x_{i}^{3}-6 \sum_{1 \leqslant i<j<k \leqslant 4} x_{i} x_{j} x_{k}$, find the range of $S$.