5. Let the set of all permutations $X=(x_{1}, x_{2}, \cdots, x_{9})$ of $1,2, \cdots, 9$ be $A$. For any $X \in A$, let
\[
\begin{array}{l}
f(X)=x_{1}+2 x_{2}+\cdots+9 x_{9}, \\
M=\{f(X) \mid X \in A\} .
\end{array}
\]

Find $|M|$ (where $|M|$ denotes the number of elements in the set $M$).
(Xiong Bin)
5. Generally prove: when $n \geqslant 4$, for all permutations $X_{n}=\left(x_{1}, x_{2}, \cdots, x_{n}\right)$ of the first $n$ positive integers $1,2, \cdots, n$, if
$$
\begin{array}{l}
f\left(X_{n}\right)=x_{1}+2 x_{2}+\cdots+n x_{n}, \\
M_{n}=\{f(X)|X \in A|,
\end{array}
$$
$$
\text { then }\left|M_{n}\right|=\frac{n^{3}-n+6}{6} \text {. }
$$

Below, we prove using mathematical induction:
$$
\begin{aligned}
M_{n}= & \left\{\frac{n(n+1)(n+2)}{6}, \frac{n(n+1)(n+2)}{6}+1,\right. \\
& \left.\cdots, \frac{n(n+1)(2 n+1)}{6}\right\} .
\end{aligned}
$$

When $n=4$, by the rearrangement inequality, the smallest element in set $M$ is $f(\{4,3,2,1\})=20$, and the largest element is $f(\{1,2,3,4\})=30$.
$$
\begin{array}{l}
\text { Also, } f(\{3,4,2,1\})=21, f(\{3,4,1,2\})=22, \\
f(\{4,2,1,3\})=23, f(\{2,3,4,1\})=24, \\
f(\{2,4,1,3\})=25, f(\{1,4,3,2\})=26, \\
f(\{1,4,2,3\})=27, f(\{2,1,4,3\})=28, \\
f(\{1,2,4,3\})=29,
\end{array}
$$

then $\left|M_{4}\right|=\{20,21, \cdots, 30\}$ has $11=\frac{4^{3}-4+6}{6}$ elements. $\square$
Therefore, the proposition holds for $n=4$.
Assume the proposition holds for $n-1(n \geqslant 5)$. Consider the case for $n$.

For any permutation $X_{n-1}=\left(x_{1}, x_{2}, \cdots, x_{n-1}\right)$ of $1,2, \cdots, n-1$, always take $x_{n}=n$, to get a permutation $x_{1}, x_{2}, \cdots, x_{n-1}, n$ of $1,2, \cdots, n$. Then
$$
\sum_{k=1}^{n} k x_{k}=n^{2}+\sum_{k=1}^{n-1} k x_{k} \text {. }
$$

By the induction hypothesis, at this point, $\sum_{k=1}^{n} k x_{k}$ takes all integers in the interval
$$
\begin{array}{l}
{\left[n^{2}+\frac{(n-1) n(n+1)}{6}, n^{2}+\frac{(n-1) n(2 n-1)}{6}\right]} \\
=\left[\frac{n\left(n^{2}+5\right)}{6}, \frac{n(n+1)(2 n+1)}{6}\right]
\end{array}
$$

Let $x_{n}=1$. Then
$$
\begin{array}{l}
\sum_{k=1}^{n} k x_{k}=n+\sum_{k=1}^{n-1} k x_{k} \\
=n+\sum_{k=1}^{n-1} k\left(x_{k}-1\right)+\frac{n(n-1)}{2} \\
=\frac{n(n+1)}{2}+\sum_{k=1}^{n-1} k\left(x_{k}-1\right) .
\end{array}
$$

By the induction hypothesis, $\sum_{k=1}^{n} k x_{k}$ takes all integers in the interval
$$
\begin{array}{l}
{\left[\frac{n(n+1)}{2}+\frac{(n-1) n(n+1)}{6},\right.} \\
\left.\frac{n(n+1)}{2}+\frac{n(n-1)(2 n-1)}{6}\right] \\
=\left[\frac{n(n+1)(n+2)}{6}, \frac{2 n\left(n^{2}+2\right)}{6}\right]
\end{array}
$$

Since $\frac{2 n\left(n^{2}+2\right)}{6} \geqslant \frac{n\left(n^{2}+5\right)}{6}$, $\sum_{k=1}^{n} k x_{k}$
takes all integers in the interval
$$
\left[\frac{n(n+1)(n+2)}{6}, \frac{n(n+1)(2 n+1)}{6}\right]
$$

Thus, the proposition holds for $n$.
By mathematical induction, the proposition is true.
$$
\begin{array}{l}
\text { Also, } \frac{n(n+1)(2 n+1)}{6}-\frac{n(n+1)(n+2)}{6} \\
=\frac{n^{3}-n}{6},
\end{array}
$$

then the number of elements in set $M_{n}$ is $\frac{n^{3}-n+6}{6}$.
In particular, when $n=9$, $|M|=\left|M_{9}\right|=121$.