9. (16 points) Given the integer sequence $\left\{a_{i}\right\}$ defined as follows:
$$
a_{i}=\left\{\begin{array}{ll}
i, & 1 \leqslant i \leqslant 5 ; \\
a_{1} a_{2} \cdots a_{i-1}-1, & i>5 .
\end{array}\right.
$$

Find the value of $\sum_{i=1}^{2019} a_{i}^{2}-a_{1} a_{2} \cdots a_{2019}$.
For any $i \geqslant 6$, we have
$$
\begin{array}{l}
a_{i}=a_{1} a_{2} \cdots a_{i-1}-1 . \\
\text { Then } a_{i+1}=a_{1} a_{2} \cdots a_{i}-1 \\
=\left(a_{1} a_{2} \cdots a_{i-1}\right) a_{i}-1 \\
=\left(a_{i}+1\right) a_{i}-1 \\
=a_{i}^{2}+a_{i}-1 .
\end{array}
$$

Thus, for any $i \geqslant 6$, we have
$$
\begin{array}{l}
a_{i}^{2}=a_{i+1}-a_{i}+1 . \\
\text { Therefore } \sum_{i=1}^{2019} a_{i}^{2}-a_{1} a_{2} \cdots a_{2019} \\
=\sum_{i=1}^{5} a_{i}^{2}+\sum_{i=6}^{2019} a_{i}^{2}-\left(a_{2020}+1\right) \\
=\sum_{i=1}^{5} i^{2}+\sum_{i=6}^{2019}\left(a_{i+1}-a_{i}+1\right)-\left(a_{2020}+1\right) \\
=55+\left(a_{2020}-a_{6}+2014\right)-a_{2020}-1 \\
=2068-a_{6}=1949 .
\end{array}
$$