//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define ull unsigned ll
#define ff first
#define ss second
#define int long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
using namespace std;
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18;
constexpr ll mod = 998244353;
const int MAXN = 1e5+10;
mt19937 rnd(time(nullptr));

struct treap{
	struct item{
	    item *l;
	    item *r;
	    int val, prior, cnt, max;
	    bool rev;
	    item(){}
	    item(int x){
	        val = x;
	        prior = rnd();
	        cnt = 1;
	        rev = 0;
	        l = nullptr;
	        r = nullptr;
	    }
	};
	typedef item *pitem;
	typedef pair < pitem, pitem > Pair;
	
	pitem rt = nullptr;
	
	int cnt(pitem v){
	    return v ? v->cnt : 0;
	}
	
	int max(pitem v){
	    return v ? v->max : 0;
	}
	
	void upd_cnt(pitem v){
	    if (v){
	    	v->cnt = cnt(v->l) + 1 + cnt(v->r);
	        v->max = std::max(max(v->l), std::max(v->val, max(v->r)));
	    }
	}
	
	void push(pitem v){
	    if (v && v->rev){
	        swap(v->l, v->r);
	        if (v->l) v->l->rev ^= 1;
	        if (v->r) v->r->rev ^= 1;
	        v->rev = 0;
	    }
	}
	
	pitem merge(pitem l, pitem r){
	    push(l);
	    push(r);
	    if (!l || !r) return l ? l : r;
	    
	    if (l->prior > r->prior){
	        l->r = merge(l->r, r);
	        upd_cnt(l);
	        return l;
	    }
	    else{
	        r->l = merge(l, r->l);
	        upd_cnt(r);
	        return r;
	    }
	}
	
	Pair split(pitem v, int k){
	    if (!v) return make_pair(nullptr, nullptr);
	    push(v);
	    if (k <= cnt(v->l)){
	        Pair t = split(v->l, k);
	        v->l = t.second;
	        upd_cnt(v);
	        return make_pair(t.first, v);
	    }
	    else{
	        Pair t = split(v->r, k - cnt(v->l) - 1);
	        v->r = t.first;
	        upd_cnt(v);
	        return make_pair(v, t.second);
	    }
	}
	
	void insert(pitem& v, int x, int pos){
	    Pair t = split(v, pos - 1);
	    pitem nd = new item(x);
	    v = merge(t.first, merge(nd, t.second));
	}
	
	void erase(pitem& v, int pos){
	    Pair t = split(v, pos - 1);
	    Pair q = split(t.second, 1);
	    v = merge(t.first, q.second);
	}
	
	int get(pitem& v, int l, int r){
	    Pair t = split(v, r);
	    Pair q = split(t.first, l - 1);
	    int res = max(q.second);
	    v = merge(q.first, merge(q.second, t.second));
	    return res;
	}
	
	void reverse(pitem& v, int l, int r){
	    Pair t = split(v, r);
	    Pair q = split(t.first, l - 1);
	    q.second->rev ^= true;
	    v = merge(q.first, merge(q.second, t.second));
	}
};

void sol1(int n, vector <int> &a){
	vector <pii> ans;
	while (n > 1){
		for (int i = 2; i <= n; ++i){
			if (a[i] < a[i-1]){
				swap(a[i], a[i-1]);
				ans.pb({i-1, i});
			}
		}
		--n;
	}
	cout << ans.size() << '\n';
	for (auto i : ans) cout << i.ff << " " << i.ss << '\n';
}

void solve(){
	int n;
	cin >> n;
	vector <int> a(n+1);
	for (int i = 1; i <= n; ++i) cin >> a[i];
	
	if (n <= 6000){
		sol1(n, a);
		return;
	}
	treap tr;
	for (int i = 1; i <= n; ++i) tr.insert(tr.rt, a[i], i);
	/*for (int i = 0; i < 800; ++i){
		int l = rnd() % n, r = rnd() % n;
		if (l > r) swap(l, r);
		tr.reverse(tr.rt, l + 1, r + 1);
	}*/
	return;
	vector <int> b = a;
	sort(all(b));
	
	vector <pii> ans;
	for (int i = n; i >= 1; --i){
		int v = tr.get(tr.rt, i, i);
		if (v == b[i]) continue;
		int l = 1, r = i;
		while (r - l > 1){
			int m = (l + r) / 2;
			if (tr.get(tr.rt, m, i) == b[i]) l = m;
			else r = m;
		}
		ans.pb({l, i});
		tr.reverse(tr.rt, l, i);
	}
	
	cout << ans.size() << '\n';
	for (auto i : ans) cout << i.ff << " " << i.ss << '\n';
}
 
signed main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    solve();
}