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

Previous submission (verdict: Wrong answer on test 4):
    #define GLIBCXX_DEBUG



    #include <bits/stdc++.h>

    // #include "optimization.h"

    using namespace std;

    std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

    #define all(a) a.begin(), a.end()

    #ifdef LOCAL

    #define dbg(...) [](auto...zxc){ ((cout << zxc << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)

    #define dbgv(v) cout<< #v <<" : [ "; for(auto &zxc: v) {cout << zxc << " "; }cout <<"]"<< endl;

    #define dbgm(v) cout<< #v <<" :"; for(auto &zxc: v) {cout << '\n' << zxc.fs << ": " << zxc.sc; }cout << endl;

    #else

    #define dbg(...)

    #define dbgv(v)

    #define dbgm(v)

    #endif



    using ll = long long;

    using ld = long double;

    using ull = unsigned long long;



    template <class T>

    T gcd(T a, T b) {

        while (b) a = a % b, swap(a, b);

        return a;

    }



    const ll mod = 998244353;



    int64_t poww(int64_t val, int64_t d, int64_t modd = mod) {

        int64_t ans = 1, mn = val;

        while (d) {

            if (d & 1) ans = mn * ans % modd;

            mn = mn * mn % modd, d >>= 1;

        }

        return ans;

    }



    void solve() {

        int n; cin >> n;

        vector<int> a(n); 

        for(int i=0;i<n;i++){

            cin >> a[i];

        }

        vector<int>perm(n);

        vector<pair<int,int>> ans;

        set<pair<int,int>> s, cands;

        iota(all(perm),1);

        int ind = 0;

        while(ind!=n){

            if(perm[ind]==a[ind]){

                ind++;

            }else{

                int cur_ind = find(all(perm), a[ind]) - perm.begin();

                for(int i=cur_ind;i>=ind+1;i--){

                    s.insert({perm[i], perm[i-1]});

                    swap(perm[i], perm[i-1]);

                }

            }

        }

        iota(all(perm),1);

        ind = 0;

        while(ind!=n){

            for(int i=1;i<n;i++){

                if(!(s.count({perm[i-1], perm[i]}) || s.count({perm[i], perm[i-1]}))){

                    if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i],perm[i-1]});  

                    if(cands.insert({perm[i-1],perm[i]}).second)ans.push_back({perm[i-1],perm[i]});

                } 

            }

            if(perm[ind]==a[ind]){

                ind++;

            }else{

                int cur_ind = find(all(perm), a[ind]) - perm.begin();

                for(int i=cur_ind;i>=ind+1;i--){

                    if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i], perm[i-1]});

                    swap(perm[i], perm[i-1]);

                    // if(i< n-1){

                    //        if(!(s.count({perm[i+1], perm[i]}) || s.count({perm[i], perm[i+1]}))){

                    //         if(cands.insert({perm[i+1],perm[i]}).second)ans.push_back({perm[i+1],perm[i]});  

                    //         if(cands.insert({perm[i],perm[i+1]}).second)ans.push_back({perm[i],perm[i+1]});

                    //     } 

                    // }

                    // if(i>=2){

                    //        if(!(s.count({perm[i-1], perm[i-2]}) || s.count({perm[i-1], perm[i-2]}))){

                    //         if(cands.insert({perm[i-1],perm[i-2]}).second)ans.push_back({perm[i-1],perm[i-2]});  

                    //         if(cands.insert({perm[i-2],perm[i-1]}).second)ans.push_back({perm[i-2],perm[i-1]});

                    //     } 

                    // }

                    for(int i=1;i<n;i++){

                        if(!(s.count({perm[i-1], perm[i]}) || s.count({perm[i], perm[i-1]}))){

                            if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i],perm[i-1]});  

                            if(cands.insert({perm[i-1],perm[i]}).second)ans.push_back({perm[i-1],perm[i]});

                        } 

                    }



                }

            }

        }

        cout << ans.size() << '\n';

        for(auto el: ans){

            cout << el.first << ' ' << el.second << '\n';

        }

    }



    signed main() {

        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

        int t = 1;

        //cin >> t;

        while (t--) solve();

    }

