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.
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
// #include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<p64, p64> pp64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9 + 7;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
// #define mint modint998244353
int LIM = 2e5 + 100;
v64 arr(LIM);
v64 rev(LIM);
vp64 ans;
v64 counter(LIM);
void c_swap(int a, int b)
{
    ans.push_back({a, b});
    counter[arr[a]] = 1 - counter[arr[a]];
    counter[arr[b]] = 1 - counter[arr[b]];
    swap(arr[a], arr[b]);
    rev[arr[a]] = a;
    rev[arr[b]] = b;
}
int reduce(int a)
{
    bool f = 0;
    int cur = a;
    while (true)
    {
        int start = cur;
        while (counter[cur] - counter[arr[cur]] != 1)
        {

            cur = arr[cur];
            if (cur == start)
                return cur;
        }
        int next = arr[cur];
        c_swap(cur, rev[cur]);
        cur = next;
    }
    return -1;
}
void solve()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        rev[arr[i]] = i;
    }
    vp64 roots;
    v64 visited(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        if (visited[i] == 0)
        {
            int cur = arr[i];
            visited[cur] = 1;
            int num = 1;
            while (cur != i)
            {
                cur = arr[cur];
                visited[cur] = 1;
                num++;
            }
            roots.push_back({num, i});
        }
    }
    sort(all(roots));
    if (sz(roots) > 1)
    {
        int m = sz(roots);
        for (int i = 0; i + 1 < sz(roots); i += 2)
        {
            if (sz(roots) & 1)
            {
                if (i == sz(roots) - 3)
                    break;
            }
            c_swap(roots[i].se, roots[i + 1].se);
            int cur = reduce(roots[i].se);
            c_swap(cur, arr[cur]);
        }
        if (sz(roots) & 1)
        {
            int a = roots[m - 1].se, b = roots[m - 2].se, c = roots[m - 3].se;
            if (roots[m - 1].fi + roots[m - 2].fi + roots[m - 3].fi != 3)
            {
                c_swap(a, b);
                for (int i = a;; i = arr[i])
                {
                    if (counter[arr[i]] == 0)
                    {
                        c_swap(i, c);
                        break;
                    }
                }
                int cur = reduce(c);
                c_swap(cur, arr[cur]);
                cur = reduce(c);
                c_swap(cur, arr[cur]);
            }
        }
    }
    else
    {
        int a = arr[roots[0].se];
        c_swap(roots[0].se, arr[roots[0].se]);
        for (int i = roots[0].se;; i = arr[i])
        {
            if (counter[i])
            {
                c_swap(i, a);
                break;
            }
        }
        int cur = reduce(a);
        c_swap(cur, arr[cur]);
    }
    cout << sz(ans) << endl;
    for (int i = 0; i < sz(ans); i++)
    {
        cout << ans[i].fi << " " << ans[i].se << endl;
    }
}

int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    forn(i, t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
    return 0;
}