#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pll pair<ll, ll>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> yree;
const ll inf = 0x3fff3fff3fff3fff;
const ll N = 5e5+20;
namespace algo1{
    vector<pll> ops;
    ll solve(ll n, vector<ll> a, bool add=false){
        ll len = 0;
        ll l=0, r=0;
        for(ll it=0;it<n;it++){
            auto j = min_element(a.begin()+l, a.end()-r);
            if(add) ops.emplace_back(l, j-a.begin());
            len+=j-a.begin()-l+1;
            reverse(a.begin()+l, j+1);
            ++l;
        }
        if(add){
            cout<<ops.size()<<'\n';
            for(auto [i, j] : ops) cout<<i+1<<' '<<j+1<<'\n';
        }
        return len;
    }
}
namespace algo2{
    vector<pll> ops;
    ll solve(ll n, vector<ll> a, bool add=false){
        ll len = 0;
        ll l=0, r=0;
        for(ll it=0;it<n;it++){
            auto j = max_element(a.begin()+l, a.end()-r);
            if(add) ops.emplace_back(j-a.begin(), n-r-1);
            len+=a.end()-r-j;
            reverse(j, a.end()-r);
            ++r;
        }
        if(add){
            cout<<ops.size()<<'\n';
            for(auto [i, j] : ops) cout<<i+1<<' '<<j+1<<'\n';
        }
        return len;
    }
}
namespace algo3{
    vector<pll> ops;
    ll solve(ll n, vector<ll> a, bool add=false){
        ll len = 0;
        ll l=0, r=0;
        for(ll it=0;it<n;it++){
            if(it&1){
                auto j = max_element(a.begin()+l, a.end()-r);
                if(add) ops.emplace_back(j-a.begin(), n-r-1);
                len+=a.end()-r-j;
                reverse(j, a.end()-r);
                ++r;
            }else{
                auto j = min_element(a.begin()+l, a.end()-r);
                if(add) ops.emplace_back(l, j-a.begin());
                len+=j-a.begin()-l+1;
                reverse(a.begin()+l, j+1);
                ++l;
            }
        }
        if(add){
            cout<<ops.size()<<'\n';
            for(auto [i, j] : ops) cout<<i+1<<' '<<j+1<<'\n';
        }
        return len;
    }
}
signed main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    assert(n<=4000);
    vector<ll> a(n);
    copy_n(istream_iterator<ll>(cin), n, a.begin());
    ll r1 = algo1::solve(n, a, true);
    //ll r2 = algo2::solve(n, a);
    //ll r3 = algo3::solve(n, a);
    /*if(r1 <= r2 && r1 <= r3)        algo1::solve(n, a, true);
    else if(r2 <= r1 && r2 <= r3)   algo2::solve(n, a, true);
    else if(r3 <= r2 && r3 <= r1)   algo3::solve(n, a, true);*/
}
