Example 8 Find the maximum value of $n$ such that there exists an arithmetic sequence $a_{1}, a_{2}, \cdots, a_{n}(n \geqslant 3)$ satisfying
$$
\sum_{i=1}^{n}\left|a_{i}\right|=\sum_{i=1}^{n}\left|a_{i}+1\right|=\sum_{i=1}^{n}\left|a_{i}-2\right|=507 .
$$
(2005, China Southeast Mathematical Olympiad)
【Analysis】Let's assume $a_{i}=a-i d(d>0, i=1,2$, $\cdots, n)$. Then the given system of equations becomes
$$
\left\{\begin{array}{l}
\sum_{i=1}^{n}|a-i d|=507, \\
\sum_{i=1}^{n}|a+1-i d|=507, \\
\sum_{i=1}^{n}|a-2-i d|=507 .
\end{array}\right.
$$

Thus, the absolute value sum function $f(x)=\sum_{i=1}^{n}|x-i d|$ has three "equal value points":
$$
f(a-2)=f(a)=f(a+1)=507,
$$

which implies that $n=2 k\left(k \in \mathbf{Z}_{+}\right)$, and
$$
\begin{array}{l}
\left\{\begin{array}{l}
a-2, a, a+1 \in[k d,(k+1) d], \\
f(k d)=507
\end{array}\right. \\
\Rightarrow\left\{\begin{array}{l}
d \geqslant 3, \\
k^{2} d=507
\end{array}\right. \\
\Rightarrow\left\{\begin{array}{l}
d \geqslant 3, \\
k^{2}=\frac{507}{d} \leqslant \frac{507}{3}=169
\end{array}\right. \\
\Rightarrow\left\{\begin{array}{l}
d \geqslant 3, \\
k \leqslant 13 .
\end{array}\right.
\end{array}
$$

Therefore, $n \leqslant 26$, with equality holding when $d=3, k=13$.
Thus, $a-2=k d=39$, which means $a=41$. The corresponding arithmetic sequence is $\{41-3 k\}(k=1,2, \cdots, 26)$.
Hence, $n_{\max }=26$.
【Note】This example essentially involves the positioning and calculation of the minimum value of the absolute value sum function
$$
f(x)=\sum_{i=1}^{n}|x-i d|
$$