#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define ll long long
// #define LOCALIO

const int N = 2000;

struct st {
	int first, last;
	int l, r;
	bool rev;
};

int a[N];
vector<st> per;
vector<pair<int, int> > curr;

void flp(int s, int e) {
	while (s < e) {
		st z = per[s];
		per[s] = per[e];
		per[e] = z;
		per[s].rev = per[s].rev ^ true;
		per[e].rev = per[e].rev ^ true;
		s++, e--;
	}
	if (s == e) {
		per[s].rev = per[s].rev ^ true;
	}
}

bool doit(int ct) {
	int l = 0;
	bool end = true;
	for (int i = 0; i < per.size(); i++) {
		int first = per[i].rev ? per[i].last : per[i].first;
		int last = per[i].rev ? per[i].first : per[i].last;
		if (l + 1 != first) {
			end = false;
			break;
		}
		l = last;
	}
	if (end)
		return true;
	if (ct == 3) {
		return false;
	}
	for (int i = 0; i < per.size(); i++) {
		for (int h = (per[i].first == per[i].last ? i + 1 : i);
				h < per.size(); h++) {
			int first = per[i].rev ? per[i].last : per[i].first;
			int last = per[h].rev ? per[h].first : per[h].last;
			// cout << "count " << ct << " " << i << " " << h << endl;
			flp(i, h);
			curr.push_back(make_pair(first, last));
			if (doit(ct + 1)) {
				return true;
			}
			curr.pop_back();
			// cout << "count " << ct << " " << i << " " << h << endl;
			flp(i, h);
		}
	}
	return false;
}

int main() {
#ifdef LOCALIO
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
	int n;
	cin >> n;
	int l = 0;
	st s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0 && abs(a[i] - a[i - 1]) > 1) {
			s.first = a[l];
			s.last = a[i - 1];
			s.l = l;
			s.r = i - 1;
			s.rev = false;
			per.push_back(s);
			l = i;
		}
	}

	s.first = a[l];
	s.last = a[n - 1];
	s.l = l;
	s.r = n - 1;
	s.rev = false;
	per.push_back(s);

	if (doit(0)) {
		printf("%d\n", curr.size());
		stack<pair<int, int> > s;
		for (int i = 0; i < curr.size(); i++) {
			int l = curr[i].first;
			int r = curr[i].second;
			int p1, p2;
			for (int h = 0; h < n; h++) {
				if (a[h] == l) {
					p1 = h;
				}
				if (a[h] == r) {
					p2 = h;
				}
			}
			s.push(make_pair(p1 + 1, p2 + 1));
			while (p1 < p2) {
				int z = a[p1];
				a[p1] = a[p2];
				a[p2] = z;
				p1++; p2--;
			}
		}
		while (s.size()) {
			printf("%d %d\n", s.top().first, s.top().second);
			s.pop();
		}
	} else {
		return 1;
	}
	// for (int i = 0; i < per.size(); i++) {
	// 	cout << per[i].rev << " " << per[i].first << " " << per[i].last << endl;
	// }
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define ll long long
// #define LOCALIO

const int N = 2000;

int a[N];
int n;
stack<pair<int, int> > st;

void doit(int it) {
	int i;
	for (i = 0; i < n; i++) {
		if (a[i] != i + 1) {
			break;
		}
	}
	if (i >= n) {
		cout << st.size() << endl;
		while (st.size()) {
			cout << st.top().first + 1 << " " << st.top().second + 1<< endl;
			st.pop();
		}
		exit(0);
	}
	if (it == 3) {
		return;
	}
	int v[10];
	v[0] = 0;
	int kn = 1;
	for (int i = 1; i < n; i++) {
		if (abs(a[i] - a[i - 1]) > 1) {
			if (i != n - 1) {
				v[kn++] = i;
			}
			if (i - 1 != 0) {
				v[kn++] = i - 1;
			}
		}
	}
	v[kn++] = n - 1;
	for (int i = 0; i < kn; i++) {
		for (int h = i + 1; h < kn; h++) {
			reverse(a + v[i], a + v[h] + 1);
			st.push(make_pair(v[i], v[h]));
			doit(it + 1);
			st.pop();
			reverse(a + v[i], a + v[h] + 1);
		}
	}
}

