From Codeforces. Geometry. Solve the geometry problem "Rational Bubble Sort".
Examples
Input:[1,2,3]
Output:0
Input:[2,3,4]
Output:0
Hints
Total sum is invariant. Final sorted array must have all elements = average S/n. Twice the average (2S/n) must be integer for pairwise averaging to work.
Greedy scan: if element equals S/n skip; otherwise pair it with next neighbor and check they sum to 2S/n. If pairing covers whole array, answer Yes.
If pairing fails, check if any split i exists where prefix average < suffix average (strict). That gap lets you sort. No such split = No.
Rational Bubble Sort
**From Codeforces.** Geometry. Solve the geometry problem "Rational Bubble Sort".