8. Let $n$ be a given positive integer, and the sum $\sum_{1 \leqslant i<j \leqslant n}\left|x_{i}-x_{j}\right|=\left|x_{1}-x_{2}\right|+\left|x_{1}-x_{3}\right|+\cdots+$ $\left|x_{1}-x_{n}\right|+\left|x_{2}-x_{3}\right|+\left|x_{2}-x_{4}\right|+\cdots+\left|x_{2}-x_{n}\right|+\left|x_{n-2}-x_{n}\right|+\left|x_{n-2}-x_{n}\right|+$ $\left|x_{n-1}-x_{n}\right|$, where $0 \leqslant x_{i} \leqslant 1, i=1,2, \cdots, n$. Let $S(n)$ denote the maximum possible value of the sum. Find $S(n)$. (1974 Canadian Mathematical Olympiad)
8. Let $0 \leqslant x_{1} \leqslant x_{2} \leqslant \cdots \leqslant x_{n} \leqslant 1$. Let $S=\sum_{i \leqslant i<j \leqslant n}\left|x_{i}-x_{j}\right|=\sum_{1 \leqslant i<j \leqslant n}\left(x_{j}-\right.$ $\left.x_{i}\right)$.
This sum has $\mathrm{C}_{n}^{2}$ terms. Each $x_{k}$ appears in $n-1$ terms $(1 \leqslant k \leqslant n)$, which are
$$x_{k}-x_{1}, x_{k}-x_{2}, \cdots, x_{k}-x_{k-1}, x_{k-1}-x_{k}, \cdots, x_{n}-x_{k}$$

Therefore,
$$S=\sum_{k=1}^{n}\left[(k-1) x_{k}-(n-k) x_{k}\right]=\sum_{k=1}^{n}\left[x_{k}(2 k-n-1)\right]$$

When $k<\frac{n+1}{2}$, $2 k-n-1<0$, so,
$$S \leqslant \sum_{k \geqslant \frac{n+1}{2}}^{n}\left[x_{k}(2 k-n-1)\right]$$

When $n$ is even,
$$\begin{aligned}
S \leqslant & \sum_{k \leqslant \frac{n}{2}+1}^{n}\left[x_{k}(2 k-n-1)\right] \leqslant \sum_{k=\frac{n}{2}+1}^{n}(2 k-n-1)= \\
& 1+3+5+\cdots+(n-1)=\frac{n^{2}}{4}
\end{aligned}$$

When $n$ is odd,
$$\begin{array}{l}
S \leqslant \sum_{k=\frac{n+1}{2}}\left[x_{k}(2 k-n-1)\right] \leqslant \sum_{k=\frac{n+1}{2}}^{n}(2 k-n-1)= \\
\quad 2+4+6+\cdots+(n-1)=\frac{n^{2}-1}{4}
\end{array}$$

In summary, $S \leqslant\left[\frac{n^{2}}{4}\right]$.
On the other hand, if $n$ is even, we can take $x_{1}=x_{2}=\cdots=x_{\frac{n}{2}}=0, x_{\frac{n}{2}+1}=$ $x_{\frac{n}{2}+2}=\cdots=x_{n}=1$, making $S=\frac{n^{2}}{4}$.

If $n$ is odd, we can take $x_{1}=x_{2}=\cdots=x_{\frac{n-1}{2}}=0, x_{\frac{n+1}{2}}=x_{\frac{n+3}{2}}=\cdots=x_{n}=1$, making $S$ $=\frac{n^{2}-1}{4}$

Therefore, whether $n$ is even or $n$ is odd, we always have $S(n)=\left[\frac{n^{2}}{4}\right]$.