IMO 1986 LL IRE45

Given n real numbers a1 \leqa2 \leq\cdot \cdot \cdot \leqan, define

IMO 1986 LL IRE45

Origin: IRE

Problem

Given n real numbers a1 \leqa2 \leq\cdot \cdot \cdot \leqan, define M1 = 1 n n  i=1 ai, M2 = n(n −1)  1\leqi<j\leqn aiaj, Q = M 2 1 −M2. Prove that a1 \leqM1 −Q \leqM1 + Q \leqan and that equality holds if and only if a1 = a2 = \cdot \cdot \cdot = an.