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

Previous submission (verdict: Wrong answer on test 4):
/*

This code template was updated by Yukii_P on 2024/11/12.

*/
#include <bits/stdc++.h>
#define FIO cin.tie(0); ios::sync_with_stdio(false)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define inf 0x3f3f3f3f

#ifndef ONLINE_JUDGE
#define debug(...) std::cerr << #__VA_ARGS__ << " = "; dbg1(__VA_ARGS__)
void dbg2() { std::cerr << "\n"; }
template<typename T, typename... T2>
void dbg2(T x, T2... args) {
    std::cerr << ", " << x;
    dbg2(args...);
}
template<typename T, typename... T2>
void dbg1(T x, T2... args) {
    std::cerr << x;
    dbg2(args...);
}
#else
#define debug(...) 
#endif

using namespace std;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using pii = std::pair<int, int>;

inline char nc() {
    static char buf[1 << 20], *p1, *p2;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<20, stdin), p1 == p2) ? EOF : *p1++;
}
#ifndef ONLINE_JUDGE
#define nc getchar
#endif
void read() {}
template<typename T, typename... T2> 
inline void read(T &x, T2 &... oth) {
    x = 0; char c = nc(), up = c;
    while(!isdigit(c)) up = c, c = nc();
    while(isdigit(c)) x = x * 10 + c - '0', c = nc();
    up == '-' ? x = -x : 0;
    read(oth...);
}

constexpr int N = 1e3 + 10;
constexpr int MOD = 998244353;

int a[N], b[N];
set<int> st[N];
pii ans[N];
int top;

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    iota(b+1, b + n+1, 1);
    auto pb = [&]() {
        for (int i = 1; i <= n; ++i) {
            cout << b[i] << " \n"[i == n];
        }
    };
    for (int i = 1; i <= n; ++i) {
        if (a[i] > b[i]) {
            for (int j = a[i] - 1; j >= i; --j) {
                swap(b[j], b[j + 1]);
                ans[top++] = {b[j], b[j + 1]};
                st[b[j]].insert(b[j + 1]);
                st[b[j + 1]].insert(b[j]);
            }
        }
        //pb();
    }
    for (int i = 1; i <= n - 1; ++i) {
        if (st[a[i]].contains(a[i+1])) continue;
        ans[top++] = {a[i+1], a[i]};
        ans[top++] = {a[i], a[i+1]};
    }
    cout << top << '\n';
    for (int i = 0; i < top; ++i) {
        cout << ans[i].fi << ' ' << ans[i].se << '\n';
    }
}

signed main() {
    
    FIO;
    int t = 1;
    while (t--) solve();

    return 0;
}

/*

 __  __     ___    ___      _      __ _            ___      _             _      
 \ \/ /    | _ \  /   \    | |    / _` |   ___    / __|    | |    _  _   | |__   
  >  <     |  _/  | - |    | |    \__, |  / _ \  | (__     | |   | +| |  | '_ \  
 /_/\_\   _|_|_   |_|_|   _|_|_   |___/   \___/   \___|   _|_|_   \_,_|  |_.__/  
_|"""""|_| """ |_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 

(Font: ASCII - Train)

"El Psy Kongroo." -- Hououin Kyoma

*/

Submission (verdict: Wrong answer on test 1):
/*

This code template was updated by Yukii_P on 2024/11/12.

*/
#include <bits/stdc++.h>
#define FIO cin.tie(0); ios::sync_with_stdio(false)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define inf 0x3f3f3f3f

#ifndef ONLINE_JUDGE
#define debug(...) std::cerr << #__VA_ARGS__ << " = "; dbg1(__VA_ARGS__)
void dbg2() { std::cerr << "\n"; }
template<typename T, typename... T2>
void dbg2(T x, T2... args) {
    std::cerr << ", " << x;
    dbg2(args...);
}
template<typename T, typename... T2>
void dbg1(T x, T2... args) {
    std::cerr << x;
    dbg2(args...);
}
#else
#define debug(...) 
#endif

using namespace std;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using pii = std::pair<int, int>;

inline char nc() {
    static char buf[1 << 20], *p1, *p2;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<20, stdin), p1 == p2) ? EOF : *p1++;
}
#ifndef ONLINE_JUDGE
#define nc getchar
#endif
void read() {}
template<typename T, typename... T2> 
inline void read(T &x, T2 &... oth) {
    x = 0; char c = nc(), up = c;
    while(!isdigit(c)) up = c, c = nc();
    while(isdigit(c)) x = x * 10 + c - '0', c = nc();
    up == '-' ? x = -x : 0;
    read(oth...);
}

constexpr int N = 1e3 + 10;
constexpr int MOD = 998244353;

int a[N];
pii ans[N];
int top;

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < n; ++j) {
            if (a[j] < a[j+1]) {
                swap(a[j], a[j+1]);
                ans[top++] = {a[j], a[j+1]};
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < n; ++j) {
            if (a[j] > a[j+1]) {
                swap(a[j], a[j+1]);
                ans[top++] = {a[j], a[j+1]};
            }
        }
    }
    cout << top << '\n';
    for (int i = 0; i < top; ++i) {
        cout << ans[i].fi << ' ' << ans[i].se << '\n';
    }
}

signed main() {
    
    FIO;
    int t = 1;
    while (t--) solve();

    return 0;
}

/*

 __  __     ___    ___      _      __ _            ___      _             _      
 \ \/ /    | _ \  /   \    | |    / _` |   ___    / __|    | |    _  _   | |__   
  >  <     |  _/  | - |    | |    \__, |  / _ \  | (__     | |   | +| |  | '_ \  
 /_/\_\   _|_|_   |_|_|   _|_|_   |___/   \___/   \___|   _|_|_   \_,_|  |_.__/  
_|"""""|_| """ |_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 

(Font: ASCII - Train)

"El Psy Kongroo." -- Hououin Kyoma

*/