I was going over a question and need your opinion about solution of the sum of the absolute values as
$$S_n = |0-a|+|1-a|+|2-a|+ \dots + |(n-1)-a|+|n-a|$$
where a is a constant term. What could be the general sum of this series?
The general sum of the series, assuming $a$ is real, is easily expressed in terms of the auxiliary function $s(n,a) := \sum_{k=0}^n (n-a) = (n+1)(\frac n2 - a)$. Then $$ S_n = \begin{cases} s(n,a) - 2s(\lfloor a \rfloor, a), & 0 < a< n; \\ s(n,a), & 0 \ge a; \\ -s(n,a), & a \ge n. \end{cases}$$