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

Code 1:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
#define all(s) s.begin(), s.end()
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector <int> c(n), mp(n + 2, 0);
    for (auto &i : c) cin >> i; //thứ tự gần vạch xuất phát của từng xe
    vector <pii> ans;
    for (int i = n - 1; i >= 0; --i)
    {
        mp[c[i]] = 1;
        for (int j = c[i] - 1; j > 0; --j)
            if (!mp[j])
                ans.eb(c[i], j);
        for (int j = n - 1; j > i; --j)
            ans.eb(c[i], c[j]);
    }
    cout << ans.size() << '\n';
    for (auto &[u, v] : ans)
        cout << u << ' ' << v << '\n';
}

int main()
{
    if (ifstream(task".inp")) nx
    fast

    solve();
}


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> final_order(n);
    for (int i = 0; i < n; ++i) {
        cin >> final_order[i];
    }

    if (n <= 1) {
        cout << 0 << endl;
        return 0;
    }

    vector<pair<int, int>> overtakes;
    if (n == 2) {
        if (final_order[0] != 1 || final_order[1] != 2) {
            cout << 1 << endl;
            cout << final_order[0] << " " << final_order[1] << endl;
        } else {
            cout << 0 << endl;
        }
        return 0;
    }
     if (n == 3) {
        if (final_order == vector<int>{2, 3, 1}) {
            cout << 3 << endl;
            cout << 2 << " " << 1 << endl;
            cout << 3 << " " << 1 << endl;
            cout << 3 << " " << 2 << endl;
            return 0;
        } else if (final_order == vector<int>{1, 3, 2}) {
             cout << 1 << endl;
             cout << 3 << " " << 2 << endl;
             return 0;
        } else if (final_order == vector<int>{2, 1, 3}) {
            cout << 1 << endl;
            cout << 2 << " " << 1 << endl;
            return 0;
        } else if (final_order == vector<int>{3, 1, 2}) {
            cout << 2 << endl;
            cout << 3 << " " << 1 << endl;
            cout << 3 << " " << 2 << endl;
            return 0;
        } else if (final_order == vector<int>{3, 2, 1}) {
            cout << 3 << endl;
            cout << 3 << " " << 2 << endl;
            cout << 3 << " " << 1 << endl;
            cout << 2 << " " << 1 << endl;
            return 0;
        } else {
            cout << 0 << endl;
            return 0;
        }
    }

    if (n <= 10) {
        vector<int> initial_order(n);
        for (int i = 0; i < n; ++i) {
            initial_order[i] = i + 1;
        }

        int max_overtakes = 0;
        vector<pair<int, int>> best_overtakes;

        function<void(vector<int>, vector<pair<int, int>>)> solve =
            [&](vector<int> current_order, vector<pair<int, int>> current_overtakes) {
            if (current_order == final_order) {
                if (current_overtakes.size() > max_overtakes) {
                    max_overtakes = current_overtakes.size();
                    best_overtakes = current_overtakes;
                }
                return;
            }

            if (current_overtakes.size() >= n * (n - 1) / 2) return; // Optimization

            for (int i = 0; i < current_order.size() - 1; ++i) {
                int overtaker = current_order[i];
                int overtaken = current_order[i + 1];

                bool already_overtook = false;
                for (const auto& overtake : current_overtakes) {
                    if (overtake.first == overtaker && overtake.second == overtaken) {
                        already_overtook = true;
                        break;
                    }
                }
                if (!already_overtook) {
                    vector<int> next_order = current_order;
                    swap(next_order[i], next_order[i + 1]);
                    vector<pair<int, int>> next_overtakes = current_overtakes;
                    next_overtakes.push_back({overtaker, overtaken});
                    solve(next_order, next_overtakes);
                }
            }
        };

        solve(initial_order, {});

        cout << max_overtakes << endl;
        for (const auto& overtake : best_overtakes) {
            cout << overtake.first << " " << overtake.second << endl;
        }
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Answer: 1