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 vector<long long int> vi;
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
#define get(n) \
    ll n;      \
    cin >> n;
#define gets(n, m) \
    ll n, m;       \
    cin >> n >> m;
#define getss(n, m, o) \
    ll n, m, o;        \
    cin >> n >> m >> o;
#define show(n) cout << n << endl;
#define getv(n) \
    vi v(n);    \
    loop(i, 0, n) cin >> v[i];
#define sort(v) sort(all(v));
#define getstr(s) \
    string s;     \
    cin >> s;
#define showstr(s) cout << s << endl;
#define showv(v) loop(i, 0, v.size()) cout << v[i] << " ";
#define endl "\n";
#define sp " ";
#define getmatrix(n, m)                     \
    vector<vector<ll>> v(n, vector<ll>(m)); \
    loop(i, 0, n) loop(j, 0, m) cin >> v[i][j];
#define showmatrix(n, m)                      \
    loop(i, 0, n)                             \
    {                                         \
        loop(j, 0, m) cout << v[i][j] << " "; \
        cout << endl;                         \
    }
#define gethashmap(n) \
    map<ll, ll> m;    \
    loop(i, 0, n)     \
    {                 \
        int a;        \
        cin >> a;     \
        m[a]++;       \
    }
#define showhashmap                                \
    for (auto it = m.begin(); it != m.end(); it++) \
        cout << it->first << sp << it->second << endl;
#define getset(n)    \
    set<int> s;      \
    loop(i, 0, n)    \
    {                \
        int a;       \
        cin >> a;    \
        s.insert(a); \
    }
#define sumv(v) accumulate(all(v), 0);

long long int NcR(int n, int r)
{

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    long long p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);

            // dividing by gcd, to simplify
            // product division by their gcd
            // saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}

void yesno(bool c)
{
    if (c)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}
constexpr int N = 2E7;
vector<int> minp, primes;
void sieve(int n)
{
    minp.assign(n + 1, 0);
    primes.clear();

    for (int i = 2; i <= n; i++)
    {
        if (minp[i] == 0)
        {
            minp[i] = i;
            primes.push_back(i);
        }

        for (auto p : primes)
        {
            if (i * p > n)
            {
                break;
            }
            minp[i * p] = p;
            if (p == minp[i])
            {
                break;
            }
        }
    }
}
ll power(ll x, int y, int p)
{
    ll res = 1; // Initialize result

    x = x % p; // Update x if it is more than or
    // equal to p

    while (y > 0)
    {

        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, int p)
{
    return power(n, p - 2, p);
}
ll nCrModPFermat(ll n, int r, int p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    
    while (t--)
    {
        get(n);
        getv(n);

        vector<pair<ll, ll>> ans;
        for(int i=0; i<n; i++){
            for(int j=0; j<n-i-1; j++){
                if(v[j] > v[j+1]){
                    ans.pb({v[j], v[j+1]});
                    swap(v[j], v[j+1]);
                }
                else{
                    ans.pb({v[j], v[j+1]});
                    ans.pb({v[j+1], v[j]});
                }
            }
        }

        cout<<ans.size()<<endl;
        reverse(all(ans));
        for(auto x: ans){
            cout<<x.first<<" "<<x.second<<endl;
        }

        
        
    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long int> vi;
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
#define get(n) \
    ll n;      \
    cin >> n;
#define gets(n, m) \
    ll n, m;       \
    cin >> n >> m;
#define getss(n, m, o) \
    ll n, m, o;        \
    cin >> n >> m >> o;
#define show(n) cout << n << endl;
#define getv(n) \
    vi v(n);    \
    loop(i, 0, n) cin >> v[i];
#define sort(v) sort(all(v));
#define getstr(s) \
    string s;     \
    cin >> s;
#define showstr(s) cout << s << endl;
#define showv(v) loop(i, 0, v.size()) cout << v[i] << " ";
#define endl "\n";
#define sp " ";
#define getmatrix(n, m)                     \
    vector<vector<ll>> v(n, vector<ll>(m)); \
    loop(i, 0, n) loop(j, 0, m) cin >> v[i][j];
#define showmatrix(n, m)                      \
    loop(i, 0, n)                             \
    {                                         \
        loop(j, 0, m) cout << v[i][j] << " "; \
        cout << endl;                         \
    }
#define gethashmap(n) \
    map<ll, ll> m;    \
    loop(i, 0, n)     \
    {                 \
        int a;        \
        cin >> a;     \
        m[a]++;       \
    }
#define showhashmap                                \
    for (auto it = m.begin(); it != m.end(); it++) \
        cout << it->first << sp << it->second << endl;
#define getset(n)    \
    set<int> s;      \
    loop(i, 0, n)    \
    {                \
        int a;       \
        cin >> a;    \
        s.insert(a); \
    }
#define sumv(v) accumulate(all(v), 0);

long long int NcR(int n, int r)
{

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    long long p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);

            // dividing by gcd, to simplify
            // product division by their gcd
            // saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}

void yesno(bool c)
{
    if (c)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}
constexpr int N = 2E7;
vector<int> minp, primes;
void sieve(int n)
{
    minp.assign(n + 1, 0);
    primes.clear();

    for (int i = 2; i <= n; i++)
    {
        if (minp[i] == 0)
        {
            minp[i] = i;
            primes.push_back(i);
        }

        for (auto p : primes)
        {
            if (i * p > n)
            {
                break;
            }
            minp[i * p] = p;
            if (p == minp[i])
            {
                break;
            }
        }
    }
}
ll power(ll x, int y, int p)
{
    ll res = 1; // Initialize result

    x = x % p; // Update x if it is more than or
    // equal to p

    while (y > 0)
    {

        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, int p)
{
    return power(n, p - 2, p);
}
ll nCrModPFermat(ll n, int r, int p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    
    while (t--)
    {
        get(n);
        getv(n);

        vector<pair<ll, ll>> ans;
        for(int i=0; i<n; i++){
            for(int j=0; j<n-i-1; j++){
                if(v[j] < v[j+1]){
                    ans.pb({v[j], v[j+1]});
                    swap(v[j], v[j+1]);
                }
                
            }
        }

        for(int i=0; i<n; i++){
            for(int j=0; j<n-i-1; j++){
                if(v[j] > v[j+1]){
                    ans.pb({v[j], v[j+1]});
                    swap(v[j], v[j+1]);
                }
                
            }
        }

        cout<<ans.size()<<endl;
        reverse(all(ans));
        for(auto x: ans){
            cout<<x.first<<" "<<x.second<<endl;
        }

       

        
        
    }

    return 0;
}