#include <bits/stdc++.h>
#define ¹ first
#define ² second
std::vector<int> A, B;
void swap(int a, int b){
	while(a < b){
		std::swap(A[a++], A[b--]);
	}
}
int main(){
	int n, i, a, b, cin, cout;
	std::cin >> n;
	for(i = 0; i < n; ++i){
		std::cin >> a;
		A.push_back(a - 1);
		B.push_back(a - 1);
	}
	std::sort(B.begin(), B.end());
	for(a = 0; a < n; ++a){
		if(A[a] != B[a]) break;
	}
	for(b = n - 1; b >= 0; --b){
		if(A[b] != B[b]) break;
	}
	std::vector<std::pair<int, int>> Z;
	while(a < b){
		for(cin = a; cin < b; ++cin){
			if(A[cin] == B[a]) break;
		}
		while(A[cin] == A[cin + 1]) ++cin;
		for(cout = b; cout > a; --cout){
			if(A[cout] == B[b]) break;
		}
		while(A[cout] == A[cout - 1]) --cout;
		if(cin - a <= b - cout){
			Z.emplace_back(a + 1, cin + 1);
			swap(a, cin);
		}else{
			Z.emplace_back(cout + 1, b + 1);
			swap(cout, b);
		}
		for(; a < n; ++a){
			if(A[a] != B[a]) break;
		}
		for(; b >= 0; --b){
			if(A[b] != B[b]) break;
		}
	}
	std::cout << Z.size() << "\n";
	for(auto z : Z){
		std::cout << z.¹ << ' ' << z.² << "\n";
	}
}
