#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 32000+7;
int A[N];
bool vs[N];
vector<pair<int,int> > ans;
void rev(int l,int r){
    for(int i = 0;(i+1)*2<=(r-l+1);i+=1){
        swap(A[l+i],A[r-i]);
        swap(vs[l+i],vs[r-i]);
    }
}
void srt(int l,int r){
    if (l==r){
        return;
    }

    int mid = (l+r)/2;
    srt(l,mid);
    srt(mid+1,r);
    int pref = 0;
    while(mid-pref>=l && vs[mid-pref]){
        pref += 1;
    }
    int suf = 0;
    while(r-suf>mid && vs[r-suf]){
        suf += 1;
    }
    pref -= 1;
    pref = mid-pref;
    suf = r-suf;
    if (suf<=mid || pref>mid || pref>suf){
        return;
    }
    ans.push_back({pref,suf});
    rev(pref,suf);
}
void sol(int l,int r){
    if (l==r){
        return;
    }
    int mid = (l+r)/2;
    vector<pair<int,int> > V;
    for(int i = l;i<=r;i+=1){
        V.push_back({A[i],i});
        vs[i] = 1;
    }
    sort(V.begin(),V.end());

    for(int i = 0;i<=mid-l;i+=1){
        vs[V[i].second] = 0;
    }
    srt(l,r);
    sol(l,mid);
    sol(mid+1,r);
}
void solve(){
    int n;
    cin>>n;
    for(int i = 1;i<=n;i+=1){
        cin>>A[i];
    }
    sol(1,n);
    cout<<ans.size()<<endl;
    for(auto [l,r]:ans){
        cout<<l<<' '<<r<<endl;
    }
    for(int i = 2;i<=n;i+=1){
        if (A[i]<A[i-1]){
            assert(0);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
