403021: GYM100971 B Derangement

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Derangementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A permutation of n numbers is a sequence of integers from 1 to n where each number is occurred exactly once. If a permutation p1, p2, ..., pn has an index i such that pi = i, this index is called a fixed point.

A derangement is a permutation without any fixed points.

Let's denote the operation swap(a, b) as swapping elements on positions a and b.

For the given permutation find the minimal number of swap operations needed to turn it into derangement.

Input

The first line contains an integer n (2 ≤ n ≤ 200000) — the number of elements in a permutation.

The second line contains the elements of the permutation — n distinct integers from 1 to n.

Output

In the first line output a single integer k — the minimal number of swap operations needed to transform the permutation into derangement.

In each of the next k lines output two integers ai and bi (1 ≤ ai, bi ≤ n) — the arguments of swap operations.

If there are multiple possible solutions, output any of them.

ExamplesInput
6
6 2 4 3 5 1
Output
1
2 5

加入题单

上一题 下一题 算法标签: