#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <cstring>
#define endl '\n'

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    
    vector<ll>a(n);
    
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<ll>a2;
    a2 = a;
    
    reverse(a2.begin(), a2.end());
    
    ll cur = 1, last = 0;
    
    vector<pair<ll, ll>> ans;
    
    while(!is_sorted(a.begin(), a.end()) && cur < 32001 && last < n){
        //cout << last << endl;
        for(int i = last; i < n; i++){
            if(a[i] == cur){
                ll l = last, r = i;
                reverse(a.begin() + l, a.begin() + r + 1);
                
                ans.push_back({l, r});
                last++;
            }
        }
        cur++;
    }
    
    cur = -1;
    for(auto i: a2)
        cur = max(cur, i);
    
    last = 0;
    
    vector<pair<ll, ll>> ans2;
    
    while(cur > 0 && last < n){
        for(int i = last; i < n; i++){
            if(a2[i] == cur){
                ll l = last, r = i;
                reverse(a2.begin() + l, a2.begin() + r + 1);
                
                ans2.push_back({l, r});
                last++;
            }
        }
        cur--;
    }
    ans2.push_back({0, n - 1});
    
    if(ans.size() < ans2.size()){
        cout << ans.size() << endl;
    
        for(auto i: ans)
            cout << i.first + 1 << ' ' << i.second + 1 << endl;
    }
    else{
        cout << ans2.size() << endl;
    
        for(auto i: ans2)
            cout << i.first + 1 << ' ' << i.second + 1 << endl;
    }
    
    return 0;
}
