#include <bits/stdc++.h>
using namespace std;

vector<int> a;
vector<pair<int,int>> journal;
void reverse(int f,int s) {
    for(int i = 0; i < (s - f+1) / 2; i++) {
        swap(a[f+i],a[s-i]);
    }
}
void dp(int l, int r) {
    if(l == r) return;
    int f,s;
    while(true) {
        int m = (l + r)/2;
        f = -1;
        s = -1;
        vector <int> xx;
        for(int i = l; i <= r; i++) {
            xx.push_back(a[i]);
        }
        sort(xx.begin(), xx.end());
        int m2 = xx[(xx.size())/2];
        for(int i = l; i <= m; i++) {
            if(a[i] > m2) {f = i; break;}
        }
        for(int i = r; i > m; i--) {
            if(a[i] <= m2) {s = i; break;}
        }
        if(f == -1 && s == -1) {
            dp(l,m);
            dp(m+1,r);
            return;
        }
        journal.push_back({f,s});
        reverse(f, s);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    a.push_back(0);
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    dp(1, n);
    cout << journal.size() << '\n';
    for(int i =0;i < journal.size(); i++) {
        cout << journal[i].first << ' ' << journal[i].second << "\n";
    }
}
