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

#define DIM 32007

typedef long long ll;
typedef long double ld;


ll n, a[DIM], rs1, rs2, l, r, sum1, sum2;
vector<ll> v;
pair<ll, ll> res[2*DIM], res2[2*DIM];

ll bin(ll l, ll r, ll x){
    ll m = 0;
    while(l<r){
        m = (l+r+1)/2;
        if(v[m]>x) r = m-1;
        else l = m;
    }
    if(v[l]<x && v[l]!=0) l++;
    if(l!=0 && v[l-1] >=x) l--;
    return l;
}


int main(){
    
    cin>>n;
    
    for(int i=1;i<=n;i++){
        cin>>a[i];
        
    }
    rs1 = 0;
    sum1=0;
    sum2=0;
    v.insert(v.begin(), a[1]);
    for(int i = 2; i<=n;i++){
        l = bin(0, i-2, a[i]);
        v.insert(v.begin()+l, a[i]);
        
        r = i;
        l +=1;

        
        if(r-l>=1){
            rs1++;
            sum1+=r-l+1;
            res[rs1] = {l, r};
        }
        l+=1;
        
        if(r-l>=1){
            sum1+=r-l+1;
            rs1++;
            res[rs1] = {l, r};
        }
    }
    
    /*
    
    reverse(a+1, a+1+n);
    
    rs2 = 1;
    res2[1] = {1, n};
    sum2+=n;
    
    v.clear();
    v.insert(v.begin(), a[1]);
    for(int i = 2; i<=n;i++){
        l = bin(0, i-2, a[i]);
        v.insert(v.begin()+l, a[i]);
        
        r = i;
        l +=1;
        
        
        
        
        
        if(r-l>=1){
            sum2+=r-l+1;
            rs2++;
            res2[rs2] = {l, r};
        }
        l+=1;
        
        if(r-l>=1){
            sum2+=r-l+1;
            rs2++;
            res2[rs2] = {l, r};
        }
    }
     */
    sum1=sum2;
    
    if(sum1<=sum2){
        cout<<rs1<<endl;
        
        for(int i=1;i<=rs1;i++){
            cout<<res[i].first<<" "<<res[i].second<<endl;
        }
    }
    
    else{
        cout<<rs2<<endl;
        
        for(int i=1;i<=rs2;i++){
            cout<<res2[i].first<<" "<<res2[i].second<<endl;
        }
    }
    
    
    
    return 0;
}
