EditorialIf all values are equal, every rearrangement is sorted. Otherwise sorting in nonincreasing order gives a strict descent and a valid answer. Time is O(NlogN)O(N\log N)O(NlogN). The small subtask can enumerate permutations.