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;
#define int ll
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define endl '\n'
#define yn(ans) cout << (ans ? "YES\n" : "NO\n")
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
const int MOD = 1000000007;
const int N = 200000;
const int inf = INT_MAX;
template <typename S>ostream& operator<<(ostream& os,const vector<S>& vector) {for (auto element : vector) {os << element << " ";} return os;}
template <typename S>istream& operator>>(istream& is, vector<S>& vec) {for (auto& element : vec) {is >> element;}return is;}
template <typename T1, typename T2>ostream& operator<<(ostream& os, const pair<T1, T2>& p) {os << "{" << p.first << ", " << p.second << "}";return os;}

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

    vector<pii> final_pos(n);
    fo(i,n) final_pos[arr[i] -1] = {arr[i],i};

    vector<pii> ans;

    Fo(i, 1, n) {
        Fo(j, i, 0) {
            if (final_pos[j].second < final_pos[j - 1].second) {
                swap(final_pos[j], final_pos[j - 1]);
                ans.push_back(make_pair(final_pos[j - 1].first,final_pos[j].first));
            } else {
                Fo(k,j,0) {
                    ans.push_back(make_pair(final_pos[k].first, final_pos[k - 1].first));
                }
                Fo(k,1,j+1){
                    ans.push_back(make_pair(final_pos[k - 1].first, final_pos[k].first));
                }
                break;
            }
        }
    }



    cout << ans.size() << endl;
    if (ans.size() > 0){
        fo(i,ans.size()){
            cout << ans[i].first << ' ' << ans[i].second << endl;
        }
    }
}


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

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define endl '\n'
#define yn(ans) cout << (ans ? "YES\n" : "NO\n")
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
const int MOD = 1000000007;
const int N = 200000;
const int inf = INT_MAX;
template <typename S>ostream& operator<<(ostream& os,const vector<S>& vector) {for (auto element : vector) {os << element << " ";} return os;}
template <typename S>istream& operator>>(istream& is, vector<S>& vec) {for (auto& element : vec) {is >> element;}return is;}
template <typename T1, typename T2>ostream& operator<<(ostream& os, const pair<T1, T2>& p) {os << "{" << p.first << ", " << p.second << "}";return os;}

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

    vector<pii> final_pos(n);
    fo(i,n) final_pos[arr[i] -1] = {arr[i],i};

    vector<pii> ans;

    Fo(i, 1, n) {
        Fo(j, i, 0) {
            if (final_pos[j].second < final_pos[j - 1].second) {
                swap(final_pos[j], final_pos[j - 1]);
                ans.push_back(make_pair(final_pos[j - 1].first,final_pos[j].first));
            } else {
                Fo(k,j,0) {
                    ans.push_back(make_pair(final_pos[k].first, final_pos[k - 1].first));
                    swap(final_pos[k - 1], final_pos[k]);
                }
                Fo(k,1,j+1){
                    swap(final_pos[k],final_pos[k - 1]);
                    ans.push_back(make_pair(final_pos[k - 1].first, final_pos[k].first));
                }
                break;
            }
        }
    }



    cout << ans.size() << endl;
    if (ans.size() > 0){
        fo(i,ans.size()){
            cout << ans[i].first << ' ' << ans[i].second << endl;
        }
    }
}


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