3A. Let $a_{1}, a_{2}, \ldots$ be an arithmetic progression with difference $d$. Calculate

$$
S_{n}=a_{1}^{2}+a_{4}^{2}+a_{7}^{2}+\ldots+a_{3 n-2}^{2}-a_{2}^{2}-a_{5}^{2}-\ldots-a_{3 n-1}^{2}
$$

i.e., express $S_{n}$ in terms of $a_{1}, d$, and $n$.
Solution. We have

$$
\begin{aligned}
S_{n} & =a_{1}^{2}+a_{4}^{2}+a_{7}^{2}+\ldots+a_{3 n-2}^{2}-a_{2}^{2}-a_{5}^{2}-a_{8}^{2}-\ldots-a_{3 n-1}^{2} \\
& =a_{1}^{2}-a_{2}^{2}+a_{4}^{2}-a_{5}^{2}+\ldots+a_{3 n-2}^{2}-a_{3 n-1}^{2} \\
& =\left(a_{1}-a_{2}\right)\left(a_{1}+a_{2}\right)+\left(a_{4}-a_{5}\right)\left(a_{4}+a_{5}\right)+\ldots+\left(a_{3 n-2}-a_{3 n-1}\right)\left(a_{3 n-2}+a_{3 n-1}\right) \\
& =-d\left(a_{1}+a_{2}+a_{4}+a_{5}+\ldots+a_{3 n-2}+a_{3 n-1}\right) \\
& =-d\left(a_{1}+a_{4}+a_{7}+\ldots+a_{3 n-2}+a_{2}+a_{5}+\ldots+a_{3 n-1}\right) \\
& =-d\left[\left(2 a_{1}+(n-1) 3 d\right) \cdot \frac{n}{2}+\left(2 a_{2}+(n-1) 3 d\right) \cdot \frac{n}{2}\right]=-d n\left(2 a_{1}+(3 n-2) d\right)
\end{aligned}
$$