#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 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();
    }

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

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