#C6243. Sorting with Limited Swaps

    ID: 49982 Type: Default 1000ms 256MiB

Sorting with Limited Swaps

Sorting with Limited Swaps

You are given an array of n integers. Your task is to sort the array in non-decreasing order by performing a series of swap operations. In each swap, you choose two positions in the array (1-indexed) and swap their values. The goal is to achieve a sorted array using at most \(10^4\) swaps.

If the array is already sorted, you should output 0 swaps. Otherwise, your program must output the number of swaps performed followed by the list of swap operations. Each swap is represented by two indices denoting the positions of the elements that were swapped.

Note: There can be multiple valid sequences of swaps. Your output will be accepted if the sequence of swaps indeed sorts the array and the total number of swaps does not exceed \(10^4\).

inputFormat

The input is given via standard input. The first line contains an integer (n) (the number of elements). The second line contains (n) space-separated integers representing the array.

outputFormat

Output to standard output. The first line should contain an integer (k) representing the number of swaps performed. Each of the following (k) lines should contain two space-separated integers (i) and (j) (1-indexed) indicating a swap between positions (i) and (j).## sample

3
1 2 3
0

</p>