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

Previous submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
#ifdef WIDA_WORK_SPACE
    #include "debug.h"
#endif

using i64 = long long;

signed main() {
    int n;
    cin >> n;
    vector<int> in(n);
    for (auto &i : in) {
        cin >> i;
    }

    vector<int> now(n);
    vector<pair<int, int>> ans;
    map<pair<int, int>, int> dic;
    iota(now.begin(), now.end(), 1);

    for (int p = n - 1; p >= 0; p--) {
        for (int i = 0; i < n; i++) {
            if (now[i] == in[p]) {
                for (int j = i + 1; j <= p; j++) {
                    dic[{now[j], now[j - 1]}]++;
                    ans.push_back({now[j], now[j - 1]});
                    swap(now[j - 1], now[j]);
                }
                break;
            }
        }
    }

    if ((n - 1) * n - (int)ans.size() > (int)ans.size()) {
        cout << (n - 1) * n - (int)ans.size() << "\n";
        iota(now.begin(), now.end(), 1);
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < n; j++) {
                if (dic.count({now[j - 1], now[j]})) {
                    continue;
                }
                cout << now[j] << " " << now[j - 1] << "\n";
                swap(now[j - 1], now[j]);
            }
        }
    } else {
        cout << ans.size() << "\n";
        for (auto [i, j] : ans) {
            cout << i << " " << j << "\n";
        }
    }
}

int __OI_INIT__ = []() {
    ios::sync_with_stdio(0), cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    return 0;
}();

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#ifdef WIDA_WORK_SPACE
    #include "debug.h"
#endif

using i64 = long long;

signed main() {
    int n;
    cin >> n;
    vector<int> in(n), chk;
    vector<pair<int, int>> ans1, ans2;
    for (auto &i : in) {
        cin >> i;
    }

    chk = in;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            if (chk[j - 1] > chk[j]) {
                swap(chk[j], chk[j - 1]);
                ans1.push_back({chk[j], chk[j - 1]});
            }
        }
    }

    chk = in;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            if (chk[j - 1] < chk[j]) {
                swap(chk[j], chk[j - 1]);
                ans2.push_back({chk[j], chk[j - 1]});
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            if (chk[j - 1] > chk[j]) {
                swap(chk[j], chk[j - 1]);
                ans2.push_back({chk[j], chk[j - 1]});
            }
        }
    }
    
    if (ans1.size() < ans2.size()) {
        cout << ans2.size() << "\n";
        reverse(ans2.begin(), ans2.end());
        for (auto [i, j] : ans2) {
            cout << i << " " << j << "\n";
        }
    } else {
        cout << ans1.size() << "\n";
        reverse(ans1.begin(), ans1.end());
        for (auto [i, j] : ans1) {
            cout << i << " " << j << "\n";
        }
    }
}

int __OI_INIT__ = []() {
    ios::sync_with_stdio(0), cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    return 0;
}();