#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n;
	cin>>n;
    int arr[n];
    set<pair<int,int> > ind;
    for (int i=0; i<n; ++i){
        cin>>arr[i];
        ind.insert({arr[i]-1, i});
    }
    // sort(arr, arr+n);
    vector<int> s;
    vector<pair<int,int> > res;
    int q=0, i=0;
    for (auto x: ind){
        x.first=i++;
        if (q>0){
            // cout<<x.second<<' ';
            int lower=s.end()-lower_bound(s.begin(), s.end(), x.second);
            // cout<<lower<<'\n';
            if (x.second+lower!=x.first){
                s.insert(upper_bound(s.begin(), s.end(), x.second) , x.second);
                ++q;
                res.push_back({x.first+1, x.second+lower+1});
                if (x.second+lower-x.first>1){
                    res.push_back({x.first+2, x.second+lower+1});
                }
            }
            // return 0;
        }
        else if (x.first!=x.second){
            ++q;
            s.push_back(x.second);
            res.push_back({x.first+1, x.second+1});
            if (x.second-x.first>1){
                res.push_back({x.first+2, x.second+1});
            }
        }
    }
    cout<<res.size()<<'\n';
    for (auto x: res){
        cout<<x.first<<' '<<x.second<<'\n';
    }
}
