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

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;



#define MULTI 0

#define dbg(x) cout << #x << " = " << x << "\n"

#define cin_vector(vec, n, T) vector<T> vec(n); for(ll i = 0; i < n; i++) cin >> vec[i];



template <typename T> void print(vector<T> &v){ for (auto &a : v) cout << a << " "; cout << "\n";}



void solve() {

    int n;

    cin>>n;

    cin_vector(a,n,int);

    vector<int>b;

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

        b.push_back(i);

    }

    int total =0;

    vector<pair<int,int>> c;

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

        auto it = find(b.begin(),b.end(),a[i]);

        int f_ov = b.end()-1-it;

        total+=f_ov;

        total+=n-1-i;

        // dbg(f_ov);

        b.erase(it);

        for(int j = 1; j<=f_ov; j++ ){

            // dbg(*(it+j));

            c.push_back({*(it+j),a[i]});

        }

        for(int j=n-i-2; j>=0; j--){

            c.push_back({a[i],*(b.begin()+j)});

            // cout<<a[i]<<" "<<<<endl;

            // dbg(*(b.begin()+j));

            

        }

        

    }

    cout<<total<<endl;

    // dbg(total);

    for(auto cc: c){

        cout<<cc.first<<" "<<cc.second<<endl;

    }

    // cout<<endl;

}



int32_t main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(15); cout.setf(ios::fixed);

    ll t=1; if(MULTI) cin>>t;

    for (ll it = 1; it <= t; it++) {

        // cout << "Case #" << it << ": ";

        solve();

    }

    return 0;

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;



#define MULTI 0

#define dbg(x) cout << #x << " = " << x << "\n"

#define cin_vector(vec, n, T) vector<T> vec(n); for(ll i = 0; i < n; i++) cin >> vec[i];



template <typename T> void print(vector<T> &v){ for (auto &a : v) cout << a << " "; cout << "\n";}



void solve() {

    int n;

    cin>>n;

    cin_vector(a,n,int);

    vector<int>b;

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

        b.push_back(i);

    }

    int total =0;

    vector<pair<int,int>> c;

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

        auto it = find(b.begin(),b.end(),a[i]);

        int f_ov = b.end()-1-it;

        total+=f_ov;

        total+=n-1-i;

        // dbg(f_ov);

        for(int j = 1; j<=f_ov; j++ ){

            // dbg(*(it+j));

            c.push_back({*(it+j),a[i]});

        }

        b.erase(it);

        for(int j=n-i-2; j>=0; j--){

            c.push_back({a[i],*(b.begin()+j)});

            // cout<<a[i]<<" "<<<<endl;

            // dbg(*(b.begin()+j));

            

        }

        // print(b);   

    }

    cout<<total<<endl;

    // dbg(total);

    for(auto cc: c){

        cout<<cc.first<<" "<<cc.second<<endl;

    }

    // cout<<endl;

}



int32_t main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(15); cout.setf(ios::fixed);

    ll t=1; if(MULTI) cin>>t;

    for (ll it = 1; it <= t; it++) {

        // cout << "Case #" << it << ": ";

        solve();

    }

    return 0;

}