9. (16 points) When $x \in [1,2017]$, find
$$
f(x)=\sum_{i=1}^{2017} i|x-i|
$$

the minimum value.
When $k \leqslant x \leqslant k+1(1 \leqslant k \leqslant 2016)$,
$$
\begin{array}{l}
f(x)=\sum_{i=1}^{k} i(x-i)+\sum_{i=k+1}^{2017} i(i-x) \\
=\left(k^{2}+k-2017 \times 1009\right) x+ \\
\frac{2017 \times 2018 \times 4035}{6}-\frac{k(k+1)(2 k+1)}{3}
\end{array}
$$

is a linear function, and its minimum value is attained at the endpoints of the interval $[k, k+1]$.

Thus, the minimum term of the sequence $\{f(k)\}(1 \leqslant k \leqslant 2016)$ is the desired value.
Notice that,
$$
\begin{array}{l}
f(k+1)>f(k) \\
\Leftrightarrow k^{2}+k-2017 \times 1009>0 \\
\Leftrightarrow k \geqslant 1427 . \\
\text { Hence } f(x)_{\min }=f(1427)=801730806 .
\end{array}
$$