8. If $f(x)=\sum_{k=0}^{4034} a_{k} x^{k}$ is the expansion of $\left(x^{2}+x+2\right)^{2017}$, then $\sum_{k=0}^{1344}\left(2 a_{3 k}-a_{3 k+1}-a_{3 k+2}\right)=$ $\qquad$
8. 2 .

Let $x=\omega\left(\omega=-\frac{1}{2}+\frac{\sqrt{3}}{2} \mathrm{i}\right)$. Then
$$
\begin{array}{l}
x^{2}+x+2=1 \\
\Rightarrow \sum_{k=0}^{1344}\left(a_{3 k}+a_{3 k+1} \omega+a_{3 k+2} \omega^{2}\right)=1
\end{array}
$$

Taking the conjugate of the above equation, we get
$$
\sum_{k=0}^{1344}\left(a_{3 k}+a_{3 k+1} \omega^{2}+a_{3 k+2} \omega\right)=1 \text {. }
$$

Adding the two equations, we get
$$
\sum_{k=0}^{1344}\left(2 a_{3 k}-a_{3 k+1}-a_{3 k+2}\right)=2 \text {. }
$$