#include <bits/stdc++.h>
using namespace std;


vector <int> v;


/*void rev(int l, int r) {
    for 
}*/


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n, c = 0;
	cin >> n;
    v.resize(n);
    vector < vector <int> > res;

    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    bool isSorted = false;
    while (isSorted == false) {
        int l = 0, r = 0;
        isSorted = true;

        for (int i = 1; i < n; i++) {
            r++;
            l++;
            //cout << l << " " << r << "\n"; //

            if (v[i] < v[i - 1]) {
                l--;
                isSorted = false;
            }
            else {
                if (r != l) {
                    c++; // C++
                    res.push_back({l, r});
                    //cout << l << " " << r << "\n"; //
                    reverse(v.begin() + l - 1, v.begin() + r);
                    /*for (int j = 0; j < v.size(); j++) {//
                        cout << v[j] << " ";
                    }
                    cout << "\n"; */
                }
                l = r;
            }
        }

        if (r != l) {
            c++; // C++
            res.push_back({l, r});
            //cout << l << " " << r << "\n"; //
            reverse(v.begin() + l, v.begin() + r + 1);
            /*for (int j = 0; j < v.size(); j++) {//
                cout << v[j] << " ";
            }
            cout << "\n"; */
        }
    }

    cout<< c <<"\n";

    for (int i = 0; i < res.size(); i++) {
        cout << res[i][0] << " " << res[i][1] << "\n";
    }
}
