#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    long int n;
    cin >> n;

    vector <long int> a(n);
    vector <long int> is(n);

    long int mn = 1000000;
    for (long int i=0;i<n;i++)
        {
            cin >> a[i];
            is[a[i]]++;
            if (a[i] < mn)
                mn = a[i];
        }


    /* for (long int i=0;i<n;i++)
     {
         cout << is[a[i]] << " ";
     }
     cout << endl;*/

     long int j = 1;
     long int pos = mn;
     long int k = 0;
     vector  < pair <long int, long int> > mas;

     while (j != n)
     {
     //  cout << "is a pos - " << is[pos] << " ";
       if (is[pos] > 0)
       {
         // cout << "pos = " << pos << endl;
          vector<long int>::iterator it = find(a.begin()+k, a.end(), pos);
          if (k != it-a.begin())
          {
              mas.push_back({k+1, it-a.begin()+1});
        //     cout << k+1 << " " << it-a.begin()+1 << endl;
          reverse( a.begin()+k, it+1);

        // for (long int i=0;i<n;i++)
         //  cout << a[i] << " ";
         // cout << endl;
          k++;
          j++;
      //   cout << j << endl;
          is[pos]-=1;
          }
          else
            {
                pos++;
                k++;
                j++;
            }
       }
       else
        pos++;
     }

     cout << mas.size() << endl;

     for (long int i=0;i<mas.size();i++)
     {
         cout << mas[i].first << " " << mas[i].second << endl;
     }

}
// 2 4 3 5 1
