#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 32000+7;
int A[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]);
    }
}
void srt(int l,int r,int cmp){
    if (l==r){
        return;
    }

    int mid = (l+r)/2;
    srt(l,mid,cmp);
    srt(mid+1,r,cmp);
    int pref = 0;
    while(mid-pref>=l && A[mid-pref]>cmp){
        pref += 1;
    }
    int suf = 0;
    while(r-suf>mid && A[r-suf]>cmp){
        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<int> V;
    for(int i = l;i<=r;i+=1){
        V.push_back(A[i]);
    }
    sort(V.begin(),V.end());
    int spl = V[0];
    for(int i = 0;i<=mid-l;i+=1){
        if (i+1<V.size() && V[i]!=V[i+1]){
            spl = V[i];
        }
    }
    srt(l,r,spl);
    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;
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
