6 Let $x_{1}, x_{2}, \cdots, x_{n}$ be $n$ non-negative real numbers $\left(n>2, n \in \mathbf{N}^{*}\right)$, and
$$\sum_{i=1}^{n} x_{i}=n, \sum_{i=1}^{n} i x_{i}=2 n-2 .$$

Find the maximum value of $x_{1}+4 x_{2}+\cdots+n^{2} x_{n}$.
6. Let $y_{i}=\sum_{j=i}^{n} x_{j}$, then $y_{1}=n, \sum_{i=1}^{n} y_{i}=2 n-2$, hence $S=\sum_{k=1}^{n} k^{2} x_{k}=\sum_{k=1}^{n} k^{2}$ $\left(y_{k}-y_{k+1}\right)+n^{2} y_{n}=\sum_{k=1}^{n}(2 k-1) y_{k}$.

Since $y_{1}=n, y_{2} \geqslant y_{3} \geqslant \cdots \geqslant y_{n}$, if there exists $i \in\{2,3, \cdots, n-1\}$, such that $y_{i}>y_{n}$ (denote $i$ as the largest index for which $y_{i}>y_{n}$ holds). Because
$$\begin{aligned}
& (2 i-1) y_{i}+(2 i+1+\cdots+2 n-1) y_{n} \\
&= (2 i-1) y_{n} + (2 i+1+\cdots+2 n-1) y_{n} + (2 i-1)(y_{i} - y_{n}).
\end{aligned}$$

Thus, under the condition of keeping $y_{i}+y_{i+1}+\cdots+y_{n}$ unchanged, replacing them with their average value will increase $S$.

Therefore, when $y_{2}=y_{3}=\cdots=y_{n}$, $S_{\text {max }}=n^{2}-2$.