Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 7):
// bye bye bye

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    vector<pair<int,int>> ovr;
    vector<pair<int,int>> othr;
    vector<pair<int,int>> final;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (A[i] > A[j]) {
                ovr.emplace_back(A[i], A[j]);
            } else {
                othr.emplace_back(A[j], A[i]);
                final.emplace_back(A[i], A[j]);
            }
        }
    }
    cout << ovr.size() + othr.size() + final.size() << '\n';
    for (auto [x,y] : ovr) {
        cout << x << ' ' << y << '\n';
    }
    for (auto [x,y] : othr) {
        cout << x << ' ' << y << '\n';
    }
    for (auto [x,y] : final) {
        cout << x << ' ' << y << '\n';
    }
    return 0;
}

Submission (verdict: Wrong answer on test 4):
// bye bye bye

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    vector<int> P(N);
    iota(P.begin(), P.end(), 1);
    int first = -1;
    int last = -1;
    vector<pair<int,int>> hmm;
    map<int,int> mp;
    for (int i = 1; i <= N; i++) {
        mp[i] = i - 1;
    }
    int ptr = 0;
    debug(ptr);
    vector<vector<bool>> chk(1001, vector<bool>(1001));
    while (ptr < N) {
        if (P[ptr] != A[ptr]) {
            if (first == -1) {
                first = ptr;
            }
            last = ptr + 1;
            for (int i = mp[A[ptr]]; i > ptr; i--) {
                swap(mp[P[i]], mp[P[i - 1]]);
                hmm.emplace_back(P[i], P[i - 1]);
                chk[P[i]][P[i - 1]] = true;
                chk[P[i - 1]][P[i]] = true;
                swap(P[i], P[i - 1]);
            }
        }
        ++ptr;
    }
    debug(P);
    vector<pair<int,int>> yup;
    ptr = 0;
    while (ptr < N) {
        int last = N - 1;
        int start = ptr;
        for (int i = ptr; i < N; i++) {
            if (i > last) {
                break;
            }
            for (int j = i + 1; j < N; j++) {
                if (j > last) {
                    break;
                }
                if (chk[P[i]][P[j]]) {
                    last = min(last, j - 1);
                }
            }
        }
        // internal swapping
        if (start != last) {
            for (int i = last; i >= start; i--) {
                for (int j = last; j >= start; j--) {
                    if (i != j) {
                        yup.emplace_back(A[i], A[j]);
                    }
                }
            }
        }
        ptr = last + 1;
    }
    cout << hmm.size() + yup.size() << '\n';
    for (auto [x,y] : hmm) cout << x << ' ' << y << '\n';
    for (auto [x,y] : yup) cout << x << ' ' << y << '\n';
    return 0;
}