5. Solution. It can be regrouped as follows:

$$
\begin{aligned}
(|x-1|+|x+1|+|x-2|+|x+2|+\cdots & +|x-2015|+|x+2015|-4030 x)+ \\
& +(x-a)^{2}+(x-4030+a)^{2}=0
\end{aligned}
$$

The first expression in parentheses is non-negative, and it equals zero if and only if $x \geqslant 2015$. Therefore, the original equation is equivalent to the system

$$
\left\{\begin{array}{l}
x \geqslant 2015 \\
x=a \\
x-4030+a=0
\end{array}\right.
$$

From which, if $a=2015$, then $x=2015$; if $a \neq 2015$, then there are no solutions.
Answer: If $a=2015$, then $x=2015$; if $a \neq 2015$, then there are no solutions. Answer to variant: 7-2: If $c=2014$, then $x=2014$; if $c \neq 2014$, then there are no solutions,