#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,tune=native")

#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <numeric>
#include <map>
#include <cassert>
#include <algorithm>
#include <random>
#include <stack>

using namespace std;

#define int long long
#define se second
#define fi first

vector<int> t(4 * 32001);

void update(int v, int tl, int tr, int pos)
{
	if (tl == tr && tr == pos)
	{
		++t[v];
		return;
	}
	int tm = (tl + tr) >> 1;
	if (tm >= pos) update(2 * v, tl, tm, pos);
	else update(2 * v + 1, tm + 1, tr, pos);
	t[v] = (t[2 * v + 1] + t[2 * v]);
}

int getm(int l, int r, int v, int tl, int tr)
{
	if (l > tr || r < tl) return 0;
	if (l <= tl && r >= tr) return t[v];
	int tm = (tl + tr) >> 1;
	return (getm(l, min(r, tm), 2 * v, tl, tm) + getm(max(l, tm + 1), r, 2 * v + 1, tm + 1, tr));
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& i : a) cin >> i;
	vector<pair<int, int>> res;
	update(1, 0, 32000, a[0]);
	for (int i = 1; i < n; ++i)
	{
		int pos = getm(1, a[i], 1, 0, 32000);
		if (pos + 1 < i + 1) res.push_back({ pos + 1, i + 1 });
		if (pos + 2 < i + 1) res.push_back({ pos + 2, i + 1 });
		update(1, 0, 32000, a[i]);
	}
	cout << res.size() << '\n';
	int ans = 0;
	for (int i = 0; i < res.size(); ++i) cout << res[i].first << " " << res[i].second << '\n';
	int ans = 0;
	for (int i = 0; i < res.size(); ++i) ans += -res[i].first + res[i].second + 1;
	assert(ans <= 512000000);
	return 0;
}
