Let be the initial sortedness and the number of strict inversions. Swapping an adjacent inversion increases sortedness by one. If , perform insertion-sort swaps to attain . Otherwise sort first. If duplicates exist, repeatedly swap an adjacent equal pair for the remaining operations. If all elements differ, spend pairs of operations swapping the same position twice; an odd remainder loses one unit of sortedness. Permutation parity makes this loss unavoidable.
Time is and sortedness is at most . The small subtask can enumerate operation sequences with score updates per swap. The checker requires exactly valid indices and awards only for a correct optimum with a nonoptimal, properly formatted witness.