#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <iomanip>
#include <string>

using namespace std;

map<int,int> mp;
map<int,int> ind;
    
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> p;
    int b[n+1];
    for(int i = 0; i < n; i++)
    {
        cin>>b[i];
        p.push_back(b[i]);
        ind[b[i]] = i;
    }
    sort(p.begin(), p.end());
    if(p == a) 
    {
        cout<<0;
        return 0;
    }
    vector <pair<int,int>> res;
    for(int i = 0; i < n; i++)
    {
        int x;
        //cout<<p[i]<<" "<<b[i]<<'\n';
        if(b[i] != p[i])
        {
            for(int j = i; j < n; j++)
            {
                if(b[j] == p[i])
                {
                    x = j;
                }
            }
            res.push_back({i, x});
            vector<int> v;
            for(int j = i; j <= (i + x) / 2;  j++)
            {
                if(b[j] == b[j+1] - 1) 
                {
                    v.push_back(j);
                }
                swap(b[j], b[x - (j - i)]);
            }
            int er;
            if(v.size() > 0)
            {
                er = v[0];
            }
            for(int q = 1; q < v.size(); q++)
            {
                int l = er;
                while(v[q] == er + 1)
                {
                    q++;
                    er++;
                    if(q == v.size()) break;
                }
                if(er - l > 1) 
                {
                    res.push_back({l, er});
                    for(int j = l; j <= (l + er) / 2;  j++)
                    {
                        swap(b[j], b[er - (j - l)]);
                    }
                }
            }
        }
    }
    cout<<res.size()<<"\n";
    for(auto i : res)
    {
        cout<< i.first + 1<<" "<<i.second + 1<<'\n';
    }
}