3. Given the sequence $\left\{a_{n}\right\}$ satisfies:
$$
a_{1}=3, a_{n+1}=u_{n}^{2}-(n+1) a_{n}+1 \text {. }
$$

Then the sum of the first $n$ terms of the sequence $\left\{a_{n}\right\}$ is $\qquad$
3. $\frac{n(n+5)}{2}$.

By induction, we can obtain $a_{n}=n+2$. Then we have
$$
a_{n+1}=(n+2)^{2}-(n+1)(n+2)+1=n+3 \text {. }
$$

And $a_{1}=3=1+2$ satisfies the condition. Therefore, $a_{n}=n+2$.
Thus, the sum of the first $n$ terms of the sequence $\left\{a_{n}\right\}$ is
$$
S_{n}=3+4+\cdots+(n+2)=\frac{n(n+5)}{2} \text {. }
$$