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

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#ifndef ONLINE_JUDGE
#include "debugg.cpp"
#else
#define debug(...)
#define debugArr(...)
#endif
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// used to create indexed set where we can declare a indexed set as indexed_set
// s.find_by_order(2) returns an iterator pointing to the element with index 2 in the set based on 0-based indexing like arrays
// s.order_of_key(7) return the index of the element 7 in the set and if not there it returns what position it would be at
// order_of_key(x) returns essentially the number of elements less than x in the set
// find_by_order(x) returns the xth largest element in set
#define endl "\n"
#define set_bits __builtin_popcountll
#define pb push_back
#define fast() ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll>>
#define my_sort(v) sort(v.begin(),v.end())
#define my_reverse_sort(v) sort(v.rbegin(),v.rend())
#define print(v) for(auto it:v)cout<<it<<" "
#define int ll
#define all(a) a.begin(),a.end()


signed main()
{
    fast();
    ll n;cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++) ans+=i;
    vll order(n+1);
    map<ll,ll>mp;
    for(int i=0;i<n;i++){
        ll a;cin>>a;
        order[i+1]=a;
        mp[a]=i+1;
    }
    map<ll,ll>pos;
    vpll final;
    for(int i=1;i<=n;i++) pos[i]=n-i+1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<i;j++){
            final.pb({i,j});
        }
    }
    debug(order);
    for(int i=1;i<=n;i++){
        ll go=order[i];
        for(int j=1;j<=n;j++){
            if(pos[j]<pos[go] && pos[go]>mp[go] && pos[j]!=mp[j]){
                final.pb({go,j});
                pos[go]--;
                pos[j]++;
            }
        }
    }
    cout<<(ll)final.size()<<endl;
    for(auto a:final) cout<<a.first<<" "<<a.second<<endl;

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#ifndef ONLINE_JUDGE
#include "debugg.cpp"
#else
#define debug(...)
#define debugArr(...)
#endif
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// used to create indexed set where we can declare a indexed set as indexed_set
// s.find_by_order(2) returns an iterator pointing to the element with index 2 in the set based on 0-based indexing like arrays
// s.order_of_key(7) return the index of the element 7 in the set and if not there it returns what position it would be at
// order_of_key(x) returns essentially the number of elements less than x in the set
// find_by_order(x) returns the xth largest element in set
#define endl "\n"
#define set_bits __builtin_popcountll
#define pb push_back
#define fast() ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll>>
#define my_sort(v) sort(v.begin(),v.end())
#define my_reverse_sort(v) sort(v.rbegin(),v.rend())
#define print(v) for(auto it:v)cout<<it<<" "
#define int ll
#define all(a) a.begin(),a.end()


signed main()
{
    fast();
    ll n;cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++) ans+=i;
    vll order(n+1);
    map<ll,ll>mp;
    for(int i=0;i<n;i++){
        ll a;cin>>a;
        order[i+1]=a;
        mp[a]=i+1;
    }
    map<ll,ll>pos;
    vpll final;
    for(int i=1;i<=n;i++) pos[i]=n-i+1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<i;j++){
            final.pb({i,j});
        }
    }
    debug(order);
    map<ll,ll>poshas;
    vll done(n+1,0);
    for(int i=1;i<=n;i++){
        ll go=order[i];
        for(int j=1;j<=n;j++){
            if(pos[j]<pos[go] && pos[go]>mp[go] && !done[j]){
                final.pb({go,j});
                pos[go]--;
                pos[j]++;
            }
        }
        done[go]=1;
    }
    cout<<(ll)final.size()<<endl;
    for(auto a:final) cout<<a.first<<" "<<a.second<<endl;

}