Divide and Sum
HardRating 1900CodeforcesCombinatorics & Modular Arithmetic
Approach hintTry it first, then revealHide
Try small cases: after sorting, every pair matches one element of the larger half with one element of the smaller half. The cost is therefore identical for every partition, so multiply it by the number of partitions.