Given sequence a[0]
, a[1]
, ... a[n-1]
of n unique integers, each belongs to the interval [0; n - 1]. The exchange is an operation (i, j) (0 ≤ i, j ≤ n - 1) that swaps the values a[i]
and a[j]
. Sort the sequence using the minimum number of exchanges. Print all exchanges.
First line contains number n (n ≤ 10^6
). Second line contains n different integers from the interval [0; n - 1].
In the first line print the minimum number of exchanges k. In the next k lines print all performed exchanges as pairs (i, j).