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

Solution 1 (runtime: 1296 ms):
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <limits.h>
using namespace std;

int main(){
    int n,a;
    cin>>n;

    // n = 4;
    vector<int> v(n);
    vector<int> final_(n);
    vector<int> index_v(n+1);
    vector<int> index_f(n+1);
    
    for(int i=0;i<n;i++){
        cin>>a;
        final_[a-1] = i+1;
        v[i] = n-i;
        // index[n-i] = i;
    }

    // final_ = {2,3,1,4};
    // final_ = {1,4,2,3};
    // v =      {4,3,2,1};

    for(int i=0;i<n;i++){
        index_v[n-i] = i;
        index_f[final_[i]] = i;
    }

    // cout<<"reached"<<endl;
    vector<pair<int,int>> swaps;
    for(int a = n ;a > 0 ;a--){
        while( v[index_f[a]] != a){
            int b = v[index_f[a]];
            swap(v[index_v[b]],v[index_v[b+1]]);
            swaps.push_back({index_v[b+1]+1,index_v[b]+1});
            swap(index_v[b],index_v[b+1]);
            // cout<<a<<' '<<index_[a]<<' '<<index[a-1]<<endl;
        }
        // cout<<"reached "<<a<<endl;
        // for(int b:v)cout<<b<<' ';
        // cout<<endl;
        // for(int b:index_v)cout<<b<<' ';
        // cout<<endl;
        // if(j<-1)cout<<"Error"<<endl;
    }

    int num = n*(n-1)/2 + swaps.size();
    cout<<num<<endl;
    for(int i=0;i<n;i++){
        for(int j=i+1 ;j<n ;j++){
            cout<<j+1<<' '<<i+1<<endl;
        }
    }

    for(pair<int,int> &p:swaps) 
        cout<<p.first<<' '<<p.second<<endl;

    // cout<<endl;

    return 0;
}

Solution 2 (runtime: 218 ms):
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long int ull;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ll my_rand(ll l, ll r) {
//     return uniform_int_distribution<ll>(l, r) (rng);
// }

void tcase(int Tcase)
{
	int n;
    scanf("%d",&n);
    int a[n+5], pos[n+5], b[n+5], pos2[n+5];
    for(int i = 1; i <= n; i++){
        scanf("%d",&a[i]);
        pos[a[i]] = i;
        b[i] = n+1-i;
        pos2[b[i]] = i;
    }
    vector<pair<int,int>>v;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            v.push_back({j, i});
        }
    }
    int curr = 1;
    while(curr < n){
        if(curr == pos[b[curr]]){
            curr++;
            continue;
        }
        int diff = pos2[a[curr]]-curr;
        int temp = b[curr+diff];
        for(int i = diff; i > 0; i--){
            v.push_back({b[curr+i], b[curr+i-1]});
            swap(b[curr+i], b[curr+i-1]);
        }
        for(int i = 1; i <= n; i++) pos2[b[i]] = i;
    }
    int siz = v.size();
    printf("%d\n",siz);
    for(int i = 0; i < siz; i++){
        printf("%d %d\n",v[i].first, v[i].second);
    }
}

int main(){
	int T = 1;
  	//scanf("%d",&T);
  	for(int Tcase = 1; Tcase <= T; Tcase++){
		  tcase(Tcase);
  	}
}