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

Solution 1 (runtime: 1312 ms):
// to concatanate two chars we can use std::string(1,c1)+c2 where c1 and c2 both are chars
// a 97     A 65    0 48
// to print any float upto n decimal places we can use -> cout<<fixed<<setprecision(n)<<var;
#include"bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define read(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define vec(v) vector<ll> v
#define vp(v) vector<pair<ll,ll>> v
#define vv(v) vector<vector<ll>> v
#define asc(v) sort(v.begin(),v.end())
#define desc(v) sort(v.begin(),v.end(),greater<ll>())
#define print(v) for(ll i=0;i<n;i++){cout<<v[i]; if(i!=n-1)cout<<" ";}
#define pb push_back
#define mp make_pair
#define readv(v,n) for(ll i=0;i<n;i++){ ll x;cin>>x;v.push_back(x);} 
typedef long long ll;
typedef unsigned long long int usl;
const ll N=1e9+ 7;
ll gcd(ll a,ll b){
    return (b==0) ? (a) : (gcd(b,a%b));
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){
    return (a.second < b.second);   //sort in the increasing order of the second elements of the pairs
}
ll getbit(ll n,ll pos){
    return ((n&(1LL<<pos))!=0);
}
ll setbit(ll n,ll pos){
    return (n|(1LL<<pos));
}
ll clearbit(ll n,ll pos){
    ll mask = ~(1LL<<pos);
    return (n&mask);
}
ll even(ll n){
    if(n%2 == 0)return true;
    else return false;
}
ll power(ll base,ll exp){
    ll x = 1;
    rep(i,0,exp){
        x *= base;
    }
    return x;
}
void func1(){
    ll n;cin>>n;
    vec(a);readv(a,n);
    vec(v);
    rep(i,1,n+1){
        v.pb(i);
    }

    vec(idx)(n+1);
    rep(i,1,n+1){
        idx[i] = i-1;
    }

    vv(mp)(n+1,vector<ll>(n+1));

    rep(i,0,n){
        rep(j,i+1,n){
            // if(a[j] > a[i]){
            //     mp[a[i]][a[j]] = 1;
            //     mp[a[j]][a[i]] = 1;
            // }
            // else{
            //     mp[a[i]][a[j]] = 0;
            //     mp[a[j]][a[i]] = 0;
            // }
            mp[a[i]][a[j]] = 1;
            mp[a[j]][a[i]] = 0;
        }
    }

    // for(auto it:mp){
    //     for(auto i:it){
    //         cout<<i<<" ";
    //     }
    //     cout<<endl;
    // }

    vv(swapped)(n+1,vector<ll>(n+1,0));

    vp(ans);

    rep(i,0,n){
        // ll a = v[i];
        ll ptr = idx[a[i]];
        while(ptr+1 != n){
            if(swapped[v[ptr+1]][v[ptr]] == 0 || (mp[v[ptr]][v[ptr+1]] == 0 && swapped[v[ptr+1]][v[ptr]] != 2)){
                ans.pb({v[ptr+1],v[ptr]});
                swapped[v[ptr]][v[ptr+1]]++;
                swapped[v[ptr+1]][v[ptr]]++;
                swap(v[ptr],v[ptr+1]);
                idx[v[ptr]] = ptr;
                idx[v[ptr+1]] = ptr+1;
                ptr++;
            }else break;
        }
        ptr = idx[a[i]];
        // cout<<"ptr : "<<ptr<<endl;
        // for(auto it:v)cout<<it<<" ";cout<<endl;
        while(ptr-1 != -1){
            if(swapped[v[ptr-1]][v[ptr]] == 0 || (mp[v[ptr-1]][v[ptr]] == 0 && swapped[v[ptr-1]][v[ptr]] != 2)){
                ans.pb({v[ptr],v[ptr-1]});
                swapped[v[ptr-1]][v[ptr]]++;
                swapped[v[ptr]][v[ptr-1]]++;
                swap(v[ptr],v[ptr-1]);
                idx[v[ptr]] = ptr;
                idx[v[ptr-1]] = ptr-1;
                ptr--;
            }
            else break;
        }
    }

    cout<<ans.size()<<endl;
    for(auto it:ans){
        cout<<it.first<<" "<<it.second<<endl;
    }
}
int main(){
    ll t;
    t=1;
    // cin>>t; //for single test case remove it
    while(t--){
        func1();
        if(t!=0)
        cout<<endl;
    }
    return 0;
}

Solution 2 (runtime: 1015 ms):
#include <bits/stdc++.h>
#define ull unsigned long long
#define ul unsigned long
#define l long
#define ll long long
using namespace std;
int vis[1010],fi[1010];
vector<pair<int,int>> ans;
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>fi[i];
		vis[fi[i]]=1;
		for(int j=fi[i];j<=n;j++)
			if(!vis[j])ans.push_back(make_pair(j,fi[i]));
		for(int j=n;j>0;j--)
			if(!vis[j])ans.push_back(make_pair(fi[i],j));
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	return;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	solve();
	return 0;
}