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

Previous submission (verdict: Wrong answer on test 7):
// #define NDEBUG

#define ce constexpr
#define tt template <typename T>
#define tt_ template <typename... T>
#define tn template <size_t N>
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define whole(x) (x).begin(), (x).end()
#define rwhole(x) (x).rbegin(), (x).rend()

#include <bits/stdc++.h>
// #include <bits/extc++.h>

using ll = long long;
using lll = __int128_t;
using ld = long double;
using uchar = unsigned char;
using ushort = unsigned short;
using uint = unsigned int;
using ull = unsigned long long;
using ulll = __uint128_t;
ce int mod9 = 998244353;
ce int mod10 = 1000000007;
ce int inf = 0x3f3f3f3f;
ce int neginf = 0xc0c0c0c0;
ce ll infll = 0x3f3f3f3f3f3f3f3f;
ce ll neginfll = 0xc0c0c0c0c0c0c0c0;
tt ce T &maxeq(T &a, const T &b) { return a < b ? (a = b) : a; }
tt ce T &mineq(T &a, const T &b) { return a > b ? (a = b) : a; }
ce int mylog(uint x) { return 31 - __builtin_clz(x); }
ce int mylogc(uint x) { return 32 - __builtin_clz(x - 1); }
ce int mylogll(ull x) { return 63 - __builtin_clzll(x); }
ce int mylogcll(ull x) { return 64 - __builtin_clzll(x - 1ULL); }

using namespace std;
tt_ using vec = vector<T...>;
tt_ using mset = multiset<T...>;
tt_ using mmap = multimap<T...>;
tt_ using uset = unordered_set<T...>;
tt_ using umap = unordered_map<T...>;
tt_ using umset = unordered_multiset<T...>;
tt_ using ummap = unordered_multimap<T...>;
tt_ using pq = priority_queue<T...>;
using pbb = pair<bool, bool>;
using pbi = pair<bool, int>;
using pbd = pair<bool, double>;
using pib = pair<int, bool>;
using pii = pair<int, int>;
using pid = pair<int, double>;
using pdb = pair<double, bool>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
using vb = vec<bool>;
using vi = vec<int>;
using vll = vec<ll>;
using vd = vec<double>;

// template <typename S, typename T>
// using rbtree = __gnu_pbds::tree<S, __gnu_pbds::null_type, T, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#undef tt
#undef tt_
#undef tn

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i{}; i < n; ++i)
    {
        int x;
        cin >> x;
        p[--x] = i;
    }
    int cnt{};
    vector<int> a(n), np(n);
    iota(whole(a), 0);
    iota(whole(np), 0);
    vector<pair<int, int>> ans;
    for (int i{}; i < n; ++i)
    {
        for (int j{np[i] + 1}; j < n && (a[j] > i || p[a[j]] < p[i]); ++j)
        {
            ++cnt;
            ans.eb(a[j], i);
            np[a[j]] = j - 1;
            np[i] = j;
            swap(a[j - 1], a[j]);
        }
        for (int j{np[i] - 1}; j >= 0 && p[i] < p[a[j]]; --j)
        {
            ++cnt;
            ans.eb(i, a[j]);
            np[a[j]] = j + 1;
            np[i] = j;
            swap(a[j], a[j + 1]);
        }
    }
    cout << cnt << '\n';
    for (auto [x, y] : ans)
        cout << x + 1 << ' ' << y + 1 << '\n';
    return 0;
}

Submission (verdict: Accepted):
// #define NDEBUG

#define ce constexpr
#define tt template <typename T>
#define tt_ template <typename... T>
#define tn template <size_t N>
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define whole(x) (x).begin(), (x).end()
#define rwhole(x) (x).rbegin(), (x).rend()

#include <bits/stdc++.h>
// #include <bits/extc++.h>

using ll = long long;
using lll = __int128_t;
using ld = long double;
using uchar = unsigned char;
using ushort = unsigned short;
using uint = unsigned int;
using ull = unsigned long long;
using ulll = __uint128_t;
ce int mod9 = 998244353;
ce int mod10 = 1000000007;
ce int inf = 0x3f3f3f3f;
ce int neginf = 0xc0c0c0c0;
ce ll infll = 0x3f3f3f3f3f3f3f3f;
ce ll neginfll = 0xc0c0c0c0c0c0c0c0;
tt ce T &maxeq(T &a, const T &b) { return a < b ? (a = b) : a; }
tt ce T &mineq(T &a, const T &b) { return a > b ? (a = b) : a; }
ce int mylog(uint x) { return 31 - __builtin_clz(x); }
ce int mylogc(uint x) { return 32 - __builtin_clz(x - 1); }
ce int mylogll(ull x) { return 63 - __builtin_clzll(x); }
ce int mylogcll(ull x) { return 64 - __builtin_clzll(x - 1ULL); }

using namespace std;
tt_ using vec = vector<T...>;
tt_ using mset = multiset<T...>;
tt_ using mmap = multimap<T...>;
tt_ using uset = unordered_set<T...>;
tt_ using umap = unordered_map<T...>;
tt_ using umset = unordered_multiset<T...>;
tt_ using ummap = unordered_multimap<T...>;
tt_ using pq = priority_queue<T...>;
using pbb = pair<bool, bool>;
using pbi = pair<bool, int>;
using pbd = pair<bool, double>;
using pib = pair<int, bool>;
using pii = pair<int, int>;
using pid = pair<int, double>;
using pdb = pair<double, bool>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
using vb = vec<bool>;
using vi = vec<int>;
using vll = vec<ll>;
using vd = vec<double>;

// template <typename S, typename T>
// using rbtree = __gnu_pbds::tree<S, __gnu_pbds::null_type, T, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#undef tt
#undef tt_
#undef tn

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> A(n), p(n);
    for (int i{}; i < n; ++i)
    {
        cin >> A[i];
        p[--A[i]] = i;
    }
    int cnt{};
    vector<int> a(n), np(n);
    iota(whole(a), 0);
    iota(whole(np), 0);
    vector<pair<int, int>> ans;
    for (auto &i : A)
    {
        for (int j{np[i] + 1}; j < n; ++j)
        {
            ++cnt;
            ans.eb(a[j], i);
            np[a[j]] = j - 1;
            np[i] = j;
            swap(a[j - 1], a[j]);
        }
        for (int j{np[i] - 1}; j >= 0 && p[i] < p[a[j]]; --j)
        {
            ++cnt;
            ans.eb(i, a[j]);
            np[a[j]] = j + 1;
            np[i] = j;
            swap(a[j], a[j + 1]);
        }
    }
    cout << cnt << '\n';
    for (auto [x, y] : ans)
        cout << x + 1 << ' ' << y + 1 << '\n';
    return 0;
}