#include <bits/stdc++.h>

#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define watch(x) cout << (#x) << " : " << x << '\n'
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector <int> pos(n); iota(all(pos), 0);
    sort(all(pos), [&a](const auto &x, const auto &y) -> bool {
        return a[x] < a[y];
    });
    int stA[n];
    for (int i = 0; i < n; i++)
        stA[i] = a[i];
    int need[n];
    for (int i = 0; i < n; i++)
        need[i] = a[pos[i]];
    vector < pair<int, int> > ans;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (need[i] == a[j]) {
                ans.push_back({i, j});
                break;
            }
        }
        if (ans.back().first != ans.back().second)
            reverse(a + ans.back().first, a + ans.back().second + 1);
        else
            ans.pop_back();
    }

    for (int i = 0; i < n; i++) a[i] = stA[i];

    vector < pair<int, int> > ans2;
    for (int i = n-1; i >= 0; i--) {
        for (int j = i; j >= 0; j--) {
            if (need[i] == a[j]) {
                ans2.push_back({j, i});
                break;
            }
        }
        if (ans2.back().first != ans2.back().second)
            reverse(a + ans2.back().first, a + ans2.back().second + 1);
        else
            ans2.pop_back();
    }

    vector < pair <int, int> > ans3;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (need[i] == a[j]) {
                ans3.push_back({j, n-1});
                ans3.push_back({i, n-1});
                break;
            }
        }

        if (ans3.back().first != ans3.back().second)
            reverse(a + ans3.back().first, a + ans3.back().second + 1);
        if (ans3[ans3.size() - 2].first != ans3[ans3.size() - 2].second)
            reverse(a + ans3[ans3.size() - 2].first, a + ans3[ans3.size() - 2].second + 1);
    }

    ll f = 0, s = 0, t = 0;
    for (auto [l, r] : ans) f += (r - l + 1);
    for (auto [l, r] : ans2) s += (r - l + 1);
    for (auto [l, r] : ans3) t += (r - l + 1);
    if (s < t && s < f) swap(ans2, ans);
    if (t < s && t < f) swap(ans3, ans);

    cout << (int) ans.size() << '\n';
    for (auto [l, r] : ans)
        cout << l+1 << ' ' << r+1 << '\n';
}

main () {
    boost;
    solve();
    return 0;
}
