#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve()
{
    int n;
    cin>>n;
    vector<int>a(n),b,c;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int cost=0;
    b=a;
    c=a;
    sort(b.begin(),b.end());
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            for(int j=i+1;j<n;j++)
            {
                if(a[j]==b[i])
                {
                    v.push_back({i+1,j+1});
                    reverse(a.begin()+i,a.begin()+j+1);
                    cost+=j-i+1;
                    break;
                }
            }
        }
    }
    if(cost<=2000000)
    {
        cout<<v.size()<<endl;
        for(auto [q,w]:v)cout<<q<<' '<<w<<endl;
        return;
    }
    v.clear();
    a=c;
    cost=0;
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=b[i])
        {
            for(int j=i-1;j>=0;j--)
            {
                if(a[j]==b[i])
                {
                    v.push_back({j+1,i+1});
                    cost+=i-j+1;
                    reverse(a.begin()+j,a.begin()+i+1);
                }
            }
        }
    }
    cout<<v.size()<<endl;
    for(auto [q,w]:v)cout<<q<<' '<<w<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);cin.tie(nullptr);
    solve();
}
