#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int short
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define m_p make_pair
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC target("avx,avx2")
using namespace std;
using namespace __gnu_pbds;
#define ordered set tree < int ,  null_type ,  less ,  rb_tree_tag ,  tree_order_statistics_node_update >
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//constexpr int N=2147483647;
//constexpr int INF=2147483647;
//constexpr int BIGINF=1e18;
//constexpr int N=500001;
//constexpr int mod=998244353;
int A[32001];
int B[320001];
int A0[32001];
ll cnt1=0, cnt2=0;
void rev(int l, int r)
{
    for(int i=0; i<=(r-l)/2; i++)
    {
        swap(A[l+i], A[r-i]);
    }
}
void solve()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>A[i];
        B[i]=A[i];
        A0[i]=A[i];
    }
    sort(B+1, B+n+1);
    vector<pair<int, int> >ans;
    vector<pair<int, int> >ans1;
    for(int i=1; i<=n; i++)
    {
        if(A[i]!=B[i])
        {
            int j=i;
            while(A[j]!=B[i])
                j++;
            rev(i, j);
            ans.pb({i, j});
            cnt1+=j-i+1;
        }
    }
    for(int i=1; i<=n; i++)
        A[i]=A0[i];
    for(int i=1; i<=n; i++)
    {
        if(A[i]!=B[i])
        {
            int j=n;
            while(A[j]!=B[i])
                j--;
            rev(i, j);
            ans1.pb({i, j});
            cnt2+=j-i+1;
        }
    }
    if(cnt1<cnt2)
    {
        cout<<ans.size()<<'\n';
        for(auto [i,j]:ans)
            cout<<i<<" "<<j<<'\n';
    } else
    {
        cout<<ans1.size()<<'\n';
        for(auto [i,j]:ans1)
            cout<<i<<" "<<j<<'\n';

    }

}
main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t=1;
//    cin>>t;
    while(t)
    {
        t--;
        solve();
    }
}
//5 8
//1 2
//1 3
//1 5
//2 3
//3 4
//4 1
//5 3
//5 2

