4. Let real numbers $a_{1}, a_{2}, \cdots, a_{40}$ satisfy $\sum_{i=1}^{40} a_{i}=0$, and

for any $i=1,2, \cdots, 40$, we have $\left|a_{i}-a_{i+1}\right| \leqslant 1$ (define $a_{41}=a_{1}$ ).
Find: (1) the maximum value of $a_{10}+a_{20}+a_{30}+a_{40}$;
(2) the maximum value of $a_{10} a_{20}+a_{30} a_{40}$.
(35th China Mathematical Olympiad)
(1) When $a_{10}=a_{20}=a_{30}=a_{40}=\frac{5}{2}$, the maximum value is 10.
(2) When $a_{10}=a_{20}>0, a_{30}=a_{40}<0$, the maximum is achieved.
Consider $a_{10}+a_{20}=x$ and $a_{30}+a_{40}=y$.
By the AM-GM inequality, we only need to find the maximum value of $x^{2}+y^{2}$, which can be transformed into a function problem, and the maximum value can be found to be $\frac{425}{8}$.