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>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;

	vector<int> arr(n+1);
	vector<int> link(n+1);
	vector<int> W(n+1);

	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	for(int i = 1; i <= n; i++){
		link[arr[i]] = arr[arr[i]];
		W[arr[i]] = i;
	}

	vector<vector<int>> comp;
	vector<int> no(n+1, -1);
	

	for(int i = 1; i <= n; i++){
		if(no[i] == -1){
			int c = comp.size();
			int cur = link[i];

			comp.push_back({i});
			no[i] = c;
			
			while(cur != i){
				no[cur] = c;
				comp[c].push_back(cur);
				cur = link[cur];
			}
		}
	}

	vector<pair<int,int>> ans;
	auto process = [&](int x, int y){
		int i = W[x];
		int j = W[y];
		ans.push_back({i, j});
		arr[W[x]] = -arr[W[x]];
		arr[W[y]] = -arr[W[y]];
		swap(W[x], W[y]);
		swap(arr[W[x]], arr[W[y]]);
		// for(int i = 1; i <= n; i++) cerr << arr[i] << " ";cerr << "\n";
	};
	for(int i = 1; i < comp.size(); i += 2){
		vector<int>& A = comp[i-1];
		vector<int>& B = comp[i];

		process(A[0], B[0]);
		int keepA = A.back();
		int keepB = B.back();

		for(int i = 1; i < A.size(); i++){
			process(A[i-1], A[i]);
		}
		for(int i = 1; i < B.size(); i++){
			process(B[i-1], B[i]);
		}
		process(keepA, keepB);
	}

	if(comp.size() % 2){
		vector<int>& loop = comp.back();
		
		if(comp.size() > 1){
			vector<int>& A = loop;
			vector<int> B = {comp[0][0]};

			process(A[0], B[0]);
			int keepA = A.back();
			int keepB = B.back();

			for(int i = 1; i < A.size(); i++){
				process(A[i-1], A[i]);
			}
			for(int i = 1; i < B.size(); i++){
				process(B[i-1], B[i]);
			}
			process(keepA, keepB);


		}
		else{
			int a = loop[0];
			int b = loop[1];
			int c = loop[2];

			process(b, c);
			process(a, b);
			int curr = 0;
			for(int i = 0; i < sz(loop) - 2; i++){
				if(arr[a] > 0){
					curr = a;
					a = arr[curr];
					process(curr, arr[curr]);
					curr = a;
				}
				else if(arr[c] > 0){
					curr = c;
					c = arr[curr];
					process(curr, arr[curr]);
					curr = c;
				}
				else assert(0);
			}
			process(curr, -arr[curr]);	
		}
	}
	cout << ans.size() << "\n";
	for(auto x : ans) cout << x.first << " " << x.second << "\n";
}