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

Solution 1 (runtime: 1311 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    int n;
    cin >> n;

    vector<int> final_order(n);
    for (int i = 0; i < n; ++i) {
        cin >> final_order[i];
    }

    // vector<int> initial_order(n);
    // for (int i = 0; i < n; ++i) {
        // initial_order[i] = i + 1;
    // }

    vector<pair<int, int>> overtakes;
	vector<bool> mask(n+1,false);
	int cnt=0;
    for (int i = 0; i < n; ++i) {
    	mask[final_order[i]]=true;
    	for(int j=final_order[i]+1;j<=n;j++){
    		if(mask[j]==false){
    			cnt++;
    			overtakes.emplace_back(j, final_order[i]);
    		}
    	}
    	for(int j=n;j;j--){
    		if(mask[j]==false){
    			cnt++;
    			overtakes.emplace_back(final_order[i], j);
    		}
    	}
        // for (int j = 0; j < n - 1; ++j) {
            // if(final_order[j] < final_order[j + 1] && !(st.count({final_order[j] , final_order[j + 1]}))){
            	// overtakes.emplace_back(final_order[j], final_order[j + 1]);
            	// //overtakes.emplace_back(final_order[j + 1], final_order[j]);
            	// st.insert({final_order[j], final_order[j + 1]});
            	// swap(final_order[j], final_order[j + 1]);
            // }
            // else if (final_order[j] > final_order[j + 1] && !(st.count({final_order[j] , final_order[j + 1]}))) {
                // overtakes.emplace_back(final_order[j], final_order[j + 1]);
                // st.insert({final_order[j], final_order[j + 1]});
                // swap(final_order[j], final_order[j + 1]);
            // }
        // }
    }

    cout << cnt << endl;
    
    for (auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}


Solution 2 (runtime: 1156 ms):
#pragma GCC optimize("O3")

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

#include<iostream>

#include<vector>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<map>

#include<set>

#include<queue>

#include<stack>

using namespace std;



typedef long long ll;

typedef long double ld;

#define all(v) v.begin(),v.end()

#define F first 

#define S second 



#define MAXN  1

ll spf[MAXN];



void sieve(){

    spf[1] = 1;

    for (ll i=2; i<MAXN; i++)

        spf[i] = i;

 

    for (ll i=4; i<MAXN; i+=2)

        spf[i] = 2;

 

    for (ll i=3; i*i<MAXN; i++){

        if (spf[i] == i){

            for (ll j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)

                    spf[j] = i;

        }

    }

}

vector<ll> getFactorization(ll x){

    vector<ll> ret;

    while (x != 1){

        ret.push_back(spf[x]);

        x = x / spf[x];

    }

    return ret;

}

ll ABS(ll a){

    if(a<0)return -a;

    return a;

}

ll getIthBit(ll n,ll i){

    ll mask=(1<<i);

    return  (n&mask)>0 ? 1:0;

}

ll GCD(ll a, ll b){

    return b == 0 ? a : GCD(b, a % b);   

}

ll digitsum(ll n){

    ll ret=0;

    while(n){

        ret += n%10;  

        n/=10;

    }

    return ret;

}

ll power(ll x,ll n){

    if(n==0)    return 1;

    ll a = power(x,n/2);

    if(n%2==0)  return (a*a);

    else    return (a*a*x);

}

ll LCM(ll a, ll b){

    return(a*(b/GCD(a,b)));

}

ll RoundUp(ll num,ll deno){

    if(num%deno==0)return(num/deno);

    else return ((num/deno)+1);

}



void solve()

{

    ll n;

    cin>>n;

    vector<ll> a(n);

    for(ll i=0; i<n; i++)

    {

        cin>>a[i];

    }

    reverse(all(a));

    vector<pair<ll,ll>> v;

    for(ll i=0; i<n; i++)

    {

        vector<ll> temp;

        for(ll j=i+1; j<n; j++)

        {

            temp.push_back(a[j]);

        }

        sort(all(temp));

        ll ind = lower_bound(temp.begin(), temp.end(), a[i]) - temp.begin() - 1;

        for(ll j=ind; j>=0; j--)

        {

            v.push_back({a[i], temp[j]});

        }

        for(ll j=0; j<=ind; j++)

        {

            v.push_back({temp[j], a[i]});

        }

        for(ll j=ind+1; j<temp.size(); j++)

        {

            v.push_back({temp[j], a[i]});

        }

    }

    cout<<v.size()<<endl;

    for(auto it: v)

    {

        cout<<it.first<<" "<<it.second<<endl;

    }

}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll t = 1;

    while(t--)

    {

        solve();

    }

    return 0;

}