Count the triplets $(x, y, z)$ of $\{1,2, \cdots, n+1\}$ that satisfy $z>\max \{x, y\}$.
We count $T$ as the number of triplets. For each $z \in\{1,2, \cdots, n+1\}$ there are $(z-1)^{2}$ pairs $(x, y)$ satisfying $x, y<z$. Therefore,

$$
T=\sum_{z=1}^{n+1}(z-1)^{2}=1+2^{2}+\cdots+n^{2}
$$

We count $T$ in another way. There are

$-\binom{n+1}{2}$ triplets such that $x=y<z$

$-\binom{n+1}{3}$ triplets corresponding to $x<y<z$,

$-\binom{n+1}{3}$ triplets corresponding to $y<x<z$,

From this, we deduce that

$$
T=2\binom{n+1}{3}+\binom{n+1}{2}=\frac{(n+1) n(n-1)}{3}+\frac{(n+1) n}{2}=\frac{(n+1) n(2 n+1)}{6}
$$

and we deduce the well-known formula

$$
1+2^{2}+\cdots+n^{2}=\frac{n(n+1)(2 n+1)}{6}
$$