There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins. 

In one operation, you can do the following:

  * Choose 2 distinct indices i and j.

  * Then, swap the coins on positions i and j.

  * Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)




Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.

Note that you do not need to minimize the number of operations.

Input

The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.

The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).

Output

In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.

In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.

Examples

Input


3
2 1 3


Output


3
1 3
3 2
3 1


Input


5
1 2 3 4 5


Output


0

Note

Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.

The series of moves performed in the first sample changes the coins as such:

  * [~~~2,~~~1,~~~3] 
  * [-3,~~~1,-2] 
  * [-3,~~~2,-1] 
  * [~~~1,~~~2,~~~3] 



In the second sample, the coins are already in their correct positions so there is no need to swap.
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
vector<pair<int, int>> ans;
void solve_three_cycles(const vector<int>& c0,const vector<int>&  c1,const vector<int>&  c2) {
    ans.push_back(MP(c0.back(), c1.back()));
    ans.push_back(MP(c1.back(), c2.back()));
    for(int i=0; i<c1.size()-1; i++)
        ans.push_back(MP(c0.back(), c1[i]));
    for(int i=0; i<c2.size(); i++)
        ans.push_back(MP(c1.back(), c2[i]));
    for(int i=0; i<c0.size(); i++)
        ans.push_back(MP(c1.back(), c0[i]));
}
void solve_two_cycles(const vector<int>& c0,const vector<int>&  c1) {
    ans.push_back(MP(c0.back(), c1.back()));
    for(int i=0; i<c1.size()-1; i++)
        ans.push_back(MP(c0.back(), c1[i]));
    for(int i=0; i<c0.size(); i++)
        ans.push_back(MP(c1.back(), c0[i]));
}
void solve_single_cycle(vector<int> c) {
    ans.push_back(MP(c[0], c[1]));
    ans.push_back(MP(c[1], c.back()));
    swap(c[0], c[1]);
    for(int i=2; i<c.size(); i++)
        ans.push_back(MP(c[1], c[i]));
    ans.push_back(MP(c[0], c[1]));
}
void solve_single_cycle_with_innocent(const vector<int>& c, int s) {
    ans.push_back(MP(c[1], s));
    ans.push_back(MP(s, c[0]));
    ans.push_back(MP(c[1], s));
}
int main() {
    int n;
    cin>>n;
    vector<int>c(n);
    for(int i=0; i<n; i++) {
        cin>>c[i];
        c[i]--;
    }
    vector<vector<int>>cycles;
    vector<bool>visited(n, false);
    for(int i=0; i<n; i++) {
        if(visited[i])
            continue;
        vector<int>cycle;
        cycle.push_back(i);
        visited[i] = true;
        while (c[cycle.back()] != i) {
            cycle.push_back(c[cycle.back()]);
            visited[cycle.back()] = true;
        }
        if (cycle.size() == 1)
            continue;
        cycles.push_back(cycle);
    }
    if (cycles.size() == 0) {
    }
    else if (cycles.size() == 1) {
        if (cycles[0].size() > 2) {
            solve_single_cycle(cycles[0]);
        }
        else {
            int innocent = -1;
            for(int j = 0; j < 3; j++) {
                if(j != cycles[0][0] && j != cycles[0][1])
                    innocent = j;
            }
            solve_single_cycle_with_innocent(cycles[0], innocent);
        }
    }
    else {
        int i = 0;
        if (cycles.size() % 2) {
            solve_three_cycles(cycles[0], cycles[1], cycles[2]);
            i = 3;
        }
        else {
            solve_two_cycles(cycles[0], cycles[1]);
            i = 2;
        }
        while (i < cycles.size()) {
            solve_two_cycles(cycles[i], cycles[i+1]);
            i += 2;
        }
    }
    cout<<ans.size()<<endl;
    for(const auto& p : ans) {
        printf("%d %d\n",p.first+1, p.second+1);
    }
}
