#include <bits/stdc++.h>

using namespace std;

int n;

mt19937 mt(time(nullptr));

vector<pair<int, int>> solve1(vector<int> a) {
    vector<pair<int, int>> ops;
    for (int i = 0; i < n; ++i) {
        auto it = min_element(a.begin() + i, a.end());
        if (a[i] == *it) continue;
        ops.push_back({i, it - a.begin()});
        reverse(a.begin() + i, it + 1);
    }
    return ops;
}

vector<pair<int, int>> solve2(vector<int> a) {
    vector<pair<int, int>> ops;
    for (int i = 0; i < 3; ++i) {
        int l = mt() % (a.size() - 1);
        int len = mt() % a.size();
        int r = min(int(a.size()) - 1, l + len);
        reverse(a.begin() + l, a.begin() + r + 1);
        ops.push_back({l, r});
    }
    for (int i = n - 1; i > 0; --i) {
        auto it = max_element(a.begin(), a.begin() + i + 1);
        if (a[i] == *it) continue;
        ops.push_back({it - a.begin(), i});
        reverse(it, a.begin() + i + 1);
    }
    return ops;
}

long long calc(vector<pair<int, int>>& ops) {
    long long res = 0;
    for (auto [l, r] : ops) {
        res += r - l + 1;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    vector<int> a(n);
    for (auto& i : a) cin >> i;

    auto res = solve2(a);

//    auto sol1 = solve1(a);
//    if (calc(sol1) < calc(res)) {
//        res = sol1;
//    }

    cout << res.size() << '\n';
    for (auto [l, r] : res) {
        cout << l + 1 << ' ' << r + 1 << '\n';
    }
    return 0;
}
