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

Solution 1 (runtime: 1077 ms):
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <cstring>
#include <time.h>
#include <chrono>
#include <random>
#include <ctime>
#include <iomanip>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define ff second
#define ss first
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x));
#define sortall(x) sort(all(x))
#define tr(it, arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const double pi = 3.141592653589793238;
const ll mod = 1e9+7;

void solve() {
    int n;
    cin >> n;

    vector <vector <int>> counter(n, vector <int> (n, 1));
    vector <int> positionToPlayer(n);
    vector <int> playerToPosition(n);
    vector <int> finalOrder;
    for (int i = 0; i < n; i++) {
        positionToPlayer[i] = i;
        playerToPosition[i] = i; 
    }

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;

        finalOrder.push_back(x - 1);
    }

    vector <pair <int, int>> operations;

    for (int i = n - 1; i >= 0; i--) {
        int which = finalOrder[i];

        while (playerToPosition[which] != 0) {
            int whichPosition = playerToPosition[which];
            operations.push_back({which + 1, positionToPlayer[whichPosition - 1] + 1});
            counter[positionToPlayer[whichPosition - 1]][which]--;
            playerToPosition[which] = whichPosition - 1;
            positionToPlayer[whichPosition] = positionToPlayer[whichPosition - 1];
            playerToPosition[positionToPlayer[whichPosition - 1]] = whichPosition;
            positionToPlayer[whichPosition - 1] = which;
        }

        while (playerToPosition[which] != i) {
            int whichPosition = playerToPosition[which];
            operations.push_back({positionToPlayer[whichPosition + 1] + 1, which + 1});
            counter[positionToPlayer[whichPosition + 1]][which]--;
            playerToPosition[which] = whichPosition + 1;
            positionToPlayer[whichPosition] = positionToPlayer[whichPosition + 1];
            playerToPosition[positionToPlayer[whichPosition + 1]] = whichPosition;
            positionToPlayer[whichPosition + 1] = which;
        }
    }

    cout << operations.size() << endl;
    for (auto it: operations) {
        cout << it.first << " " << it.second << endl;
    }
}

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 1359 ms):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n],b[n];
    vector<pair<int,int>> v;
    for (int i=0;i<n;i++) {cin>>b[i];a[i]=n-i;}
    int ans=n*(n-1)/2;
    for (int i=n;i>1;i--) {
        for (int j=i-1;j>0;j--) {
            v.push_back(make_pair(i,j));
        }
    }
    int idx=n-1;
    while (idx>-1) {
        int index=idx;
        while (index>-1&&b[index]==a[index]) {index--;idx--;}
        if (index==-1) break;
        int ind=0;
        while (ind<n&&a[ind]!=b[index]) ind++;
        if (ind==n) break;
        for (int j=ind;j<index;j++) {
            v.push_back(make_pair(a[j+1],a[j]));
            int temp=a[j];
            a[j]=a[j+1];
            a[j+1]=temp;
            ans++;
        }
        idx--;
    }
    cout<<ans<<endl;
    for (int i=0;i<v.size();i++) cout<<v[i].first<<" "<<v[i].second<<endl;
}