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

Previous submission (verdict: Wrong answer on test 1):
#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] != 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;
        }

        if (i != n - 1) {
            if (counter[positionToPlayer[i]][positionToPlayer[i + 1]] && counter[positionToPlayer[i + 1]][positionToPlayer[i]]) {
                operations.push_back({positionToPlayer[i] + 1, positionToPlayer[i + 1] + 1});
                operations.push_back({positionToPlayer[i + 1] + 1, positionToPlayer[i] + 1});
                counter[positionToPlayer[i]][positionToPlayer[i + 1]]--;
                counter[positionToPlayer[i + 1]][positionToPlayer[i]]--;
            }
        }
    }

    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;
}

Submission (verdict: Wrong answer on test 4):
#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] != 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;
        }

        if (i != n - 1) {
            if (counter[positionToPlayer[i]][positionToPlayer[i + 1]] && counter[positionToPlayer[i + 1]][positionToPlayer[i]]) {
                operations.push_back({positionToPlayer[i + 1] + 1, positionToPlayer[i] + 1});
                operations.push_back({positionToPlayer[i] + 1, positionToPlayer[i + 1] + 1});
                counter[positionToPlayer[i]][positionToPlayer[i + 1]]--;
                counter[positionToPlayer[i + 1]][positionToPlayer[i]]--;
            }
        }
    }

    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;
}