12. $[\mathbf{8}]$ A sequence of integers $\left\{a_{i}\right\}$ is defined as follows: $a_{i}=i$ for all $1 \leq i \leq 5$, and $a_{i}=a_{1} a_{2} \cdots a_{i-1}-1$ for all $i>5$. Evaluate $a_{1} a_{2} \cdots a_{2011}-\sum_{i=1}^{2011} a_{i}^{2}$.
Answer: -1941
For all $i \geq 6$, we have $a_{i}=a_{1} a_{2} \cdots a_{i-1}-1$. So
$$
\begin{aligned}
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{aligned}
$$

Therefore, for all $i \geq 6$, we have $a_{i}^{2}=a_{i+1}-a_{i}+1$, and we obtain that
$$
\begin{aligned}
& a_{1} a_{2} \cdots a_{2011}-\sum_{i=1}^{2011} a_{i}^{2} \\
= & a_{2012}+1-\sum_{i=1}^{5} a_{i}^{2}-\sum_{i=6}^{2011} a_{i}^{2} \\
= & a_{2012}+1-\sum_{i=1}^{5} i^{2}-\sum_{i=6}^{2011}\left(a_{i+1}-a_{i}+1\right) \\
= & a_{2012}+1-55-\left(a_{2012}-a_{6}+2006\right) \\
= & a_{6}-2060 \\
= & -1941
\end{aligned}
$$