Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#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+diff], b[curr+diff-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);
  	}
}


Submission (verdict: Accepted):
#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);
  	}
}