prove the maximum of $\sum_{1\leq r
Let n be a positive integer. Prove that the maximum possible value of $Z =\sum_{1\leq r<s\leq 2n}(s-r-n)x_rx_s$, where $-1\leq x_i\leq 1$ for all i, is attained when $x_i\in \{-1,1\}\,\forall i$.
I know that $Z$ is linear in the $x_i$'s, but I can't seem to justify why the maximum is attained at boundary points. Finding the contribution of the sum by one particular $x_i$ doesn't seem very useful either.
 A: Suppose $Z$ attains the maximum value when $(x_1, x_2, \cdots, x_n)=(t_1, t_2, \cdots, t_n)\in [-1,1]^n$.
Fix an index $i$ between $1$ and $n$.
Consider the function of one variable $x_i$, $Z_i(x_i)=Z(x_1, x_2, \cdots, x_n)|_{x_j=t_i\text{ for all j}\not=i}$. More specifically,
$$\begin{aligned}
Z_i(x_i)&=\sum_{1\leq r<s\leq 2n, r\not=i, s\not=i}(s-r-n)t_rt_s 
+ \sum_{i<s\leq 2n}(s-i-n)x_it_s 
+ \sum_{1\leq r<i}(i-r-n)t_rx_i\\
&=b_i
+ c_ix_i\\
\end{aligned}$$
where $$b_i=\sum_{1\leq r<s\leq 2n, r\not=i, s\not=i}(s-r-n)t_rt_s $$ and $$c_i=\sum_{i<s\leq 2n}(s-i-n)t_s 
+ \sum_{1\leq r<i}(i-r-n)t_r$$ are constants. Since $Z_i(x_i)$ is a linear function of $x_i$, either $Z_i(-1)$ or $Z_i(1)$ will attain its maximum value for $x_i\in[-1,1]$. (If $c_i\not=0$, then $Z_i(x_i)$ cannot attain its maximum value when $x_i\not\in\{1,-1\}$. We do not need this finer fact, though.) Hence $Z$ can attain its maximum value when $x_i\in\{-1,1\}$. We can replace $t_i$ with $1$ or $-1$ respectively.
We can run the replacement above successively for $i$ from $1$ to $n$. We see that $Z$ can attain its maximum value when $x_i\in \{-1,1\}$ for all $i$.
