3. The sequence of positive integers $\left\{a_{n}\right\}$ satisfies: for any $n \in \mathbf{N}_{+}$, $a_{n}+a_{n+1}=2007$, and $31\left(a_{n}^{2}+a_{n} a_{n+1}+a_{n+1}^{2}\right)$. Then the sum of all different values of the sum of the first 2007 terms of the sequence $\left\{a_{n}\right\}$ is $\qquad$.
3. 1345368366 .

From $31\left(a_{n}^{2}+a_{n} a_{n+1}+a_{n+1}^{2}\right)$, we get
$$
31\left[a_{n}^{2}+a_{n+1}\left(a_{n}+a_{n+1}\right)\right] \text {. }
$$

Also, $31\left(a_{n}+a_{n+1}\right)$, so, $31 a_{n}$.
Since $a_{1}=2007-a_{2}<2006$, we have
$$
\begin{array}{l}
a_{1} \leqslant 2004, a_{1}=3 k(k=1,2, \cdots, 668) . \\
\text { Hence } a_{1}+a_{2}+\cdots+a_{2007} \\
=a_{1}+\left(a_{2}+a_{3}\right)+\left(a_{4}+a_{5}\right)+\cdots+\left(a_{200}+a_{2000}\right) \\
=a_{1}+2007 \times 1003 \\
=3 k+2007 \times 1003 .
\end{array}
$$

Therefore, $a_{1}+a_{2}+\cdots+a_{2007}$

Then $S=\sum_{k=1}^{668}(3 k+2007 \times 1003)=1345368366$.