4. Given the sequence $\left\{a_{n}\right\}(n \geqslant 1)$ with the general term formula
$$
a_{n}=\frac{(n+1)^{4}+n^{4}+1}{(n+1)^{2}+n^{2}+1} \text {. }
$$

Then the sum of the first $n$ terms is $\qquad$
4. $\frac{n^{3}+3 n+5}{3}$.

From $a_{n}=\frac{(n+1)^{4}+n^{4}+1}{(n+1)^{2}+n^{2}+1}=n^{2}+n+1$, we get $S_{n}=\frac{n(n+1)(2 n+1)}{6}+\frac{n(n+1)}{2}+n$ $=\frac{n^{3}+3 n+5}{3}$.