8. Consider all three-element subsets $\{a, b, c\}$ of the set $\{1,2, \cdots, n\}$, where $a<b<c$, and call $b$ the middle element. Then the sum of all middle elements $S(n)=$ $\qquad$
8. $\frac{(n-2)(n-1) n(n+1)}{12}$.

Obviously, $b \in\{2,3, \cdots, n-1\}$, the number of three-element subsets with $b$ as the middle element is $(b-1)(n-b)$.
$$
\begin{array}{l} 
\text { Then } S(n)=\sum_{b=2}^{n-1}(b-1)(n-b) b \\
\Rightarrow 2 S(n)=\sum_{b=2}^{n-1}(b-1)(n-b) b+ \\
=\sum_{b=2}^{2}((b-1)(n-b) b+ \\
\quad(n-b)(b-1)(n+1-b)) \\
=(n+1) \sum_{b=2}^{n-1}(b-1)(n-b) \\
=(n+1)\left(n \sum_{b=2}^{n-1}(b-1)-\sum_{b=2}^{n-1}(b-1) b\right) \\
= \frac{1}{6}(n-2)(n-1) n(n+1) .
\end{array}
$$