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

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pnl cout << "\n"
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << (#x) << " " << (x) << "\n"
#else
#define dbg(x) 42
#endif

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = array<int, 2>;
using vii = vector<ii>;

template <typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (auto &x : a) in >> x;
    return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &a) {
    for (auto &x : a) out << x << " ";
    return out;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(int testcase) {
    int n; cin >> n;
    vi c(n); cin >> c;
    for (int &x : c) --x;
    vi pos(n);
    for (int i = 0; i < n; i++) {
        pos[c[i]] = i;
    }
    vii ans;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (pos[j] < pos[i]) {
                ans.push_back({j, i});
            } else {
                ans.push_back({j, i});
                ans.push_back({i, j});
            }
        }
    }
    vii fans;
    vi p(n);
    iota(all(p), 0LL);
    iota(all(pos), 0LL);
    while (sz(ans)) {
        for (int i = 0; i < sz(ans); i++) {
            auto [x, y] = ans[i];
            // x overtakes y
            if (pos[x] == 1 + pos[y]) {
                swap(pos[x], pos[y]);
                swap(p[pos[x]], p[pos[y]]);
                fans.push_back({x, y});
                ans.erase(ans.begin() + i);
                break;
            }
        }
    }
    cout << sz(fans) << "\n";
    for (auto [f, s] : fans) {
        cout << f + 1 << " " << s + 1 << "\n";
    }
}

int32_t main() {
    using namespace chrono;
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    auto start = high_resolution_clock::now();
    int T = 1; // cin >> T;
    for (int t = 1; t <= T; t++) {
        solve(t);
    }
    auto end = high_resolution_clock::now();
    auto duration = duration_cast<milliseconds>(end - start);
#ifndef ONLINE_JUDGE
    cerr << "Time: " << duration.count() << " ms\n";
#endif
    return 0;
}

Submission (verdict: Time limit exceeded on test 4):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pnl cout << "\n"
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << (#x) << " " << (x) << "\n"
#else
#define dbg(x) 42
#endif

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = array<int, 2>;
using vii = vector<ii>;

template <typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (auto &x : a) in >> x;
    return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &a) {
    for (auto &x : a) out << x << " ";
    return out;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(int testcase) {
    int n; cin >> n;
    vi c(n); cin >> c;
    for (int &x : c) --x;
    vi pos(n);
    for (int i = 0; i < n; i++) {
        pos[c[i]] = i;
    }
    set<ii> ans;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (pos[j] < pos[i]) {
                ans.insert({j, i});
            } else {
                ans.insert({j, i});
                ans.insert({i, j});
            }
        }
    }
    vii fans;
    vi p(n);
    iota(all(p), 0LL);
    iota(all(pos), 0LL);
    while (sz(ans)) {
        for (auto [x, y] : ans) {
            // x overtakes y
            if (pos[x] == 1 + pos[y]) {
                swap(pos[x], pos[y]);
                swap(p[pos[x]], p[pos[y]]);
                fans.push_back({x, y});
                ans.erase({x, y});
                break;
            }
        }
    }
    cout << sz(fans) << "\n";
    for (auto [f, s] : fans) {
        cout << f + 1 << " " << s + 1 << "\n";
    }
}

int32_t main() {
    using namespace chrono;
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    auto start = high_resolution_clock::now();
    int T = 1; // cin >> T;
    for (int t = 1; t <= T; t++) {
        solve(t);
    }
    auto end = high_resolution_clock::now();
    auto duration = duration_cast<milliseconds>(end - start);
#ifndef ONLINE_JUDGE
    cerr << "Time: " << duration.count() << " ms\n";
#endif
    return 0;
}