Problem: Let $n$ be a positive integer and
let $x_1 \le x_2 \le \dots \le x_n$ be real numbers.
Prove that
\[ \left(\sum_{i=1}^{n}\sum_{j=1}^{n} |x_i - x_j|\right)^2
  \le \frac{2(n^2-1)}{3}\sum_{i=1}^{n}\sum_{j=1}^{n} (x_i - x_j)^2 \]
with equality if and only if $x_1$, $x_2$, \dots, $x_n$
form an arithmetic sequence.

Solution: Let $d_1 = x_2 - x_1$, \dots, $d_{n-1} = x_n - x_{n-1}$.
The inequality in question becomes:
\[
  \left( \sum_i i(n-i) d_i \right)^2
  \le
  \frac{n^2-1}{3} \cdot
  \left( \sum_i i(n-i) d_i^2 + 2\sum_{i<j} i(n-j) d_i d_j  \right).
\]
Clearing the square on the right-hand side we want to show
\[
  \sum_{i<j} \left( 3ij(n-i)(n-j) - (n^2-1)i(n-j) \right) \cdot 2d_i d_j
  \le \sum_i (n^2-1-3i(n-i)) \cdot i(n-i) d_i^2.
\]
We use AM-GM directly on $2d_i d_j \le d_i^2 + d_j^2$:
this actually solves the problem.
The annoying part is to check that the coefficients actually match:
\begin{claim*}
  [Big bash]
  For an index $1 \le k \le n-1$, we have
  \begin{align*}
    &\sum_{i<k} \left( 3ik(n-i)(n-k) - (n^2-1)i(n-k) \right) \\
    +& \sum_{j>k} \left( 3kj(n-k)(n-j) - (n^2-1)k(n-j) \right) \\
    = & (n^2-1-3k(n-k)) \cdot k(n-k).
  \end{align*}
\end{claim*}
\begin{proof}
  Rewrite as:
  \begin{align*}
    3k(n-k) \left( -k(n-k) + \sum_i i(n-i) \right)
      &= (n^2-1)\left( (n-k)\sum_{i<k} i + k\sum_{j>k} (n-j) \right) \\
      &+ (n^2-1-3k(n-k)) \cdot k(n-k) \\
    \iff 3k(n-k) \sum_i i(n-i)
      &= (n^2-1) \left( (n-k)\sum_{i<k} i + k\sum_{j>k}(n-j) \right) \\
      &+ (n^2-1)k(n-k) - 3k^2(n-k)^2 \\
    \iff 3k(n-k) \left( \sum_{i} i(n-i) \right)
      &= (n^2-1) \left( (n-k)\sum_{i \le k} i + k \sum_{i < n-k} i \right) \\
    \iff 3k(n-k) \frac{(n-1)n(n+1)}{6}
      &= (n^2-1) \left( (n-k)\frac{k(k+1)}{2} \right) \\
      & + (n^2-1) \left( k \frac{(n-k)(n-k-1)}{2} \right) \\
    \iff 3k(n-k) \frac{(n-1)n(n+1)}{6}
      &= (n^2-1)k(n-k) \cdot \frac n2
  \end{align*}
  which is visibly true.
\end{proof}
Equality occurs only if all $d_i$ are equal
because the coefficient of $d_i d_j$ is nonzero
for any $i \le n/2$ and $j \ge n/2$.