#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    vector<int> k = v;
    vector<int> hh = v;
    sort(k.begin(), k.end());
    vector<string> ans1;
    int min1 = 0;
    for (int i = 0; i < n; i++) {
        int f = k[i];
        int id = std::find(v.begin() + i, v.end(), f) - v.begin();
        ans1.push_back((to_string(i + 1) + " " + to_string((id + 1))));
        min1 += abs(id - i) + 1;
        reverse(v.begin() + i, v.begin() + id + 1);
    }
    sort(k.rbegin(), k.rend());
    v = hh;
    vector<string> ans2;
    int min2 = 0;
    for (int i = 0; i < n; i++) {
        int f = k[i];
        int id = std::find(v.begin() + i, v.end(), f) - v.begin();
        ans2.push_back((to_string(i + 1) + " " + to_string((id + 1))));
        min2 += abs(id - i) + 1;
        reverse(v.begin() + i, v.begin() + id + 1);
    }
    ans2.push_back(to_string(1) + " " + to_string(hh.size()));
    min2 += hh.size()-1 + 1;

    if (min1 < min2) {
        cout << ans1.size() << endl;
        for (int d = 0; d < ans1.size(); d++)
            cout << ans1[d] << endl;
    } else {
        cout << ans2.size() << endl;
        for (int d = 0; d < ans2.size(); d++)
            cout << ans2[d] << endl;
    }
}