int main() {
#ifdef LOCALIO
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	doit(0);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define ll long long
// #define LOCALIO

const int N = 2000;

int a[N];
int n;
stack<pair<int, int> > st;

void doit(int it) {
	int i;
	for (i = 0; i < n; i++) {
		if (a[i] != i + 1) {
			break;
		}
	}
	if (i >= n) {
		cout << st.size() << endl;
		while (st.size()) {
			cout << st.top().first + 1 << " " << st.top().second + 1<< endl;
			st.pop();
		}
		exit(0);
	}
	if (it == 3) {
		return;
	}
	int v[20];
	v[0] = 0;
	int kn = 1;
	for (int i = 1; i < n; i++) {
		if (abs(a[i] - a[i - 1]) > 1) {
			if (i != n - 1) {
				v[kn++] = i;
			}
			if (i - 1 != 0) {
				v[kn++] = i - 1;
			}
		}
	}
	v[kn++] = n - 1;
	for (int i = 0; i < kn; i++) {
		for (int h = i + 1; h < kn; h++) {
			reverse(a + v[i], a + v[h] + 1);
			st.push(make_pair(v[i], v[h]));
			doit(it + 1);
			st.pop();
			reverse(a + v[i], a + v[h] + 1);
		}
	}
}

int main() {
#ifdef LOCALIO
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	doit(0);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define ll long long
// #define LOCALIO

const int N = 2000;

int a[N];
int n;
stack<pair<int, int> > st;

void doit(int it) {
	int i;
	for (i = 0; i < n; i++) {
		if (a[i] != i + 1) {
			break;
		}
	}
	if (i >= n) {
		cout << st.size() << endl;
		while (st.size()) {
			cout << st.top().first + 1 << " " << st.top().second + 1<< endl;
			st.pop();
		}
		exit(0);
	}
	if (it == 3) {
		return;
	}
	int v[20];
	v[0] = 0;
	int kn = 1;
	for (int i = 1; i < n; i++) {
		if (abs(a[i] - a[i - 1]) > 1) {
			if (i - 1 != 0) {
				v[kn++] = i - 1;
			}
			if (i != n - 1) {
				v[kn++] = i;
			}
		}
	}
	v[kn++] = n - 1;
	for (int i = 0; i < kn; i++) {
		for (int h = i + 1; h < kn; h++) {
			reverse(a + v[i], a + v[h] + 1);
			st.push(make_pair(v[i], v[h]));
			doit(it + 1);
			st.pop();
			reverse(a + v[i], a + v[h] + 1);
		}
	}
}

int main() {
#ifdef LOCALIO
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	doit(0);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define ll long long
// #define LOCALIO

const int N = 2000;

struct st {
	int first, last;
	int l, r;
	bool rev;
};

int a[N];
vector<st> per;
vector<pair<int, int> > curr;

void flp(int s, int e) {
	while (s < e) {
		st z = per[s];
		per[s] = per[e];
		per[e] = z;
		per[s].rev = per[s].rev ^ true;
		per[e].rev = per[e].rev ^ true;
		s++, e--;
	}
	if (s == e) {
		per[s].rev = per[s].rev ^ true;
	}
}

bool doit(int ct) {
	int l = 0;
	bool end = true;
	for (int i = 0; i < per.size(); i++) {
		int first = per[i].rev ? per[i].last : per[i].first;
		int last = per[i].rev ? per[i].first : per[i].last;
		if (l + 1 != first) {
			end = false;
			break;
		}
		l = last;
	}
	if (end)
		return true;
	if (ct == 3) {
		return false;
	}
	for (int i = 0; i < per.size(); i++) {
		for (int h = (per[i].first == per[i].last ? i + 1 : i);
				h < per.size(); h++) {
			int first = per[i].rev ? per[i].last : per[i].first;
			int last = per[h].rev ? per[h].first : per[h].last;
			// cout << "count " << ct << " " << i << " " << h << endl;
			flp(i, h);
			curr.push_back(make_pair(first, last));
			if (doit(ct + 1)) {
				return true;
			}
			curr.pop_back();
			// cout << "count " << ct << " " << i << " " << h << endl;
			flp(i, h);
		}
	}
}

int main() {
#ifdef LOCALIO
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
	int n;
	cin >> n;
	int l = 0;
	st s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0 && abs(a[i] - a[i - 1]) > 1) {
			s.first = a[l];
			s.last = a[i - 1];
			s.l = l;
			s.r = i - 1;
			s.rev = false;
			per.push_back(s);
			l = i;
		}
	}

	s.first = a[l];
	s.last = a[n - 1];
	s.l = l;
	s.r = n - 1;
	s.rev = false;
	per.push_back(s);

	if (doit(0)) {
		printf("%d\n", curr.size());
		stack<pair<int, int> > s;
		for (int i = 0; i < curr.size(); i++) {
			int l = curr[i].first;
			int r = curr[i].second;
			int p1, p2;
			for (int h = 0; h < n; h++) {
				if (a[h] == l) {
					p1 = h;
				}
				if (a[h] == r) {
					p2 = h;
				}
			}
			s.push(make_pair(p1 + 1, p2 + 1));
			while (p1 < p2) {
				int z = a[p1];
				a[p1] = a[p2];
				a[p2] = z;
				p1++; p2--;
			}
		}
		while (s.size()) {
			printf("%d %d\n", s.top().first, s.top().second);
			s.pop();
		}
	} else {
		return 1;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <bitset>

using namespace std;

#define ll long long
// #define LOCALIO

const int N = 2000;

struct st {
	int first, last;
	int l, r;
	bool rev;
};

int a[N];
vector<st> per;
vector<pair<int, int> > curr;

void flp(int s, int e) {
	while (s < e) {
		st z = per[s];
		per[s] = per[e];
		per[e] = z;
		per[s].rev = per[s].rev ^ true;
		per[e].rev = per[e].rev ^ true;
		s++, e--;
	}
	if (s == e) {
		per[s].rev = per[s].rev ^ true;
	}
}

bool doit(int ct) {
	int l = 0;
	bool end = true;
	for (int i = 0; i < per.size(); i++) {
		int first = per[i].rev ? per[i].last : per[i].first;
		int last = per[i].rev ? per[i].first : per[i].last;
		if (l + 1 != first) {
			end = false;
			break;
		}
		l = last;
	}
	if (end)
		return true;
	if (ct == 3) {
		return false;
	}
	for (int i = 0; i < per.size(); i++) {
		for (int h = (per[i].first == per[i].last ? i + 1 : i);
				h < per.size(); h++) {
			int first = per[i].rev ? per[i].last : per[i].first;
			int last = per[h].rev ? per[h].first : per[h].last;
			// cout << "count " << ct << " " << i << " " << h << endl;
			flp(i, h);
			curr.push_back(make_pair(first, last));
			if (doit(ct + 1)) {
				return true;
			}
			curr.pop_back();
			// cout << "count " << ct << " " << i << " " << h << endl;
			flp(i, h);
		}
	}
}

int main() {
#ifdef LOCALIO
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#endif
	int n;
	cin >> n;
	int l = 0;
	st s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0 && abs(a[i] - a[i - 1]) > 1) {
			s.first = a[l];
			s.last = a[i - 1];
			s.l = l;
			s.r = i - 1;
			s.rev = false;
			per.push_back(s);
			l = i;
		}
	}

	s.first = a[l];
	s.last = a[n - 1];
	s.l = l;
	s.r = n - 1;
	s.rev = false;
	per.push_back(s);

	if (doit(0)) {
		printf("%d\n", curr.size());
		stack<pair<int, int> > s;
		for (int i = 0; i < curr.size(); i++) {
			int l = curr[i].first;
			int r = curr[i].second;
			int p1, p2;
			for (int h = 0; h < n; h++) {
				if (a[h] == l) {
					p1 = h;
				}
				if (a[h] == r) {
					p2 = h;
				}
			}
			s.push(make_pair(p1 + 1, p2 + 1));
			while (p1 < p2) {
				int z = a[p1];
				a[p1] = a[p2];
				a[p2] = z;
				p1++; p2--;
			}
		}
		while (s.size()) {
			printf("%d %d\n", s.top().first, s.top().second);
			s.pop();
		}
	} else {
		return 1;
	}
	// for (int i = 0; i < per.size(); i++) {
	// 	cout << per[i].rev << " " << per[i].first << " " << per[i].last << endl;
	// }
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int a[N];
int n;
struct node
{
	int x,y;
	node() {};
	node(int _x,int _y):x(_x),y(_y){}
};
vector<node>vec;
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int l=-1,r=-1;
		vec.clear();
		repf(i,1,n)
			scanf("%d",&a[i]);
		while(true)
		{
			int l=-1,r=-1;
			int Max=-1;
			int sign=0;
		   repf(i,1,n)
		   {
              if(a[i]==i)
			    	continue;
			  else
			  {
				  sign=1;
				  if(l==-1) l=i;
				  if(Max==i)//可以翻转的
				  {
					  r=i;
					  vec.push_back(node(l,r));
					  while(l<=r)
						  swap(a[l++],a[r--]);
					  break;
				  }
				  else
					  Max=max(Max,a[i]);
			  }
		   }
		 //  repf(i,1,n) cout<<a[i]<<" ";cout<<endl;
		   if(sign==0) break;
		 }
		printf("%d\n",vec.size());
		repd(i,vec.size()-1,0)
			printf("%d %d\n",vec[i].x,vec[i].y);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int b[N];
int n;
struct node{
	int x,y;
	node() {}
	node(int _x,int _y):x(_x),y(_y){}
};
stack<node>vec;
bool dfs(int l,int r)
{
	int p=l,q=r;
	if(l==r)
		if(b[l]==l) return true;
	    else return false;
	if(l>r) return true;
	vec.push(node(l,r));
	if(vec.size()>3) return false;
	repf(i,l,(l+r-1)/2)
		swap(b[i],b[l+r-i]);
	while(l<r && b[l]==l) l++;
	while(l<r && b[r]==r) --r;
	if(l==r) return true;
	if(p!=l || q!=r)
	if(dfs(l,r)) return true;
	repf(i,l,(l+r)/2)
		swap(b[i],b[l+r-i]);
	vec.pop();
	repf(i,l,r-1)
		if(dfs(l,i) && dfs(i+1,r))
			return true;
	return false;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		while(!vec.empty()) vec.pop();
		repf(i,1,n) scanf("%d",&b[i]);
		int l=1,r=n;
		while(b[l]==l && l<r) ++l;
		while(b[r]==r && l<r) --r;
		if(l==r)
		{
			printf("0\n"); continue;
		}
		dfs(l,r);
		printf("%d\n",vec.size());
		stack<node>que;
	    while(!vec.empty())
		{
			que.push(vec.top()); vec.pop();
		}
		while(!que.empty())
		{
			node r=que.top(); que.pop();
			printf("%d %d",r.x,r.y);
			printf("\n");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int a[N];
int n;
struct node
{
	int x,y;
	node() {};
	node(int _x,int _y):x(_x),y(_y){}
};
vector<node>vec;
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int l=-1,r=-1;
		vec.clear();
		repf(i,1,n)
			scanf("%d",&a[i]);
		while(true)
		{
			int l=-1,r=-1;
			int Max=-1;
			int sign=0;
		   repf(i,1,n)
		   {
              if(a[i]==i)
			    	continue;
			  else
			  {
				  sign=1;
				  if(l==-1) l=i;
				  if(Max==i)//可以翻转的
				  {
					  r=i;
					  vec.push_back(node(l,r));
					  while(l<=r)
						  swap(a[l++],a[r--]);
					  break;
				  }
				  else
					  Max=max(Max,a[i]);
			  }
		   }
		 //  repf(i,1,n) cout<<a[i]<<" ";cout<<endl;
		   if(sign==0) break;
		 }
		printf("%d\n",vec.size());
		rep(i,vec.size())
			printf("%d %d\n",vec[i].x,vec[i].y);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int a[N];
int n;
struct node
{
	int x,y;
	node() {};
	node(int _x,int _y):x(_x),y(_y){}
};
vector<node>vec;
int getl()
{
	repf(i,1,n)
		if(a[i]!=i)
			return i;
	return 0;
}
int getr()
{
	repd(i,n,1)
		if(a[i]!=i)
			return i;
	return 0;
}
int getp(int x)
{
	repf(i,1,n)
		if(a[i]==x)
			return i;
}
void trans(int l,int r)
{
	repf(i,l,(l+r-1)/2)
		swap(a[i],a[l+r-i]);
}
bool dfs(int s)
{
	if(s==5) return false;
	int l=getl();
	int r=getp(l);
    if(l==0) return true;
	trans(l,r);
	if(dfs(s+1)){
		vec.push_back(node(l,r));
		return 1;
	}
	trans(l,r);
	r=getr();
	l=getp(r);
	trans(l,r);
	cout<<" "<<l<<" "<<r<<endl;
	if(dfs(s+1))
	{
		vec.push_back(node(l,r));
		return 1;
	}
	trans(l,r);
    return 0;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int l=-1,r=-1;
		vec.clear();
		repf(i,1,n)
			scanf("%d",&a[i]);
		dfs(1);
		printf("%d\n",vec.size());
		rep(i,vec.size())
			printf("%d %d\n",vec[i].x,vec[i].y);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int b[N];
int n;
struct node{
	int x,y;
	node() {}
	node(int _x,int _y):x(_x),y(_y){}
};
stack<node>vec;
bool dfs(int l,int r)
{
	int p=l,q=r;
	if(l==r)
		if(b[l]==l) return true;
	    else return false;
	if(l>r) return true;
	vec.push(node(l,r));
	if(vec.size()>3) return false;
	repf(i,l,(l+r-1)/2)
		swap(b[i],b[l+r-i]);
	while(l<r && b[l]==l) l++;
	while(l<r && b[r]==r) --r;
	if(l==r) return true;
	if(p!=l || q!=r)
	if(dfs(l,r)) return true;
	repf(i,l,(l+r)/2)
		swap(b[i],b[l+r-i]);
	vec.pop();
	repf(i,l,r-1)
		if(dfs(l,i) && dfs(i+1,r))
			return true;
	return false;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		while(!vec.empty()) vec.pop();
		repf(i,1,n) scanf("%d",&b[i]);
		int l=1,r=n;
		while(b[l]==l && l<r) ++l;
		while(b[r]==r && l<r) --r;
		if(l==r)
		{
			printf("0\n"); continue;
		}
		dfs(l,r);
		printf("%d\n",vec.size());
		while(!vec.empty())
		{
			node r=vec.top(); vec.pop();
			printf("%d %d",r.x,r.y);
			printf("\n");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int a[N];
int n;
struct node
{
	int x,y;
	node() {};
	node(int _x,int _y):x(_x),y(_y){}
};
vector<node>vec;
int getl()
{
	repf(i,1,n)
		if(a[i]!=i)
			return i;
	return 0;
}
int getr()
{
	repd(i,n,1)
		if(a[i]!=i)
			return i;
	return 0;
}
int getp(int x)
{
	repf(i,1,n)
		if(a[i]==x)
			return i;
}
void trans(int l,int r)
{
	repf(i,l,(l+r-1)/2)
		swap(a[i],a[l+r-i]);
}
bool dfs(int s)
{
	if(s==5) return false;
	int l=getl();
	int r=getp(l);
    if(l==0) return true;
	trans(l,r);
	if(dfs(s+1)){
		vec.push_back(node(l,r));
		return 1;
	}
	trans(l,r);
	r=getr();
	l=getp(r);
	trans(l,r);
	if(dfs(s+1))
	{
		vec.push_back(node(l,r));
		return 1;
	}
	trans(l,r);
    return 0;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int l=-1,r=-1;
		vec.clear();
		repf(i,1,n)
			scanf("%d",&a[i]);
		dfs(1);
		printf("%d\n",vec.size());
		rep(i,vec.size())
			printf("%d %d\n",vec[i].x,vec[i].y);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repf(i,n,m) for(int i=(n); i<=(m); ++i)
#define repd(i,n,m) for(int i=(n); i>=(m); --i)
#define ll long long
#define arc(a) ((a)*(a))
#define inf 100000
#define exp 0.00000001
#define N 1005
int b[N];
int n;
struct node{
	int x,y;
	node() {}
	node(int _x,int _y):x(_x),y(_y){}
};
stack<node>vec;
bool dfs(int l,int r)
{
	int p=l,q=r;
	if(l==r)
		if(b[l]==l) return true;
	    else return false;
	if(l>r) return true;
	vec.push(node(l,r));
	if(vec.size()>3) return false;
	repf(i,l,(l+r-1)/2)
		swap(b[i],b[l+r-i]);
	repf(i,1,n) cout<<b[i]<<" "; cout<<endl;
	while(l<r && b[l]==l) l++;
	while(l<r && b[r]==r) --r;
	if(l==r) return true;
	if(p!=l || q!=r)
	if(dfs(l,r)) return true;
	repf(i,l,(l+r)/2)
		swap(b[i],b[l+r-i]);
	vec.pop();
	repf(i,l,r-1)
		if(dfs(l,i) && dfs(i+1,r))
			return true;
	return false;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		while(!vec.empty()) vec.pop();
		repf(i,1,n) scanf("%d",&b[i]);
		int l=1,r=n;
		while(b[l]==l && l<r) ++l;
		while(b[r]==r && l<r) --r;
		if(l==r)
		{
			printf("0\n"); continue;
		}
		dfs(l,r);
		printf("%d\n",vec.size());
		while(!vec.empty())
		{
			node r=vec.top(); vec.pop();
			printf("%d %d",r.x,r.y);
			printf("\n");
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    if (!steps && sus.size() > 14) return 0;
    else if (step == 1 && sus.size() > 10) return 0;
    else if (steps == 2 && sus.size() > 14) return 0;
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    if (!steps && sus.size() > 14) return 0;
    else if (steps == 1 && sus.size() > 10) return 0;
    else if (steps == 2 && sus.size() > 14) return 0;

    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0);
    Suspected(vec, ret);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps, bool ret){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    if ( sus.size() > 14) return 0;
    //else if (steps == 1 && sus.size() > 10) return 0;
    //else if (steps == 2 && sus.size() > 14) return 0;
    bool &rr = ret;
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1, rr)){
                if (!rr) ans.push_back(pii(sus[s]+1, sus[e]+1));
                rr = 1;
            }
        }
    }
    return rr;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    if (sus.size() > 14) return 0;
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    for (int s = 0 ; s < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N, a;
    scanf("%d",&N);
    vector<int > vec,ret;

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&a);
        org.push_back(i);
        vec.push_back(a-1);
    }

    Solve(vec, 0);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    if (vec[0] != 0) ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (!ret.size() || (ret.size() && ret.back() != i && vec[i] != i)) ret.push_back(i);
            if (!ret.size() || (ret.size() && ret.back() != i+1 && vec[i+1] != i+1))ret.push_back(i+1);
        }
    if (!ret.size() || (ret.size() && ret.back() != (int)vec.size()-1 && vec[(int)vec.size()-1] != (int)vec.size()-1))
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    if (!steps && sus.size() > 14) return 0;
    else if (steps == 1 && sus.size() > 10) return 0;
    else if (steps == 2 && sus.size() > 14) return 0;
    bool ret = 0;
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                if (!ret) ans.push_back(pii(sus[s]+1, sus[e]+1));
                ret = 1;
            }
        }
    }
    return ret;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    vector<int> suspected(vec.size());
    ret.push_back(0), ret.push_back((int)vec.size()-1);
    suspected[0] = suspected[(int)vec.size()-1] = 1;
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (!suspected[i]) ret.push_back(i);
            if (!suspected[i+1]) ret.push_back(i+1);
            suspected[i] = suspected[i] = 1;
        }
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    for (int s = 0 ; s < (int)sus.size() ; s ++){
        for (int e = 0 ; e < (int)sus.size() ; e ++){
            if (s == e) continue;
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N, a;
    scanf("%d",&N);
    vector<int > vec,ret;

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&a);
        org.push_back(i);
        vec.push_back(a-1);
    }

    Solve(vec, 0);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    if (!steps && sus.size() > 14) return 0;
    else if (steps == 1 && sus.size() > 10) return 0;
    else if (steps == 2 && sus.size() > 14) return 0;
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    vector<int> suspected(1005);
    ret.push_back(0), ret.push_back((int)vec.size()-1);
    suspected[0] = suspected[(int)vec.size()-1] = 1;
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (!suspected[i]) ret.push_back(i);
            if (!suspected[i+1]) ret.push_back(i+1);
            suspected[i] = suspected[i] = 1;
        }
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    for (int s = 0 ; s < (int)sus.size() ; s ++){
        for (int e = 0 ; e < (int)sus.size() ; e ++){
            if (s == e) continue;
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N, a;
    scanf("%d",&N);
    vector<int > vec,ret;

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&a);
        org.push_back(i);
        vec.push_back(a-1);
    }

    Solve(vec, 0);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0), ret.push_back((int)vec.size()-1);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1)
            ret.push_back(i), ret.push_back(i+1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    for (int s = 0 ; s < (int)sus.size() ; s ++){
        for (int e = 0 ; e < (int)sus.size() ; e ++){
            if (s == e) continue;
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N, a;
    scanf("%d",&N);
    vector<int > vec,ret;

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&a);
        org.push_back(i);
        vec.push_back(a-1);
    }

    Solve(vec, 0);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0), ret.push_back((int)vec.size()-1);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1)
            ret.push_back(i), ret.push_back(i+1);
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    for (int s = 0 ; s < (int)sus.size() ; s ++){
        for (int e = 0 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N, a;
    scanf("%d",&N);
    vector<int > vec,ret;

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&a);
        org.push_back(i);
        vec.push_back(a-1);
    }

    Solve(vec, 0);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;
