#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("avx2")

using namespace std;

#define x first
#define y second
#define pb push_back
#define all(a) a.begin(),a.end()
#define int long long

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef vector<ll>vll;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<vi>vvi;
typedef vector<vll>vvll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;

const int N=32000,mod=1e9+7;
const char nl='\n';

int a[N],b[N],c[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        b[i]=c[i]=a[i];
    }
    sort(b+1,b+n+1);
    vpii ans;
    int sum=0;
    for(int i=1;i<=n;++i){
        if(a[i]==b[i]){
            continue;
        }
        for(int j=i+1;j<=n;++j){
            if(a[j]==b[i]){
                reverse(a+i,a+j+1);
                ans.pb({i,j});
                sum+=j-i+1;
            }
        }
    }
    vpii anss;
    int summ=0;
    for(int i=1;i<=n;++i){
        if(c[i]==b[i]){
            continue;
        }
        for(int j=n;j>=i+1;--j){
            if(c[j]==b[i]){
                reverse(c+i,c+j+1);
                anss.pb({i,j});
                summ+=j-i+1;
            }
        }
    }
    if(sum<summ){
        cout<<ans.size()<<nl;
        for(auto[i,j]:ans){
            cout<<i<<' '<<j<<nl;
        }
    }
    else{
        cout<<anss.size()<<nl;
        for(auto[i,j]:anss){
            cout<<i<<' '<<j<<nl;
        }
    }
}
