# Minimize $\sum_{i=1}^d {n_i}^2$ when $\sum_{i=1}^d {n_i}$ is fixed.

If we have $d$ integers $n_1, n_2, \ldots, n_d$ whose sum is $n$, how to show that

The minimal value of $\sum_{i=1}^d {n_i}^2$ is achieved when $n_1, n_2, \ldots, n_d$ are as nearly equal as possible.

which is the same to say

The maximal value of $\sum_{i \ne j} n_i \times n_j$ is reached when $n_1, n_2, \ldots, n_d$ are as nearly equal as possible.

-

Assume there exists $i$ and $j$ such that $n_i\geqslant n_j+2$. How to modify $n_i$ and $n_j$ only, to get numbers $(\widehat n_k)_k$ with the same sum as the numbers $(n_k)_k$ but whose squares have a smaller sum?