#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> a;
vector<pair<int, int> > ans;
vector<int> seO;
map<vector<int>, int> dist;
map<vector<int>, pair<int, int> > TO;

void PRNT() {

//    cout << "COME" << endl;
    while (true) {
        if (TO.count(a) == 0)break;
        ans.push_back(TO[a]);
        int F = TO[a].first, S = TO[a].second;
//        cout << F << " " << S << " << " << endl;
//        for (auto i : a)cout << i << " ";
//        cout << endl;
        reverse(a.begin() + F, a.begin() + S + 1);
//        for (auto i : a)cout << i << " ";
//        cout << endl;
    }
    cout << ans.size() << '\n';
    for (auto [i, j] : ans)
        cout << i + 1 << " " << j + 1 << '\n';
}

int main()
{
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        seO.push_back(a[i]);
    }
    sort(seO.begin(), seO.end());

    priority_queue<pair<int, vector<int> > > q;
    q.push({0, seO});
    dist[seO] = 0;
    while (!q.empty()) {
        auto [cst, v] = q.top();
        q.pop();
        for (int i = 0; i < v.size(); i++) {
            vector<int> to = v;
            for (int j = 1;; j++) {
                if (i - j < 0 || i + j >= to.size())break;
                swap(to[i - j], to[i + j]);

//                cout << " <<<  " << endl;
//                for (auto i : v)cout << i << " ";
//                cout << " ---> ";
//                for (auto i : to)cout << i << " ";
//                cout << endl;
                if (dist.count(to) == 0) {
                    dist[to] = dist[v] + 2*j + 1;
                    q.push({-dist[to], to});

                    TO[to] = {i - j, i + j};
                    if (to == a){PRNT();return 0;}
                } else if (dist[to] > dist[v] + 2*j + 1) {
                    dist[to] = dist[v] + 2*j + 1;
                    q.push({-dist[to], to});

                    TO[to] = {i - j, i + j};
                    if (to == a){PRNT();return 0;}
                }
            }
            to = v;

            for (int j = 0;; j++) {
                if (i - j < 0 || i + j + 1 >= to.size())break;
                swap(to[i - j], to[i + j + 1]);

//                cout << " <<<  " << endl;
//                for (auto i : v)cout << i << " ";
//                cout << " ---> ";
//                for (auto i : to)cout << i << " ";
//                cout << endl;
                if (dist.count(to) == 0) {
                    dist[to] = dist[v] + 2*j + 2;
                    q.push({-dist[to], to});

                    TO[to] = {i - j, i + j + 1};
                    if (to == a){PRNT();return 0;}
                } else if(dist[to] > dist[v] + 2*j + 2) {
                    dist[to] = dist[v] + 2*j + 2;
                    q.push({-dist[to], to});

                    TO[to] = {i - j, i + j + 1};
                    if (to == a){PRNT();return 0;}
                }
            }
        }
    }
}
/**
5
2 4 3 5 1
1 5 3 4 2
1 2 4 3 5
1 2 3 4 5
*/
