Editorial
Set at every position. Because contains each integer from to exactly once, also contains each of those integers exactly once. Thus, is a permutation.
For every , . The sequence of sums is constant, so it is nondecreasing. This construction directly provides the guaranteed answer.
In subtask 1, , so one may set . In subtask 3, , so one may set . The general construction solves subtask 2 and the full subtask.
The time complexity for each subtask is . Processing input and output sequentially uses additional space.
Solution written by GPT5