Calculate

$$
u_{n}=\sum_{i=1}^{n} \sum_{j=1}^{n} \min (i, j)
$$

Where min is the function that gives the smallest of the two numbers.
We split the second sum into two because

$$
\sum_{j=1}^{n} \min (i, j)=\sum_{j=1}^{i} \min (i, j)+\sum_{j=i+1}^{n} \min (i, j)=\sum_{j=1}^{i} j+\sum_{j=i+1}^{n} i=\frac{i(i+1)}{2}+i \cdot(n-(i+1)+1)
$$

Therefore, we have

$$
\begin{aligned}
u_{n} & =\sum_{i=1}^{n} \sum_{j=1}^{n} \min (i, j)=\sum_{i=1}^{n} \frac{i(i+1)}{2}+i(n-i)=\sum_{i=1}^{n}\left(n+\frac{1}{2}\right) i-\frac{i^{2}}{2} \\
& =\left(n+\frac{1}{2}\right) \frac{n(n+1)}{2}-\frac{n(n+1)(2 n+1)}{12}=\frac{n(n+1)(2 n+1)}{6}
\end{aligned}
$$