Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
#include<numeric>
using namespace std;


#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define srt(v) sort(all(v))

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll>> vvl;
typedef set<ll> sl;
typedef queue<ll> ql;
typedef queue<pll> qpll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef unordered_map<string, ll> umsl;
typedef unordered_map<ll, char> umlc;
typedef unordered_map<char, ll> umcl;

#define min_heap priority_queue<ll, vector<ll>, greater<ll>>
#define max_heap priority_queue<ll>


#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

static const int inf=1e9;

ll gcd(ll a, ll b) { if(b==0) return a; while (b) { a = a % b; swap(a, b);}return a;}
ll lcm(ll a,ll b){ return a*b/gcd(a,b);}
ll maxSubarraySum(vector<ll> a,ll l,ll r){ ll mx=LONG_MIN,sum=0;for(int i=l;i<=r;i++){sum+=a[i];if(sum>mx) mx=sum;if(sum<0) sum=0;}return mx;}
ll minSubarraySum(vector<ll> a,ll l,ll r){ for(int i=l;i<=r;i++) a[i]=-a[i];ll mx=LONG_MIN,sum=0;for(int i=l;i<=r;i++){sum+=a[i];if(sum>mx) mx=sum;if(sum<0) sum=0;}return mx;}
ll binarySearch(const vl& arr,ll target) {int l=0,r=arr.size() - 1; while (l<=r) { ll mid = l + (r - l) / 2;  if (arr[mid] == target) return mid; else if (arr[mid] < target)l= mid + 1; else r = mid - 1;  } return -1; }

ll mod_add(ll x,ll y,ll m){ return ((x%m+y%m)+m)%m;}
ll mod_sub(ll x,ll y,ll m){ return ((x%m-y%m)+m)%m;}
ll mod_mul(ll x,ll y,ll m){ return ((x%m)*(y%m))%m;}

ll binpow(ll x,ll y){ ll res=1; while(y){ if(y&1){ res=mod_mul(res,x,MOD);} x=mod_mul(x,x,MOD); y>>=1;}return res; }
ll inv(ll x,ll mod){ return binpow(x,mod-2);}
ll mod_div(ll x,ll y,ll m){ return mod_mul(x,inv(y,m),m);}

ll combination1(ll n,ll r,vl& fact,vl& ifact,ll m){
	return mod_mul(fact[n],mod_mul(ifact[n-r],ifact[r],m),m);
}
void fact(){
	ll n=1e6+1;
	vl fact(n);
	vl ifact(n);
	fact[0]=1;
	for(ll i=1;i<=n;i++){
		fact[i]=mod_mul(fact[i-1],i,MOD);
		// ifact[i]=binpow(fact[i],MOD-2);
	}
	ifact[n]=binpow(fact[n],MOD-2);

	// using property ifact[n-1]=ifact[n]*n
	for(ll i=n-1;i>=0;i--){
		ifact[i]=mod_mul(fact[i+1],i+1,MOD);
	}
}
template <class T> bool ckmax(T &a, T b) {return a<b ? a=b, true : false;}

int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};;

bool comp1(const pll& a,const pll& b){
    if(a.ff==b.ff) return a.ss < b.ss;
    return a.ff < b.ff;
}

ll dp[(int)3e5+5];

void solve(){
	int n; cin>>n;
	vector<int> c(n);
	for(int i=0;i<n;i++) cin>>c[i];
	vector<pair<int,int>> ans;
	for(int i=n;i>=1;i--){
		for(int j=i-1;j>=1;j--) ans.pb({i,j});
	}
	vector<int> t(n);
	for(int i=0;i<n;i++) t[i]=n-i;
	for(int i=0;i<n;i++){
		int val=c[i];
		int pos=i;
		int r=n-c[i];
		for(int j=r;j>pos;j--){
			// cout<<val<<' '<<t[j-1]<<'\n';
			ans.pb({val,t[j-1]});
			swap(t[j],t[j-1]);
		}

	}
	cout<<ans.size()<<'\n';
	for(auto it:ans){
		cout<<it.ff<<' '<<it.ss<<'\n';
	}
}