bool suspected[1005];

void Suspected(vector<int >& vec, vector<int > &ret){
    memset(suspected, 0, sizeof(suspected));
    ret.push_back(0), ret.push_back((int)vec.size()-1);
    suspected[0] = suspected[(int)vec.size()-1] = 1;
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (!suspected[i]) ret.push_back(i);
            if (!suspected[i+1]) ret.push_back(i+1);
            suspected[i] = suspected[i] = 1;
        }
}

bool Solve(vector<int > &vec, int steps){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);

    for (int s = 0 ; s < (int)sus.size() ; s ++){
        for (int e = 0 ; e < (int)sus.size() ; e ++){
            if (s == e) continue;
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1)){
                ans.push_back(pii(sus[s]+1, sus[e]+1));
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int N, a;
    scanf("%d",&N);
    vector<int > vec,ret;

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&a);
        org.push_back(i);
        vec.push_back(a-1);
    }

    Solve(vec, 0);

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int > pii;

vector<int > org;
vector<pii > ans;

void Suspected(vector<int >& vec, vector<int > &ret){
    ret.push_back(0);
    for (int i = 0 ; i+1 < (int)vec.size() ; i ++)
        if (abs(vec[i]-vec[i+1]) != 1){
            if (ret.back() != i) ret.push_back(i);
            ret.push_back(i+1);
        }
    if (ret.back() != (int)vec.size()-1)
        ret.push_back((int)vec.size()-1);
}

