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

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)

#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

#define fordt(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)

#define forde(i, a, b) for (int i = (a), _b = (b); i > _b; --i)

#define trav(a, x) for (auto& a : x)

#define rep(i, a, b) for(int i = a; i < (b); ++i)

#define all(x) begin(x), end(x)

#define sz(x) (int)(x).size()



using namespace std;

using namespace __gnu_pbds;



template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};

template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};



typedef int64_t i64;

typedef pair<int,int> _ii;

typedef vector<int> vi;

typedef long long ll;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

constexpr int maxn = 2e5 + 7;

constexpr i64 oo = 1e9 + 7;



void solve() {

    int n;

    cin >> n;



    vi a(n);

    rep(i, 0, n) cin >> a[i];



    vector <_ii> ans;

    fordt(i, n - 1, 0) {

        fordt(j, a[i] - 1, 1) ans.push_back({a[i], j});

        fore(j, 0, i) {

            if(a[j] < a[i]) ans.push_back({a[j], a[i]});

        }

    }



    cout << sz(ans) << '\n';

    trav(x, ans) cout << x.first << ' ' << x.second << '\n';

}



#define NAME "C."

int main() {

    cin.tie(0)->sync_with_stdio(false);



    if(fopen(NAME"inp", "r")) {

        freopen(NAME"inp", "r", stdin);

        freopen(NAME"out", "w", stdout);

    }



    int t=1;

    while(t--) solve();

}

Submission (verdict: Wrong answer on test 5):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)

#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

#define fordt(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)

#define forde(i, a, b) for (int i = (a), _b = (b); i > _b; --i)

#define trav(a, x) for (auto& a : x)

#define rep(i, a, b) for(int i = a; i < (b); ++i)

#define all(x) begin(x), end(x)

#define sz(x) (int)(x).size()



using namespace std;

using namespace __gnu_pbds;



template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};

template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};



typedef int64_t i64;

typedef pair<int,int> _ii;

typedef vector<int> vi;

typedef long long ll;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

constexpr int maxn = 2e5 + 7;

constexpr i64 oo = 1e9 + 7;



void solve() {

    int n;

    cin >> n;



    vi a(n);

    rep(i, 0, n) cin >> a[i];



    map <_ii, int> cnt;

    vector <_ii> ans;

    vector <int> state(n, 0);

    iota(all(state), 1);

    fordt(i, n - 1, 0) {

        int pos_ai = lower_bound(all(state), a[i]) - state.begin();

        for(int j = pos_ai; j >= 1; --j) {

            ans.push_back({state[j], state[j - 1]});

            swap(state[j], state[j - 1]);

        }



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

            ans.push_back({state[j + 1], state[j]});

            swap(state[j], state[j + 1]);

        }

    }



    cout << sz(ans) << '\n';

    trav(x, ans) cout << x.first << ' ' << x.second << '\n';

}



#define NAME "C."

int main() {

    cin.tie(0)->sync_with_stdio(false);



    if(fopen(NAME"inp", "r")) {

        freopen(NAME"inp", "r", stdin);

        freopen(NAME"out", "w", stdout);

    }



    int t=1;

    while(t--) solve();

}