#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define mp make_pair
#define pb push_back

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

constexpr int INF = (int)1e18;
constexpr int N = (int)2e5 + 111;
constexpr int md = (int)1e9 + 7;
constexpr int p = (int)998244353;

vector<int> g[N];
vector<int> additional[N];

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

set<int> pos[32222];

int score(vector<pair<int,int>>& v){
    int s = 0;
    for(auto&[x,y] : v){
        s += y - x + 1;
    }
    return s;
}

vector<pair<int,int>> solve(int& n,vector<int> v,vector<int>& t){
    vector<pair<int,int>> ans;
    for(int i = 1; i <= n; i++){
        if(t[i] == v[i])
            continue;
        int p = -1;
        for(int j = i+1; j <= n; j++){
            if(v[j] == t[i]){
                p = j;
                break;
            }
        }
        assert(p != -1);
        reverse(v.begin()+i,v.begin()+p+1);
        ans.pb(mp(i,p));
    }
    if(t[1] > t[n])
        ans.pb(mp(1,n));

    return ans;
}

void solveBig(int& n,vector<int>& v){
    vector<int> t = v;
    sort(t.begin(),t.end());

    vector<pair<int,int>> ans1,ans2;
    ans1 = solve(n,v,t);
    sort(t.rbegin(),t.rend());
    ans2 = solve(n,v,t);

    if(score(ans2) < score(ans1))
        ans1 = ans2;

    cout << ans1.size() << "\n";
    for(auto&[x,y] : ans1)
        cout << x << " " << y << "\n";
    return;
}

int getHash(int& n,vector<int>& v){
    int cur = 0;
    for(int i = n; i > 0; i--){
        cur = (cur * p + v[i]) % md;
    }
    return cur;
}

gp_hash_table<int,int> d;
gp_hash_table<int,pair<int,int>> pr;

void solveBuble(int& n,vector<int>& v){
    vector<pair<int,int>> ans;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(v[i] > v[j]){
                swap(v[i],v[j]);
                ans.pb(mp(i,j));
            }
        }
    }
    cout << ans.size() << "\n";
    for(auto&[x,y] : ans)
        cout << x << " " << y << '\n';
    return;
}

void solve(){
    int n;
    cin >> n;
    vector<int> v(n+2,0);
    v[n+1] = INF;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    solveBuble(n,v);
    return;
    if(n >= 20){
        solveBig(n,v);
        return;
    }

    vector<int> t = v;
    sort(t.begin(),t.end());
    int goal = getHash(n,t);

    d[getHash(n,v)] = 0;
    set<pair<int,vector<int>>> q;
    q.insert(mp(0,v));
    vector<int> FF = v;

    while(!q.empty()){
        v = q.begin()->second;
        int cur = q.begin()->first;
        q.erase(q.begin());
        int curH = getHash(n,v);
//        for(auto& x : v){
//            cerr << x << " ";
//        }
//        cerr << "\n";
        if(curH == goal)
            break;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                reverse(v.begin()+i,v.begin()+j+1);
                int h = getHash(n,v);
                if(v != FF && (d[h] == 0 || d[h] > cur + j - i + 1)){
                    d[h] = cur + j - i + 1;
                    pr[h] = mp(i,j);
                    q.insert(mp(cur+j-i+1,v));
                }
                reverse(v.begin()+i,v.begin()+j+1);
            }
        }
    }

    vector<pair<int,int>> ans;
    while(pr[goal].first != 0){
        int l = pr[goal].first, r = pr[goal].second;
        reverse(t.begin()+l,t.begin()+r+1);
        goal = getHash(n,t);
        ans.pb(mp(l,r));
    }

    reverse(ans.begin(),ans.end());

    cout << ans.size() << "\n";
    for(auto&[x,y] : ans)
        cout << x << " " << y << "\n";

    return;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int tests = 1;
//    cin >> tests;
    for(int test = 1; test <= tests; test++){
        solve();
    }
    return 0;
}
/**
make VUDOI great again.

5
2 4 3 5 1
2 4 3 1 5
2 1 3 4 5
1 2 3 4 5


abcaabbaccccb
5
1 13
2 8
1 9
4 12
4 7

5 6
2 4 6 4 1 5
2 4 5 1 3 5
1 6 1 2 3 6
3 6 5 5 1 2
4 3 4 2 3 6

1 2 4 4 5 6
1 2 3 4 5 5
1 1 2 3 6 6
1 2 3 5 5 6
2 3 3 4 4 6

5
2 4 3 5 1
5 3 4 2 1


1 5 3 4 2
1 2 4 3 5
1 2 3 4 5

**/