bool Solve(vector<int > &vec, int steps, bool ret){
    if (vec == org) return 1;
    if (steps == 3) return 0;
    vector<int > sus;
    Suspected(vec, sus);
    if (!steps && sus.size() > 14) return 0;
    else if (steps == 1 && sus.size() > 10) return 0;
    else if (steps == 2 && sus.size() > 14) return 0;
    bool &rr = ret;
    // cout << sus.size() << endl;
    for (int s = 0 ; s+1 < (int)sus.size() ; s ++){
        for (int e = s+1 ; e < (int)sus.size() ; e ++){
            vector<int> cop = vec;
            for (int l = sus[s], r = sus[e] ; l < r ; l ++, r --)
                swap(cop[l], cop[r]);
            if (Solve(cop, steps+1, rr)){
                if (!rr) ans.push_back(pii(sus[s]+1, sus[e]+1));
                rr = 1;
            }
        }
    }
    return rr;
}

int main()
{
    int N;
    scanf("%d",&N);
    vector<int > vec(N), ret;
    org.resize(N);

    for (int i = 0 ; i < N ; i ++){
        scanf("%d",&vec[i]);
        org[i] = i;
        vec[i] --;
    }

    Solve(vec, 0, 0);
    Suspected(vec, ret);
    //cout << ret.size() << endl;

    printf("%d\n",(int)ans.size());
    for (int i = 0 ; i < (int)ans.size() ; i ++)
        printf("%d %d\n",ans[i].first, ans[i].second);

    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int l[5], r[5], ansl[5], ansr[5], mn, A[100001], B[100001], C[100001], i, n;
void reverse(int l, int r)
{
	for (int i = l; i <= (l + r) >> 1; i++)
		swap(A[i], A[l + r - i]);
	for (int i = l; i <= r; i++) C[A[i]] = i;
}
void dfs(int x)
{
	int l1, r1, l2, r2;
	l1 = r1 = l2 = r2 = -1;
	for (int i = 1; i <= n; i++)
		if (A[i] != B[i]) {l1 = i, r1 = C[B[i]]; break;}
	for (int i = n; i >= 1; i--)
		if (A[i] != B[i]) {r2 = i, l2 = C[B[i]]; break;}
	if (l1 == -1 && r1 == -1)
	{
		mn = min(mn, x - 1);
		memcpy(ansl, l, sizeof(ansl));
		memcpy(ansr, r, sizeof(ansr));
		return;
	}
	if (x == 4) return;
	reverse(l1, r1), l[x] = l1, r[x] = r1,dfs(x + 1), reverse(l1, r1);
	reverse(l2, r2), l[x] = l2, r[x] = r2, dfs(x + 1), reverse(l2, r2);
}
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) A[i] = C[i] = i;
	for (i = 1; i <= n; i++) scanf("%d", &B[i]);
	mn = 5, dfs(1);
	if (mn < 4)
	{
		printf("%d\n", mn);
		for (i = 1; i <= mn; i++) printf("%d %d\n", ansl[i], ansr[i]);
		return 0;
	}
	for (i = 1; i <= n; i++) swap(A[i], B[i]), C[A[i]] = i;
	dfs(1);
	printf("%d\n", mn);
	for (i = mn; i >= 1; i--) printf("%d %d\n", ansl[i], ansr[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int l[5], r[5], ansl[5], ansr[5], mn, A[100001], B[100001], C[100001], i, n;
void reverse(int l, int r)
{
	for (int i = l; i <= (l + r) >> 1; i++)
		swap(A[i], A[l + r - i]);
	for (int i = l; i <= r; i++) C[A[i]] = i;
}
void dfs(int x)
{
	int l1, r1, l2, r2;
	l1 = r1 = l2 = r2 = -1;
	for (int i = 1; i <= n; i++)
		if (A[i] != B[i]) {l1 = i, r1 = C[B[i]]; break;}
	for (int i = n; i >= 1; i--)
		if (A[i] != B[i]) {r2 = i, l2 = C[B[i]]; break;}
	if (l1 == -1 && r1 == -1)
	{
		mn = min(mn, x - 1);
		memcpy(ansl, l, sizeof(ansl));
		memcpy(ansr, r, sizeof(ansr));
		return;
	}
	if (x == 4) return;
	reverse(l1, r1), l[x] = l1, r[x] = r1,
	dfs(x + 1),
	reverse(l1, r1);

	reverse(l2, r2), l[x] = l2, r[x] = r2,
	dfs(x + 1),
	reverse(l2, r2);
}
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) scanf("%d", &A[i]), C[A[i]] = i;
	for (i = 1; i <= n; i++) scanf("%d", &B[i]);
	mn = 5, dfs(1);
	if (mn < 4)
	{
		printf("%d\n", mn);
		for (i = 1; i <= mn; i++) printf("%d %d\n", ansl[i], ansr[i]);
		return 0;
	}
	for (i = 1; i <= n; i++) swap(A[i], B[i]), C[A[i]] = i;
	dfs(1);
	printf("%d\n", mn);
	for (i = mn; i >= 1; i--) printf("%d %d\n", ansl[i], ansr[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int l[5], r[5], ansl[5], ansr[5], mn, A[100001], B[100001], C[100001], i, n;
void reverse(int l, int r)
{
	for (int i = l; i <= (l + r) >> 1; i++)
		swap(A[i], A[l + r - i]);
	for (int i = l; i <= r; i++) C[A[i]] = i;
}
void dfs(int x)
{
	int l1, r1, l2, r2;
	l1 = r1 = l2 = r2 = -1;
	for (int i = 1; i <= n; i++)
		if (A[i] != B[i]) {l1 = i, r1 = C[B[i]]; break;}
	for (int i = n; i >= 1; i--)
		if (A[i] != B[i]) {r2 = i, l2 = C[B[i]]; break;}
	if (l1 == -1 && r1 == -1)
	{
		mn = min(mn, x - 1);
		memcpy(ansl, l, sizeof(ansl));
		memcpy(ansr, r, sizeof(ansr));
		return;
	}
	if (x == 4) return;
	reverse(l1, r1), l[x] = l1, r[x] = r1, dfs(x + 1), reverse(l1, r1);
	reverse(l2, r2), l[x] = l2, r[x] = r2, dfs(x + 1), reverse(l2, r2);
}
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) scanf("%d", &A[i]), C[A[i]] = i;
	for (i = 1; i <= n; i++) B[i] = i;/*
	for (i = 1; i <= n; i++) A[i] = C[i];
	for (i = 1; i <= n; i++) B[i] = i;*/
	mn = 5, dfs(1);
	printf("%d\n", mn);
	for (i = 1; i <= mn; i++) printf("%d %d\n", ansl[i], ansr[i]);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int l[5], r[5], ansl[5], ansr[5], mn, A[100001], B[100001], C[100001], i, n;
void reverse(int l, int r)
{
	for (int i = l; i <= (l + r) >> 1; i++)
		swap(A[i], A[l + r - i]);
	for (int i = l; i <= r; i++) C[A[i]] = i;
}
void dfs(int x)
{
	int l1, r1, l2, r2;
	l1 = r1 = l2 = r2 = -1;
	for (int i = 1; i <= n; i++)
		if (A[i] != B[i]) {l1 = i, r1 = C[B[i]]; break;}
	for (int i = n; i >= 1; i--)
		if (A[i] != B[i]) {r2 = i, l2 = C[B[i]]; break;}
	if (l1 == -1 && r1 == -1)
	{
		mn = min(mn, x - 1);
		memcpy(ansl, l, sizeof(ansl));
		memcpy(ansr, r, sizeof(ansr));
		return;
	}
	if (x == 4) return;
	reverse(l1, r1), l[x] = l1, r[x] = r1, dfs(x + 1), reverse(l1, r1);
	reverse(l2, r2), l[x] = l2, r[x] = r2, dfs(x + 1), reverse(l2, r2);
}
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) scanf("%d", &A[i]), C[A[i]] = i;
	for (i = 1; i <= n; i++) scanf("%d", &B[i]);/*
	for (i = 1; i <= n; i++) A[i] = C[i];
	for (i = 1; i <= n; i++) B[i] = i;*/
	mn = 5, dfs(1);
	printf("%d\n", mn);
	for (i = 1; i <= mn; i++) printf("%d %d\n", ansl[i], ansr[i]);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int l[5], r[5], ansl[5], ansr[5], mn, A[100001], B[100001], C[100001], i, n;
void reverse(int l, int r)
{
	for (int i = l; i <= (l + r) >> 1; i++)
		swap(A[i], A[l + r - i]);
	for (int i = l; i <= r; i++) C[A[i]] = i;
}
void dfs(int x)
{
	int l1, r1, l2, r2;
	l1 = r1 = l2 = r2 = -1;
	for (int i = 1; i <= n; i++)
		if (A[i] != B[i]) {l1 = i, r1 = C[B[i]]; break;}
	for (int i = n; i >= 1; i--)
		if (A[i] != B[i]) {r2 = i, l2 = C[B[i]]; break;}
	if (l1 == -1 && r1 == -1)
	{
		mn = min(mn, x - 1);
		memcpy(ansl, l, sizeof(ansl));
		memcpy(ansr, r, sizeof(ansr));
		return;
	}
	if (x == 4) return;
	reverse(l1, r1), l[x] = l1, r[x] = r1,dfs(x + 1), reverse(l1, r1);
	reverse(l2, r2), l[x] = l2, r[x] = r2, dfs(x + 1), reverse(l2, r2);
}
int main()
{
	scanf("%d", &n);
	for (i = 1; i <= n; i++) A[i] = C[i] = i;
	for (i = 1; i <= n; i++) scanf("%d", &B[i]);
	mn = 5, dfs(1);
	printf("%d\n", mn);
	for (i = 1; i <= mn; i++) printf("%d %d\n", ansl[i], ansr[i]);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,x[2000],y[10],len,z[4][2],flag,a[2000];
int check(int k){
    for (int i=1;i<=n;i++) a[i]=i;
    for (int i=1;i<=k;i++){
        int l=z[i][0],r=z[i][1];
        while (l<r){swap(a[l],a[r]); l++; r--;}
    }
    for (int i=1;i<=n;i++) if (a[i]!=x[i]) return 0;
    return 1;
}
void solve(int k){
    if (check(k)){
        int k1=k; for (int i=1;i<=k;i++) if (z[i][0]==z[i][1]) k1--;
        cout<<k1<<endl; for (int i=1;i<=k;i++) if (z[i][0]!=z[i][1])cout<<z[i][0]<<" "<<z[i][1]<<endl; flag=1; return;
    }
    if (k==3) return;
    for (int i=1;i<=len;i++)
        for (int j=i;j<=len;j++){
            z[k+1][0]=y[i]; z[k+1][1]=y[j+1]-1; solve(k+1); if (flag) return;
        }
}
int main(){
    scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&x[i]);
    len=1; y[1]=1;
    for (int i=2;i<=n;i++)
        if (i-1==y[len]){
            if (abs(x[i]-x[i-1])!=1) y[++len]=i;
        } else if (x[i]-x[i-1]!=x[i-1]-x[i-2]) y[++len]=i;
    y[len+1]=n+1;
    solve(0); return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,x[2000],y[10],len,z[4][2],flag,a[2000];
int check(int k){
    for (int i=1;i<=n;i++) a[i]=i;
    for (int i=1;i<=k;i++){
        int l=z[i][0],r=z[i][1];
        while (l<r){swap(a[l],a[r]); l++; r--;}
    }
    for (int i=1;i<=n;i++) if (a[i]!=x[i]) return 0;
    return 1;
}
void solve(int k){
    if (check(k)){
        cout<<k<<endl; for (int i=1;i<=k;i++) cout<<z[i][0]<<" "<<z[i][1]<<endl; flag=1; return;
    }
    if (k==3) return;
    for (int i=1;i<=len;i++)
        for (int j=i;j<=len;j++){
            z[k+1][0]=y[i]; z[k+1][1]=y[i+1]-1; solve(k+1); if (flag) return;
        }
}
int main(){
    scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&x[i]);
    len=1; y[1]=1;
    for (int i=2;i<=n;i++)
        if (i-1==y[len]){
            if (abs(x[i]-x[i-1])!=1) y[++len]=i;
        } else if (x[i]-x[i-1]!=x[i-1]-x[i-2]) y[++len]=i;
    y[len+1]=n+1;
    solve(0); return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,x[2000],z[4][2],len,flag,a[2000];
void reverse(int l,int r){
    while (l<r){
        swap(x[l],x[r]); l++; r--;
    }
}
void solve(int k){
    int pd=0;
    for (int i=1;i<=n;i++) if (x[i]!=i){pd=1; break;}
    if (pd==0){
        cout<<k<<endl;
        for (int i=k;i;i--) cout<<z[i][0]<<" "<<z[i][1]<<endl;
        flag=1; return;
    }
    if (k==3) return;
    int y[30],len=0;
    for (int i=1;i<=n;i++) if (abs(x[i]-x[i-1])>1||abs(x[i+1]-x[i])>1) y[++len]=i;
    for (int i=1;i<=len;i++)
        for (int j=i+1;j<=len;j++){
            z[k+1][0]=y[i]; z[k+1][1]=y[j];
            reverse(y[i],y[j]); solve(k+1);
            reverse(y[i],y[j]); if (flag) return;
        }
}
int main(){
    scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&x[i]); x[0]=0; x[n+1]=n+1;
    solve(0); return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,x[2000],y[10],len,z[4][2],flag,a[2000];
int check(int k){
    for (int i=1;i<=n;i++) a[i]=i;
    for (int i=1;i<=k;i++){
        int l=z[i][0],r=z[i][1];
        while (l<r){swap(a[l],a[r]); l++; r--;}
    }
    for (int i=1;i<=n;i++) if (a[i]!=x[i]) return 0;
    return 1;
}
void solve(int k){
    if (check(k)){
        int k1=k; for (int i=1;i<=k;i++) if (z[i][0]==z[i][1]) k1--;
        cout<<k1<<endl; for (int i=1;i<=k;i++) if (z[i][0]!=z[i][1])cout<<z[i][0]<<" "<<z[i][1]<<endl; flag=1; return;
    }
    if (k==3) return;
    for (int i=1;i<=len;i++)
        for (int j=i;j<=len;j++){
            z[k+1][0]=y[i]; z[k+1][1]=y[i+1]-1; solve(k+1); if (flag) return;
        }
}
int main(){
    scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&x[i]);
    len=1; y[1]=1;
    for (int i=2;i<=n;i++)
        if (i-1==y[len]){
            if (abs(x[i]-x[i-1])!=1) y[++len]=i;
        } else if (x[i]-x[i-1]!=x[i-1]-x[i-2]) y[++len]=i;
    y[len+1]=n+1;
    solve(0); return 0;
}


/*
Date: 2014/09/28 08:44:05 Sunday
Author: xllend3
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define X first
#define Y second
#define mp make_pair
#define ph push
#define pb push_back
#define rep(i,a,n) for(int _tmp=(n),i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a[N],b[N];
pii res[9];
int calc(){
    int ans=0;
    rep(i,1,n-1)b[i]=a[i+1]-a[i];b[0]=b[1];
    rep(i,1,n-1)if(b[i]==b[i-1]&&abs(b[i])==1);else b[i]=b[i+1],++ans;
    //rep(i,1,n)printf("%d ",a[i]);printf("[%d]\n",ans);
    return ans;
}
void rev(int l,int r){rep(i,l,l+r>>1)swap(a[i],a[r+l-i]);}
int ok(){rep(i,1,n)if(a[i]!=i)return 0;return 1;}
void dfs(int x){
    if(ok()){
        printf("%d\n",x-1);
        dep(i,x-1,1)printf("%d %d\n",res[i].X,res[i].Y);
        exit(0);
    }
    if(x>3)return;
    int p=calc();
    rep(i,1,n)rep(j,i+1,n)if(abs(a[i-1]-a[j])==1||abs(a[i]-a[j+1])==1)
    {
        rev(i,j);int t=calc();if(t<=(3-x)*2&&t<=p){
            res[x].X=i;res[x].Y=j;dfs(x+1);
        }rev(i,j);
    }
}
int main()
{
    scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);a[0]=0;a[n+1]=n+1;
    dfs(1);
    return 0;
}


/*
Date: 2014/09/28 08:44:05 Sunday
Author: xllend3
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define X first
#define Y second
#define mp make_pair
#define ph push
#define pb push_back
#define rep(i,a,n) for(int _tmp=(n),i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a[N],b[N];
pii res[9];
int calc(){
	int ans=0;
	rep(i,1,n-1)b[i]=a[i+1]-a[i];b[0]=b[1];
	rep(i,1,n-1)if(b[i]==b[i-1]&&abs(b[i])==1);else b[i]=b[i+1],++ans;
	//rep(i,1,n)printf("%d ",a[i]);printf("[%d]\n",ans);
	return ans;
}
void rev(int l,int r){rep(i,l,l+r>>1)swap(a[i],a[r+l-i]);}
int ok(){rep(i,1,n)if(a[i]!=i)return 0;return 1;}
void dfs(int x){
	if(ok()){
		printf("%d\n",x-1);
		dep(i,x-1,1)printf("%d %d\n",res[i].X,res[i].Y);
		exit(0);
	}
	if(x>3)return;
	rep(i,1,n)rep(j,i+1,n)if(abs(a[i-1]-a[j])==1||abs(a[i]-a[j+1])==1){
		rev(i,j);if(calc()<=(3-x)*2){
			res[x].X=i;res[x].Y=j;dfs(x+1);
		}rev(i,j);
	}
}
int main()
{
	scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);a[0]=0;a[n+1]=n+1;
	dfs(1);
	return 0;
}


/*
Date: 2014/09/28 08:44:05 Sunday
Author: xllend3
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define X first
#define Y second
#define mp make_pair
#define ph push
#define pb push_back
#define rep(i,a,n) for(int _tmp=(n),i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a[N],b[N];
pii res[9];
int calc(){
    int ans=0;
    rep(i,1,n-1)b[i]=a[i+1]-a[i];b[0]=b[1];
    rep(i,1,n-1)if(b[i]==b[i-1]&&abs(b[i])==1);else b[i]=b[i+1],++ans;
    //rep(i,1,n)printf("%d ",a[i]);printf("[%d]\n",ans);
    return ans;
}
void rev(int l,int r){rep(i,l,l+r>>1)swap(a[i],a[r+l-i]);}
int ok(){rep(i,1,n)if(a[i]!=i)return 0;return 1;}
void dfs(int x){
    if(ok()){
        printf("%d\n",x-1);
        dep(i,x-1,1)printf("%d %d\n",res[i].X,res[i].Y);
        exit(0);
    }
    if(x>3)return;
    int p=calc();
    rep(i,1,n)rep(j,i+1,n)//if(abs(a[i-1]-a[j])==1||abs(a[i]-a[j+1])==1)
    {
        rev(i,j);int t=calc();if(t<=(3-x)*2&&t<=p){
            res[x].X=i;res[x].Y=j;dfs(x+1);
        }rev(i,j);
    }
}
int main()
{
    scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);a[0]=0;a[n+1]=n+1;
    dfs(1);
    return 0;
}


/*
Date: 2014/09/28 08:44:05 Sunday
Author: xllend3
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define X first
#define Y second
#define mp make_pair
#define ph push
#define pb push_back
#define rep(i,a,n) for(int _tmp=(n),i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a[N],b[N];
pii res[9];
int calc(){
	int ans=0;
	rep(i,1,n-1)b[i]=a[i+1]-a[i];b[0]=b[1];
	rep(i,1,n-1)if(b[i]==b[i-1]&&abs(b[i])==1);else b[i]=b[i+1],++ans;
	//rep(i,1,n)printf("%d ",a[i]);printf("[%d]\n",ans);
	return ans;
}
void rev(int l,int r){rep(i,l,l+r>>1)swap(a[i],a[r+l-i]);}
int ok(){rep(i,1,n)if(a[i]!=i)return 0;return 1;}
void dfs(int x){
	if(ok()){
		printf("%d\n",x-1);
		dep(i,x-1,1)printf("%d %d\n",res[i].X,res[i].Y);
		exit(0);
	}
	if(x>3)return;
	rep(i,1,n)rep(j,i+1,n)if(abs(a[i-1]-a[j])==1||abs(a[i]-a[j+1])==1){
		rev(i,j);res[x].X=i;res[x].Y=j;dfs(x+1);rev(i,j);
	}
}
int main()
{
	scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);a[0]=0;a[n+1]=n+1;
	dfs(1);
	return 0;
}


/*
Date: 2014/09/28 08:44:05 Sunday
Author: xllend3
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define X first
#define Y second
#define mp make_pair
#define ph push
#define pb push_back
#define rep(i,a,n) for(int _tmp=(n),i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a[N],b[N];
pii res[9];
int calc(){
	int ans=0;
	rep(i,1,n-1)b[i]=a[i+1]-a[i];b[0]=b[1];
	rep(i,1,n-1)if(b[i]==b[i-1]&&abs(b[i])==1);else b[i]=b[i+1],++ans;
	//rep(i,1,n)printf("%d ",a[i]);printf("[%d]\n",ans);
	return ans;
}
void rev(int l,int r){rep(i,l,l+r>>1)swap(a[i],a[r+l-i]);}
int ok(){rep(i,1,n)if(a[i]!=i)return 0;return 1;}
void dfs(int x){
	if(ok()){
		printf("%d\n",x-1);
		dep(i,x-1,1)printf("%d %d\n",res[i].X,res[i].Y);
		exit(0);
	}
	if(x>3)return;
	rep(i,1,n)rep(j,i+1,n){
		rev(i,j);if(calc()<=(3-x)*2){
			res[x].X=i;res[x].Y=j;dfs(x+1);
		}rev(i,j);
	}
}
int main()
{
	scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
	dfs(1);
	return 0;
}


/*
Date: 2014/09/28 08:44:05 Sunday
Author: xllend3
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define X first
#define Y second
#define mp make_pair
#define ph push
#define pb push_back
#define rep(i,a,n) for(int _tmp=(n),i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a[N],b[N];
pii res[9];
int calc(){
    int ans=0;
    rep(i,1,n-1)b[i]=a[i+1]-a[i];b[0]=b[1];
    rep(i,1,n-1)if(b[i]==b[i-1]&&abs(b[i])==1);else b[i]=b[i+1],++ans;
    //rep(i,1,n)printf("%d ",a[i]);printf("[%d]\n",ans);
    return ans;
}
void rev(int l,int r){rep(i,l,l+r>>1)swap(a[i],a[r+l-i]);}
int ok(){rep(i,1,n)if(a[i]!=i)return 0;return 1;}
void dfs(int x){
    if(ok()){
        printf("%d\n",x-1);
        dep(i,x-1,1)printf("%d %d\n",res[i].X,res[i].Y);
        exit(0);
    }
    if(x>3)return;
    int p=calc();
    rep(i,1,n)rep(j,i+1,n)//if(abs(a[i-1]-a[j])==1||abs(a[i]-a[j+1])==1)
    {
        rev(i,j);int t=calc();if(t<=(3-x)*2&&t<p){
            res[x].X=i;res[x].Y=j;dfs(x+1);
        }rev(i,j);
    }
}
int main()
{
    scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);a[0]=0;a[n+1]=n+1;
    dfs(1);
    return 0;
}


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot;

struct data begin
	int L,R,minx;
	bool rev;
end;

data a[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[i].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			a[tot].R=i-1;
			if last<a[tot].minx then a[tot].minx=last;
			a[++tot].L=i;
			a[tot].minx=x;
		end;
		if x-last==-1 then begin
			a[tot].rev=true;
		end;
		last=x;
	end;
	a[tot].R=n;
	if last<a[tot].minx then a[tot].minx=last;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot;

struct data begin
	int L,R,minx;
	bool rev;
end;

data a[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			a[tot].R=i-1;
			if last<a[tot].minx then a[tot].minx=last;
			a[++tot].L=i;
			a[tot].minx=x;
		end;
		if x-last==-1 then begin
			a[tot].rev=true;
		end;
		last=x;
	end;
	a[tot].R=n;
	if last<a[tot].minx then a[tot].minx=last;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot;

struct data begin
	int L,R,minx;
	bool rev;
end;

data a[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			a[tot].R=i-1;
			if last<a[tot].minx then a[tot].minx=last;
			a[++tot].L=i;
			a[tot].minx=x;
		end;
		if x-last==-1 then begin
			a[tot].rev=true;
		end;
		last=x;
	end;
	a[tot].R=n;
	if last<a[tot].minx then a[tot].minx=last;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>
#include <algorithm>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,tot1;

struct data begin
	int L,R,minx;
	bool rev;
end;

inline bool operator < (const data &a,const data &b)
begin
	return a.minx<b.minx;
end;

#define MOD 100003

int haL[MOD],haR[MOD];

inline int gethash(data *a)
begin
	int ret=2333;
	int i;
	for i=1;i<=tot;i++ do begin
		ret=(ret*123+a[i].L*456+a[i].R*789+a[i].minx*233+(a[i].L!=a[i].R && a[i].rev)*23333)%MOD;
	end;
	return ret;
end;

data a[25],b[25];

inline void reverse_b(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		b[i].rev^=1;
	end;
	int L=b[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=b[i],b[i]=b[j],b[j]=t;
	for i=l;i<=r;i++ do begin
		int len=b[i].R-b[i].L;
		b[i].L=L;b[i].R=L+len;
		L+=len+1;
	end;
end;

inline void pre()
begin
	int i,j;
	for i=1;i<=tot;i++ do b[i]=a[i];
	std::sort(b+1,b+tot+1);
	int L=1;
	for i=1;i<=tot;i++ do begin
		int len=b[i].R-b[i].L;
		b[i].L=L;b[i].R=L+len;
		L+=len+1;
		b[i].rev=0;
	end;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			reverse_b(i,j);
			int ha=gethash(b);
			if haL[ha] then printf("hhh\n");
			haL[ha]=b[i].L;haR[ha]=b[j].R;
			reverse_b(i,j);
		end;
	end;
end;

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	int ha=gethash(a);
	if haL[ha] then begin
		ok=true;
		opL[++dep]=haL[ha];
		opR[dep]=haR[ha];
		return;
	end;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			b[tot1].R=i-1;
			if last<b[tot1].minx then b[tot1].minx=last;
			b[++tot1].L=i;
			b[tot1].minx=x;
		end;
		if x-last==-1 then begin
			b[tot1].rev=true;
		end;
		last=x;
	end;
	b[tot1].R=n;
	if last<b[tot1].minx then b[tot1].minx=last;
	for i=1;i<=tot1;i++ do begin
		if b[i].L==b[i].R then begin
			a[++tot]=b[i];
		end else if b[i].L+1==b[i].R then begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+1,0};
			end;
		end else begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+b[i].R-b[i].L,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,1};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+b[i].R-b[i].L,0};
			end;
		end;
	end;
	pre();
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot;

struct data begin
	int L,R,minx;
	bool rev;
end;

data a[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;

	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			a[tot].R=i-1;
			if last<a[tot].minx then a[tot].minx=last;
			a[++tot].L=i;
			a[tot].minx=x;
		end;
		if x-last==-1 then begin
			a[tot].rev=true;
		end;
		last=x;
	end;
	a[tot].R=n;
	if last<a[tot].minx then a[tot].minx=last;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,dep;
bool ok;
int L[30],R[30];
int opL[5],opR[5];
int a[1005];

inline void reverse(int i,int j)
begin
	int t;
	while i<j do begin
		t=a[i];a[i]=a[j];a[j]=t;
		++i;--j;
	end;
end;

inline void dfs()
begin
	int i;
	for i=1;i<=n;i++ do begin
		if a[i]!=i then break;
	end;
	if i>n then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	for i=1;i<=tot;i++ do begin
		if L[i]==R[i] then continue;
		opL[dep]=L[i];opR[dep]=R[i];
		reverse(L[i],R[i]);
		dfs();
		if ok then return;
		reverse(L[i],R[i]);
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i,j;
	a[0]=-1;
	int cnt=0;
	for i=1;i<=n;i++ do begin
		scanf("%d",a+i);
		if a[i]-a[i-1]!=1 && a[i]-a[i-1]!=-1 then begin
			R[cnt]=i-1;L[++cnt]=i;
		end;
	end;
	R[cnt]=n;
	tot=cnt;
	for i=1;i<cnt;i++ do begin
		for j=i+1;j<=cnt;j++ do begin
			L[++tot]=L[i];R[tot]=R[j];
		end;
	end;
	dfs();
	printf("%d\n",dep);
	for i=dep;i>=1;i-- do begin
		printf("%d %d\n",opL[i],opR[i]);
	end;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,tot1;

struct data begin
	int L,R,minx;
	bool rev;
end;

data a[25],b[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			b[tot1].R=i-1;
			if last<b[tot1].minx then b[tot1].minx=last;
			b[++tot1].L=i;
			b[tot1].minx=x;
		end;
		if x-last==-1 then begin
			b[tot1].rev=true;
		end;
		last=x;
	end;
	b[tot1].R=n;
	if last<b[tot1].minx then b[tot1].minx=last;
	for i=1;i<=tot1;i++ do begin
		if b[i].L==b[i].R then begin
			a[++tot]=b[i];
		end else if b[i].L+1==b[i].R then begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+1,0};
			end;
		end else begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+b[i].R-b[i].L,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,1};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+b[i].R-b[i].L,0};
			end;
		end;
	end;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,tot1;

struct data begin
	int L,R,minx;
	int rev;
end;

data a[25],b[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			b[tot1].R=i-1;
			if last<b[tot1].minx then b[tot1].minx=last;
			b[++tot1].L=i;
			b[tot1].minx=x;
		end;
		if x-last==-1 then begin
			b[tot1].rev=true;
		end;
		last=x;
	end;
	b[tot1].R=n;
	if last<b[tot1].minx then b[tot1].minx=last;
	for i=1;i<=tot1;i++ do begin
		if b[i].L==b[i].R then begin
			a[++tot]=b[i];
		end else if b[i].L+1==b[i].R then begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+1,0};
			end;
		end else begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+b[i].R-b[i].L,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,1};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+b[i].R-b[i].L,0};
			end;
		end;
	end;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,dep;
bool ok;
int L[30],R[30];
int opL[5],opR[5];
int a[1005];

inline void reverse(int i,int j)
begin
	int t;
	while i<j do begin
		t=a[i];a[i]=a[j];a[j]=t;
		++i;--j;
	end;
end;

inline void dfs()
begin
	int i;
	for i=1;i<=n;i++ do begin
		if a[i]!=i then break;
	end;
	if i>n then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	for i=1;i<=tot;i++ do begin
		if L[i]==R[i] then continue;
		opL[dep]=L[i];opR[dep]=R[i];
		reverse(L[i],R[i]);
		dfs();
		if ok then return;
		reverse(L[i],R[i]);
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i,j;
	a[0]=-1;
	int cnt=0;
	for i=1;i<=n;i++ do begin
		scanf("%d",a+i);
		if a[i]-a[i-1]!=1 && a[i]-a[i-1]!=-1 then begin
			R[cnt]=i-1;L[++cnt]=i;
		end;
	end;
	R[cnt]=n;
	tot=cnt;
	for i=1;i<cnt;i++ do begin
		for j=i+1;j<=cnt;j++ do begin
			L[++tot]=L[i];R[tot]=R[j];
		end;
	end;
	dfs();
	printf("%d\n",dep);
	for i=1;i<=dep;i++ do begin
		printf("%d %d\n",opL[i],opR[i]);
	end;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,dep;
bool ok;
int L[25],R[25];
int opL[25],opR[25];
int a[1005];

inline void reverse(int i,int j)
begin
	int t;
	while i<j do begin
		t=a[i];a[i]=a[j];a[j]=t;
		++i;--j;
	end;
end;

inline void dfs()
begin
	int i;
	for i=1;i<=n;i++ do begin
		if a[i]!=i then break;
	end;
	if i>n then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	for i=1;i<=tot;i++ do begin
		if L[i]==R[i] then continue;
		opL[dep]=L[i];opR[dep]=R[i];
		reverse(L[i],R[i]);
		dfs();
		if ok then return;
		reverse(L[i],R[i]);
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i,j;
	a[0]=-1;
	int cnt=0;
	for i=1;i<=n;i++ do begin
		scanf("%d",a+i);
		if a[i]-a[i-1]!=1 && a[i]-a[i-1]!=-1 then begin
			R[cnt]=i-1;L[++cnt]=i;
		end;
	end;
	R[cnt]=n;
	tot=cnt;
	for i=1;i<cnt;i++ do begin
		for j=2;j<=cnt;j++ do begin
			L[++tot]=L[i];R[tot]=R[j];
		end;
	end;
	dfs();
	printf("%d\n",dep);
	for i=1;i<=dep;i++ do begin
		printf("%d %d\n",opL[i],opR[i]);
	end;
end


#include <stdio.h>
#include <string.h>
#include <algorithm>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,tot1;

struct data begin
	int L,R,minx;
	bool rev;
end;

inline bool operator < (const data &a,const data &b)
begin
	return a.minx<b.minx;
end;

#define MOD 100003

int haL[MOD],haR[MOD];
data *haA[MOD];

inline int gethash(data *a)
begin
	int ret=2333;
	int i;
	for i=1;i<=tot;i++ do begin
		ret=(ret*123+a[i].L*456+a[i].R*789+a[i].minx*233+(a[i].L!=a[i].R && a[i].rev)*23333)%MOD;
	end;
	return ret;
end;

data a[25],b[25],bb[25*300];

inline void reverse_b(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		b[i].rev^=1;
	end;
	int L=b[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=b[i],b[i]=b[j],b[j]=t;
	for i=l;i<=r;i++ do begin
		int len=b[i].R-b[i].L;
		b[i].L=L;b[i].R=L+len;
		L+=len+1;
	end;
end;

inline void pre()
begin
	int i,j;
	for i=1;i<=tot;i++ do b[i]=a[i];
	std::sort(b+1,b+tot+1);
	int L=1;
	for i=1;i<=tot;i++ do begin
		int len=b[i].R-b[i].L;
		b[i].L=L;b[i].R=L+len;
		L+=len+1;
		b[i].rev=0;
	end;
	data *top=bb;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			reverse_b(i,j);
			int ha=gethash(b);
			haL[ha]=b[i].L;haR[ha]=b[j].R;
			haA[ha]=top;top+=tot+1;
			memcpy(haA[ha]+1,b+1,tot*sizeof(data));
			reverse_b(i,j);
		end;
	end;
end;

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline bool cmp(data *b)
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev!=b[i].rev then return false;
	for i=1;i<=tot;i++ do if a[i].minx!=b[i].minx || a[i].L!=b[i].L || a[i].R!=b[i].R then return false;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	int ha=gethash(a);
	if haA[ha] && cmp(haA[ha]) then begin
		ok=true;
		opL[++dep]=haL[ha];
		opR[dep]=haR[ha];
		return;
	end;
	if dep==2 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			b[tot1].R=i-1;
			if last<b[tot1].minx then b[tot1].minx=last;
			b[++tot1].L=i;
			b[tot1].minx=x;
		end;
		if x-last==-1 then begin
			b[tot1].rev=true;
		end;
		last=x;
	end;
	b[tot1].R=n;
	if last<b[tot1].minx then b[tot1].minx=last;
	for i=1;i<=tot1;i++ do begin
		if b[i].L==b[i].R then begin
			a[++tot]=b[i];
		end else if b[i].L+1==b[i].R then begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+1,0};
			end;
		end else begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+b[i].R-b[i].L,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,1};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+b[i].R-b[i].L,0};
			end;
		end;
	end;
	pre();
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,tot1;

struct data begin
	int L,R,minx;
	bool rev;
end;

data a[25],b[10];

inline bool check()
begin
	int i;
	for i=1;i<=tot;i++ do if a[i].L!=a[i].R && a[i].rev then return false;
	for i=1;i<tot;i++ do begin
		if a[i].minx>a[i+1].minx then return false;
	end;
	return true;
end;

inline void reverse(int l,int r)
begin
	int i,j;
	for i=l;i<=r;i++ do begin
		a[i].rev^=1;
	end;
	int L=a[l].L;
	data t;
	for i=l,j=r;i<j;i++,j-- do t=a[i],a[i]=a[j],a[j]=t;
	for i=l;i<=r;i++ do begin
		int len=a[i].R-a[i].L;
		a[i].L=L;a[i].R=L+len;
		L+=len+1;
	end;
end;

int dep;
bool ok;
int opL[5],opR[5];

inline void dfs()
begin
	if check() then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	int i,j;
	for i=1;i<=tot;i++ do begin
		for j=i;j<=tot;j++ do begin
			if a[i].L==a[j].R then continue;
			opL[dep]=a[i].L;opR[dep]=a[j].R;
			reverse(i,j);
			dfs();
			if ok then return;
			reverse(i,j);
		end;
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i;
	int last=-1;
	for i=1;i<=n;i++ do begin
		int x;
		scanf("%d",&x);
		if x-last!=1 && x-last!=-1 then begin
			b[tot1].R=i-1;
			if last<b[tot1].minx then b[tot1].minx=last;
			b[++tot1].L=i;
			b[tot1].minx=x;
		end;
		if x-last==-1 then begin
			b[tot1].rev=true;
		end;
		last=x;
	end;
	b[tot1].R=n;
	if last<b[tot1].minx then b[tot1].minx=last;
	for i=1;i<=tot1;i++ do begin
		if b[i].L==b[i].R then begin
			a[++tot]=b[i];
		end else if b[i].L+1==b[i].R then begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end;
		end else begin
			if b[i].rev then begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx+b[i].R-b[i].L,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,1};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx,0};
			end else begin
				a[++tot]=(data){b[i].L,b[i].L,b[i].minx,0};
				a[++tot]=(data){b[i].L+1,b[i].R-1,b[i].minx+1,0};
				a[++tot]=(data){b[i].R,b[i].R,b[i].minx+b[i].R-b[i].L,0};
			end;
		end;
	end;
	dfs();
	printf("%d\n",dep);
	while dep do printf("%d %d\n",opL[dep],opR[dep]),--dep;
end


#include <stdio.h>

#define if if (
#define then )
#define do )
#define for for (
#define while while (
#define begin {
#define end }

int n,tot,dep;
bool ok;
int L[25],R[25];
int opL[25],opR[25];
int a[1005];

inline void reverse(int i,int j)
begin
	int t;
	while i<j do begin
		t=a[i];a[i]=a[j];a[j]=t;
		++i;--j;
	end;
end;

inline void dfs()
begin
	int i;
	for i=1;i<=n;i++ do begin
		if a[i]!=i then break;
	end;
	if i>n then begin
		ok=true;return;
	end;
	if dep==3 then return;
	++dep;
	for i=1;i<=tot;i++ do begin
		opL[dep]=L[i];opR[dep]=R[i];
		reverse(L[i],R[i]);
		dfs();
		if ok then return;
		reverse(L[i],R[i]);
	end;
	--dep;
end;

int main()
begin
	scanf("%d",&n);
	int i,j;
	a[0]=-1;
	int cnt=0;
	for i=1;i<=n;i++ do begin
		scanf("%d",a+i);
		if a[i]-a[i-1]!=1 && a[i]-a[i-1]!=-1 then begin
			R[cnt]=i-1;L[++cnt]=i;
		end;
	end;
	R[cnt]=n;
	tot=cnt;
	for i=1;i<cnt;i++ do begin
		for j=2;j<=cnt;j++ do begin
			L[++tot]=L[i];R[tot]=R[j];
		end;
	end;
	dfs();
	printf("%d\n",dep);
	for i=1;i<=dep;i++ do begin
		printf("%d %d\n",opL[i],opR[i]);
	end;
end


#include <bits/stdc++.h>
using namespace std;
int n,i,a[1111],L[11],R[11];
void dfs(int made){
    bool S=1;
    for(int i=1;i<=n;++i)
        if(a[i]!=i){
            S=0;
            break;
        }
    if(S){
        printf("%d\n",made);
        for(int i=made;i>=1;--i)printf("%d %d\n",L[i],R[i]);
        exit(0);
    }
    if(made>3)return;
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j)
            if((abs(a[i-1]-a[j])==1)||(abs(a[i]-a[j+1])==1)){
                L[made+1]=i,R[made+1]=j;
                reverse(a+i,a+j+1);
                dfs(made+1);
                reverse(a+i,a+j+1);
            }
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&a[i]);
    a[0]=0,a[n+1]=n+1;
    dfs(0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,i,a[1111],L[11],R[11];
void dfs(int made){
    if(made>3)return;
    bool S=1;
    for(int i=1;i<=n;++i)
        if(a[i]!=i){
            S=0;
            break;
        }
    if(S){
        printf("%d\n",made);
        for(int i=made;i>=1;--i)printf("%d %d\n",L[i],R[i]);
        exit(0);
    }
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j)
            if((abs(a[i-1]-a[j])==1)||(abs(a[i]-a[j+1])==1)){
                L[made+1]=i,R[made+1]=j;
                reverse(a+i,a+j+1);
                dfs(made+1);
                reverse(a+i,a+j+1);
            }
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&a[i]);
    a[0]=0,a[n+1]=n+1;
    dfs(0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1002;
int n,i,a[maxn],L[maxn],R[maxn];
void dfs(int made){
    if(made>3)return;
    bool S=1;
    for(int i=1;i<=n;++i)
        if(a[i]!=i){
            S=0;
            break;
        }
    if(S){
        printf("%d\n",made);
        for(int i=made;i>=1;--i)printf("%d %d\n",L[i],R[i]);
        exit(0);
    }
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j)
            if((abs(a[i-1]-a[j])==1)||(abs(a[i]-a[j+1])==1)){
                L[made+1]=i,R[made+1]=j;
                reverse(a+i,a+j+1);
                dfs(made+1);
                reverse(a+i,a+j+1);
            }
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&a[i]);
    a[0]=0,a[n+1]=n+1;
    dfs(0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1002;
int n,i,a[maxn],L[10],R[10];
void dfs(int made){
    if(made>3)return;
    bool S=1;
    for(int i=1;i<=n;++i)
        if(a[i]!=i){
            S=0;
            break;
        }
    if(S){
        printf("%d\n",made);
        for(int i=made;i>=1;--i)printf("%d %d\n",L[i],R[i]);
        exit(0);
    }
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j)
            if((abs(a[i-1]-a[j])==1)||(abs(a[i]-a[j+1])==1)){
                L[made+1]=i,R[made+1]=j;
                reverse(a+i,a+j+1);
                dfs(made+1);
                reverse(a+i,a+j+1);
            }
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&a[i]);
    a[0]=0,a[n+1]=n+1;
    dfs(0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,i,a[1111],L[11],R[11];
void dfs(int made){
    bool S=1;
    for(int i=1;i<=n;++i)
        if(a[i]!=i){
            S=0;
            break;
        }
    if(S){
        printf("%d\n",made-1);
        for(int i=made-1;i>0;--i)printf("%d %d\n",L[i],R[i]);
        exit(0);
    }
    if(made>3)return;
    for(int i=1;i<=n;++i)
        for(int j=i+1;j<=n;++j)
            if((abs(a[i-1]-a[j])==1)||(abs(a[i]-a[j+1])==1)){
                L[made]=i,R[made]=j;
                reverse(a+i,a+j+1);
                dfs(made+1);
                reverse(a+i,a+j+1);
            }
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&a[i]);
    a[0]=0,a[n+1]=n+1;
    dfs(1);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstdlib>
int a[1009],sz[10],l[4],r[4],n,m;
bool check()
{
	for (int i = 1; i <= n; ++i)
		if (a[i] != i) return false;
	return true;
}
void dfs(int step)
{
	if (check()) {
		printf("%d\n",step - 1);
		for (int i = 1; i < step; ++i) printf("%d %d\n",l[i],r[i]);
		exit(0);
	}
	if (step > 3) return;
	for (int i = 1,L = 1,R; i <= m; L += sz[i++]) {
		R = L + sz[i] - 1;
		for (int j = i; j <= m; R += sz[++j]) {
			std::reverse(a + L,a + R + 1);
			l[step] = L; r[step] = R;
			dfs(step + 1);
			std::reverse(a + L,a + R + 1);
		}
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("339E.in","r",stdin);
	freopen("339E.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) scanf("%d",&a[i]);
	for (int i = 1,t = 0; i <= n; ++i) {
		if (abs(t) != 1 || a[i] != a[i - 1] + t) ++m,t = a[i + 1] - a[i];
		++sz[m];
	}
	dfs(1);
}


#include <cstdio>
#include <algorithm>
#include <cstdlib>
int a[1009],sz[10],l[4],r[4],n,m;
bool check()
{
	for (int i = 1; i <= n; ++i)
		if (a[i] != i) return false;
	return true;
}
void dfs(int step)
{
	if (check()) {
		printf("%d\n",step - 1);
		for (int i = 1; i < step; ++i) printf("%d %d\n",l[step - i],r[step - i]);
		exit(0);
	}
	if (step > 3) return;
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			if (abs(a[i] - a[j + 1]) != 1 && abs(a[i - 1] - a[j]) != 1) continue;
			std::reverse(a + i,a + j + 1);
			l[step] = i; r[step] = j;
			dfs(step + 1);
			std::reverse(a + i,a + j + 1);
		}
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("339E.in","r",stdin);
	freopen("339E.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) scanf("%d",&a[i]);
	dfs(1);
}