Submission (verdict: Wrong answer on test 4):
    #define GLIBCXX_DEBUG

    #include <bits/stdc++.h>
    // #include "optimization.h"
    using namespace std;
    std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    #define all(a) a.begin(), a.end()
    #ifdef LOCAL
    #define dbg(...) [](auto...zxc){ ((cout << zxc << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
    #define dbgv(v) cout<< #v <<" : [ "; for(auto &zxc: v) {cout << zxc << " "; }cout <<"]"<< endl;
    #define dbgm(v) cout<< #v <<" :"; for(auto &zxc: v) {cout << '\n' << zxc.fs << ": " << zxc.sc; }cout << endl;
    #else
    #define dbg(...)
    #define dbgv(v)
    #define dbgm(v)
    #endif

    using ll = long long;
    using ld = long double;
    using ull = unsigned long long;

    template <class T>
    T gcd(T a, T b) {
        while (b) a = a % b, swap(a, b);
        return a;
    }

    const ll mod = 998244353;

    int64_t poww(int64_t val, int64_t d, int64_t modd = mod) {
        int64_t ans = 1, mn = val;
        while (d) {
            if (d & 1) ans = mn * ans % modd;
            mn = mn * mn % modd, d >>= 1;
        }
        return ans;
    }

    void solve() {
        int n; cin >> n;
        vector<int> a(n); 
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        vector<int>perm(n);
        vector<pair<int,int>> ans;
        set<pair<int,int>> s, cands;
        iota(all(perm),1);
        int ind = 0;
        while(ind!=n){
            if(perm[ind]==a[ind]){
                ind++;
            }else{
                int cur_ind = find(all(perm), a[ind]) - perm.begin();
                for(int i=cur_ind;i>=ind+1;i--){
                    s.insert({perm[i], perm[i-1]});
                    swap(perm[i], perm[i-1]);
                }
            }
        }
        iota(all(perm),1);
        ind = 0;
        while(ind!=n){
            if(perm[ind]==a[ind]){
                for(int i=1;i<n;i++){
                    if(!(s.count({perm[i-1], perm[i]}) || s.count({perm[i], perm[i-1]}))){
                        if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i],perm[i-1]});  
                        if(cands.insert({perm[i-1],perm[i]}).second)ans.push_back({perm[i-1],perm[i]});
                    } 
                }
                ind++;
            }else{
                int cur_ind = find(all(perm), a[ind]) - perm.begin();
                for(int i=1;i<n;i++){
                    if(!(s.count({perm[i-1], perm[i]}) || s.count({perm[i], perm[i-1]}))){
                        if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i],perm[i-1]});  
                        if(cands.insert({perm[i-1],perm[i]}).second)ans.push_back({perm[i-1],perm[i]});
                    } 
                }
                for(int i=cur_ind;i>=ind+1;i--){
                    if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i], perm[i-1]});
                    swap(perm[i], perm[i-1]);
                    if(i< n-1){
                           if(!(s.count({perm[i+1], perm[i]}) || s.count({perm[i], perm[i+1]}))){
                            if(cands.insert({perm[i+1],perm[i]}).second)ans.push_back({perm[i+1],perm[i]});  
                            if(cands.insert({perm[i],perm[i+1]}).second)ans.push_back({perm[i],perm[i+1]});
                        } 
                    }
                    if(i>=2){
                           if(!(s.count({perm[i-1], perm[i-2]}) || s.count({perm[i-2], perm[i-1]}))){
                            if(cands.insert({perm[i-1],perm[i-2]}).second)ans.push_back({perm[i-1],perm[i-2]});  
                            if(cands.insert({perm[i-2],perm[i-1]}).second)ans.push_back({perm[i-2],perm[i-1]});
                        } 

                    }

                }
            }
        }
        cout << ans.size() << '\n';
        for(auto el: ans){
            cout << el.first << ' ' << el.second << '\n';
        }
    }

    signed main() {
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        int t = 1;
        //cin >> t;
        while (t--) solve();
    }