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

Previous submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set =tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define pb push_back
#define in insert

#define sortva(ans) sort(ans.begin(), ans.end());
#define sortvd(ans) sort(ans.rbegin(), ans.rend());

const int MOD = 1e9+7;

void printVec(vector<int> &ans){
    for(int i=0;i<ans.size();++i) cout<<ans[i]<<" ";
    cout<<"\n";
}
 

void solve(){
    int n;
    cin >> n;

    vector<int> v(n+1);
    vector<int> pos(n+1);
    for(int i = 1; i <= n ; i++){
        cin >> v[i];
        pos[v[i]] = i;
    }

    vector<int> check(n+1);
    vector<int> posele(n+1);
    for(int i = 1; i <= n ; i++){
        check[i] = i;
        posele[i] = i;
    }

    vector<pair<int,int>> ans;
    for(int i = 1; i <= n; i++){
        if(pos[v[i]] <= check[v[i]]){
            vector<pair<int,int>> temp;
            for(int j = check[v[i]] + 1; j <= n; j++){
                ans.pb({posele[j], v[i]});
                temp.pb({posele[j], v[i]});
            }
            reverse(temp.begin(), temp.end());
            for(auto x : temp){
                ans.pb({x.second, x.first});
            }
            for(int j = check[v[i]] - 1; j >= i; j--){
                ans.pb({v[i], posele[j]});
                check[j] += 1;
            }
            check[v[i]] = i;
            for(int j = 1; j <= n; j++){
                posele[check[j]] = j;
            }
        }
    }

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

    
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){solve();}
    return 0;
}








Submission (verdict: Wrong answer on test 9):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set =tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define pb push_back
#define in insert

#define sortva(ans) sort(ans.begin(), ans.end());
#define sortvd(ans) sort(ans.rbegin(), ans.rend());

const int MOD = 1e9+7;

void printVec(vector<int> &ans){
    for(int i=0;i<ans.size();++i) cout<<ans[i]<<" ";
    cout<<"\n";
}
 

void solve(){
    int n;
    cin >> n;

    vector<int> v(n+1);
    vector<int> pos(n+1);
    for(int i = 1; i <= n ; i++){
        cin >> v[i];
        pos[v[i]] = i;
    }

    vector<int> check(n+1);
    vector<int> posele(n+1);
    for(int i = 1; i <= n ; i++){
        check[i] = i;
        posele[i] = i;
    }

    vector<pair<int,int>> ans;
    for(int i = 1; i <= n; i++){
        if(pos[v[i]] <= check[v[i]]){
            vector<pair<int,int>> temp;
            for(int j = check[v[i]] + 1; j <= n; j++){
                ans.pb({posele[j], v[i]});
                temp.pb({posele[j], v[i]});
            }
            reverse(temp.begin(), temp.end());
            for(auto x : temp){
                ans.pb({x.second, x.first});
            }
            for(int j = check[v[i]] - 1; j >= i; j--){
                ans.pb({v[i], posele[j]});
                check[check[j]] += 1;
            }
            check[v[i]] = i;
            for(int j = 1; j <= n; j++){
                posele[check[j]] = j;
            }
        }
    }

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

    
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){solve();}
    return 0;
}