3. Given the sequence $\left\{a_{n}\right\}$ satisfies
$$
a_{1}=0,\left|a_{n+1}\right|=\left|a_{n}-2\right| \text {. }
$$

Let the sum of the first 2016 terms of the sequence $\left\{a_{n}\right\}$ be $S$. Then the maximum value of $S$ is $\qquad$
3.2016 .
$$
\begin{array}{l}
\text { Given } \left|a_{k+1}\right|=\left|a_{k}-2\right| \\
\Rightarrow a_{k+1}^{2}=a_{k}^{2}-4 a_{k}+4(k=1,2, \cdots, 2016) .
\end{array}
$$

Summing up, we get $a_{2017}^{2}=a_{1}^{2}-4 S+4 \times 2016 \geqslant 0$.
Therefore, $S \leqslant 2016$.
When $k$ is odd, $a_{k}=0$;
When $k$ is even, $a_{k}=2$, in this case the equality can be achieved.