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

Previous submission (verdict: Wrong answer on test 5):
#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);

    if (now == in) {
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < n; j++) {
                ans.push_back({now[j], now[j - 1]});
                swap(now[j - 1], now[j]);
            }
        }
    } else {
        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;
                }
            }
        }

        for (int i = 0; i < now.size(); i++) {
            for (int j = i + 1; j < now.size(); j++) {
                if (dic[{now[i], now[j]}] + dic[{now[j], now[i]}] != 2) {
                    ans.push_back({now[j], now[i]});
                    ans.push_back({now[i], now[j]});
                    goto P;
                }
            }
        }
    }
    P:{};

    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: 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;
}();