Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include <iostream>
#include <vector>
#include <algorithm>

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

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