Problems 1731–1740

Q1732 Suppose that the numbers $a_1,a_2,\ldots,a_n$ are equal to $1,2,\ldots,n$, but not necessarily in that order. Find the maximum possible value of

$\displaystyle S = \sum_{k=1}^n (k-a_k)^2$

and the values of the numbers $a_k$ which give this maximum.