Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 296 ms):
/*
Author : MadhavCoding
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define in(n) int n; cin>>n;
#define inll(n) ll n; cin>>n;
#define in2(x, y) int x, y; cin>>x>>y;
#define inll2(x, y) ll x, y; cin>>x>>y;
#define ins(s) string s; cin>>s;
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define pb push_back
#define pbb pop_back()
#define endl "\n"
#define N 1e5
#define MOD 1e9+7

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

using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<ll, ll, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

template<class T> void _print(T t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); 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 << "]";}

int main(int argc, char const *argv[])
{

#ifndef ONLINE_JUDGE
	freopen("error.txt", "w", stderr);
#endif

ios::sync_with_stdio(0);
cin.tie(0);

int t = 1;
while(t--)
{
	inll(n);
	vll vec(n);
	for (int i = 0; i < n; i++)
	{
		cin>>vec[i];
	}
	debug(vec);

	vi vis(n+1);
	vpl res;

	for(int i = n-1; i >= 0; i--)
	{
		ll x = vec[i];
		for(int j = x - 1; j >= 1; j--) if(!vis[j])
		{
			res.pb({x, j});
		}
		for(int j = 1; j <= x - 1; j++) if(!vis[j])
		{
			res.pb({j, x});
		}
		for(int j = x + 1; j <= n; j++) if(!vis[j])
		{
			res.pb({j, x});
		}

		vis[x] = 1;
	}
	
	cout<<res.size()<<endl;
	for(auto p : res) cout<<p.first<<" "<<p.second<<endl;
}
return 0;
}

Solution 2 (runtime: 1109 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define F first
#define S second
#define B begin
#define RB rbegin
#define E end
#define RE rend
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll tt=1;
    // cin>>tt;
    while (tt--) {
        int n;
        cin>>n;
        vector<int>v(n);
        map<int,int>index;
        vector<pair<int,int>>ans;
        for (int i = 0; i < n; i++){
            cin>>v[i];
            index[v[i]]=i;
        }
        for (int i = 1; i <n; i++)
            for (int j = i+1; j <=n; j++)
                ans.push_back({j,i});
            
        for (int i = 0; i <n; i++)
        {
            for (int j = 1; j <=n; j++)
            {
                if(index[j]>i&&j>v[i])
                    ans.push_back({v[i],j});     
            }
        }
        cout<<ans.size()<<endl;
        for (auto [x,y] : ans)
        {
            cout<<x<<" "<<y<<endl;
        }
    }
    return 0;
}