	#include <algorithm>
	#include <iostream>
	#include <cstdlib>
	#include <cstdarg>
	#include <cassert>
	#include <climits>
	#include <cstring>
	#include <complex>
	#include <cstdio>
	#include <vector>
	#include <string>
	#include <queue>
	#include <cmath>
	#include <ctime>
	#include <set>
	#include <map>
	#include <iomanip>
	#include <unordered_map>
	#include <bitset>
	#include<stack>
	#include <type_traits>
	#include <random>
	#include <chrono>
	//#define int long long
	using namespace std;
	long long a, b, c, d, e, f, g;
	long long h[1000005];
	long long pos[1000005];
	struct lol
	{
		int x, y;
	};
	vector<lol> v2;
	void solve()
	{
		cin >> a;
		for (int i = 1; i <= a; i++)
		{
			cin >> h[i];
			pos[h[i]] = i;
		}
		for (int i = 1; i <= a; i++)
		{
			if (h[i] != i)
			{
				int l = i;
				int r = pos[i];
				//cout << l << " " << r << '\n';
				v2.push_back({ l,r });
				while (l <= r)
				{
					swap(h[l], h[r]);
					pos[h[l]] = l;
					pos[h[r]] = r;
					l++;
					r--;
				}
				

			}
		}
		
		cout << v2.size()<<'\n';
		for (int i = 0; i < v2.size(); i++)
		{
			cout << v2[i].x << " " << v2[i].y << '\n';
		}
		
	}
	/*
	6
	3 3 3 3 4 5
	*/
	signed main() {
		int q = 1;
		//cin >> q;
		while (q != 0)
		{
			solve();
			q--;
		}
	}
