- Time limit: 1.00 s
- Memory limit: 512 MB
You are given an array with numbers; each number between occurs exactly twice. Your task is to sort the array so that each pair of duplicates occurs next to each other. The only operation you can use is swapping any two elements (not necessarily adjacent).
Show how to do sorting with at most swaps.
Input
The first input line has one integer . The second line has numbers: the contents of the array.
Output
First print an integer : the number of swaps
Then, print lines that describe the swaps. You can print any valid solution.
Constraints
Example 1
Input:
3 1 2 1 3 2 3
Output:
2 1 5 3 6
Explanation:
You start with:
1 2 1 3 2 3
You swap elements in positions and to get:
2 2 1 3 1 3
Then you swap elements in positions and to get:
2 2 3 3 1 1
And now you are done.