Sakurako and a Weird Permutation#409

Sakurako and a Weird Permutation

1 second
256 megabytes
Medium (≈1350)

Recently, Sakurako found a permutation .

She wants to examine it better, to understand all its properties.

In order to do this, she will need to represent it as permutations p_1p_2\dots p_k with an interesting property:

Also, as an additional property: t[p_k[p_{k-1}[\dots[p_1[i]]\dots]]]=i.

Your task is to choose (k\le n-1) and find permutations p_1p_2\dots p_k. If there are several answers, you can output any.

A sequence of integers a_1, a_2, \dots, a_n is called a permutation if the sequence contains each integer from to exactly once. For example, [1, 5, 3, 4, 2] is a permutation. However, [1, 3, 4] is not a permutation (it doesn't contain and contains , which should not appear in the sequence), and [1, 2, 2, 3] is not a permutation as well (it contains twice and doesn't contain ).

Input

The first line contains one integer (2\le n\le 5 \cdot 10^5) — the length of permutation .

The second line contains integers t_1, t_2, , t_n (1\le t_i \le n) — the permutation. It is guaranteed that is a permutation. It is guaranteed that for at least indexes of permutation t[x]\neq x. (1\le x\le n)

Output

You should output an integer (0 \leq k\le n-1). Note that there is no need to minimize .

After that, you should output permutations p_1, p_2, \dots, p_k that you chose.

Because the output may become enormous, you will not be outputting permutations fully. Instead, for each permutation p_i, you need to output all indexes in which p_{i}[q]\neq q.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Scoring

  • ( points): n\le 8;

  • ( points): n\le 100;

  • ( points): n \le 10^5;

  • ( points): without additional constraints.