int main(){

#ifndef ONLINE_JUDGE
	freopen("Error.txt","w",stderr);
#endif
	// int t; cin>>t;
	// while(t--) solve();
	solve();
	
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#include<numeric>
using namespace std;


#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define srt(v) sort(all(v))

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll>> vvl;
typedef set<ll> sl;
typedef queue<ll> ql;
typedef queue<pll> qpll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef unordered_map<string, ll> umsl;
typedef unordered_map<ll, char> umlc;
typedef unordered_map<char, ll> umcl;

#define min_heap priority_queue<ll, vector<ll>, greater<ll>>
#define max_heap priority_queue<ll>


#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

static const int inf=1e9;

ll gcd(ll a, ll b) { if(b==0) return a; while (b) { a = a % b; swap(a, b);}return a;}
ll lcm(ll a,ll b){ return a*b/gcd(a,b);}
ll maxSubarraySum(vector<ll> a,ll l,ll r){ ll mx=LONG_MIN,sum=0;for(int i=l;i<=r;i++){sum+=a[i];if(sum>mx) mx=sum;if(sum<0) sum=0;}return mx;}
ll minSubarraySum(vector<ll> a,ll l,ll r){ for(int i=l;i<=r;i++) a[i]=-a[i];ll mx=LONG_MIN,sum=0;for(int i=l;i<=r;i++){sum+=a[i];if(sum>mx) mx=sum;if(sum<0) sum=0;}return mx;}
ll binarySearch(const vl& arr,ll target) {int l=0,r=arr.size() - 1; while (l<=r) { ll mid = l + (r - l) / 2;  if (arr[mid] == target) return mid; else if (arr[mid] < target)l= mid + 1; else r = mid - 1;  } return -1; }

ll mod_add(ll x,ll y,ll m){ return ((x%m+y%m)+m)%m;}
ll mod_sub(ll x,ll y,ll m){ return ((x%m-y%m)+m)%m;}
ll mod_mul(ll x,ll y,ll m){ return ((x%m)*(y%m))%m;}

ll binpow(ll x,ll y){ ll res=1; while(y){ if(y&1){ res=mod_mul(res,x,MOD);} x=mod_mul(x,x,MOD); y>>=1;}return res; }
ll inv(ll x,ll mod){ return binpow(x,mod-2);}
ll mod_div(ll x,ll y,ll m){ return mod_mul(x,inv(y,m),m);}

ll combination1(ll n,ll r,vl& fact,vl& ifact,ll m){
	return mod_mul(fact[n],mod_mul(ifact[n-r],ifact[r],m),m);
}
void fact(){
	ll n=1e6+1;
	vl fact(n);
	vl ifact(n);
	fact[0]=1;
	for(ll i=1;i<=n;i++){
		fact[i]=mod_mul(fact[i-1],i,MOD);
		// ifact[i]=binpow(fact[i],MOD-2);
	}
	ifact[n]=binpow(fact[n],MOD-2);

	// using property ifact[n-1]=ifact[n]*n
	for(ll i=n-1;i>=0;i--){
		ifact[i]=mod_mul(fact[i+1],i+1,MOD);
	}
}
template <class T> bool ckmax(T &a, T b) {return a<b ? a=b, true : false;}

int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};;

bool comp1(const pll& a,const pll& b){
    if(a.ff==b.ff) return a.ss < b.ss;
    return a.ff < b.ff;
}

ll dp[(int)3e5+5];

void solve(){
	int n; cin>>n;
	vector<int> c(n);
	for(int i=0;i<n;i++) cin>>c[i];
	vector<pair<int,int>> ans;
	for(int i=n;i>=1;i--){
		for(int j=i-1;j>=1;j--) ans.pb({i,j});
	}
	vector<int> t(n);
	for(int i=0;i<n;i++) t[i]=n-i;
	vector<int> p(n+1);
	for(int i=0;i<n;i++){
		p[t[i]]=i;
	}
	for(int i=0;i<n;i++){
		int val=c[i];
		int pos=i;
		int r=p[i+1];
		for(int j=r;j>pos;j--){
			// cout<<val<<' '<<t[j-1]<<'\n';
			ans.pb({val,t[j-1]});
			swap(t[j],t[j-1]);
		}
		for(int j=0;j<n;j++) p[t[j]]=j;

	}
	cout<<ans.size()<<'\n';
	for(auto it:ans){
		cout<<it.ff<<' '<<it.ss<<'\n';
	}
}

int main(){

#ifndef ONLINE_JUDGE
	freopen("Error.txt","w",stderr);
#endif
	// int t; cin>>t;
	// while(t--) solve();
	solve();
	
}