12. Given the function $f(x)=x^{2}-2 \ln x$, if there exist $x_{1}, x_{2}, \cdots, x_{n} \in\left[\frac{1}{\mathrm{e}}, \mathrm{e}\right]$, such that $f\left(x_{1}\right)+f\left(x_{2}\right)+\cdots+f\left(x_{n-1}\right)=f\left(x_{n}\right)$ holds, find the maximum value of $n$.
Solve
$f^{\prime}(x)=2 x-\frac{2}{x}=\frac{2(x+1)(x-1)}{x}$, then $f(x)$ is monotonically decreasing on $\left(\frac{1}{\mathrm{e}}, 1\right)$ and monotonically increasing on $(1, \mathrm{e})$, so $f(x)_{\min }=f(1)=1, f(x)_{\max }=\max \left\{f\left(\frac{1}{\mathrm{e}}\right), f(\mathrm{e})\right\}=\mathrm{e}^{2}-2$.
Then $(n-1) f(1) \leqslant f\left(x_{1}\right)+f\left(x_{2}\right)+\cdots+f\left(x_{n-1}\right)=f\left(x_{n}\right) \leqslant f(\mathrm{e})$ $\Rightarrow n-1 \leqslant \mathrm{e}^{2}-2 \Rightarrow n \leqslant \mathrm{e}^{2}-1<6.4 \Rightarrow n \leqslant 6$. Therefore, the maximum value of $n$ is 6.