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

Previous submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>

#define CNO cout << "NO\n"

#define CYES cout << "YES\n"

#define endl '\n'

#define ls id << 1

#define rs id << 1 | 1

#define llen (mid - l + 1)

#define rlen (r - mid)

using namespace std;

using ll = long long;

using uint = unsigned int;

using ull = unsigned long long;

using ld = long double;

using i128 = __int128;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

const ll mod = 998244353;

const int N = 1010;

int n, arr[N], h[N];

bool vis[N] = { 0 };

ll ans = 0;

string str;

vector<pii> v;



template <class T>

void chmax(T &a, T b) {

    if (a < b)

        a = b;

}



template <class T>

void chmin(T &a, T b) {

    if (a > b)

        a = b;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);

    int T = 1;

    // cin >> T;

    while (T--) {

        cin >> n;

        for (int i = 1; i <= n; ++i) {

            cin >> arr[i];

            vis[i] = 0;

        }

        iota(h + 1, h + n + 1, 1);

        for (int i = 1; i <= n; ++i) {

            if (vis[h[i]])

                continue;

            vis[h[i]] = 1;

            int p = i;

            for (int j = i - 1; j >= 1; --j) {

                v.push_back({ h[i], h[j] });

            }

            for (int j = 1; j < i; ++j) {

                v.push_back({ h[j], h[i] });

            }

            while (p < n && h[p] != arr[p]) {

                v.push_back({ h[p + 1], h[p] });

                swap(h[p], h[p + 1]);

                p++;

            }

            if (h[i] != arr[i])

                i--;

        }

        cout << v.size() << endl;

        for (auto i : v) cout << i.first << " " << i.second << endl;

    }

    return 0;

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

#define CNO cout << "NO\n"

#define CYES cout << "YES\n"

#define endl '\n'

#define ls id << 1

#define rs id << 1 | 1

#define llen (mid - l + 1)

#define rlen (r - mid)

using namespace std;

using ll = long long;

using uint = unsigned int;

using ull = unsigned long long;

using ld = long double;

using i128 = __int128;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

const ll mod = 998244353;

const int N = 1010;

int n, arr[N], h[N];

bool vis[N] = { 0 };

ll ans = 0;

string str;

vector<pii> v;



template <class T>

void chmax(T &a, T b) {

    if (a < b)

        a = b;

}



template <class T>

void chmin(T &a, T b) {

    if (a > b)

        a = b;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);

    int T = 1;

    // cin >> T;

    while (T--) {

        cin >> n;

        for (int i = 1; i <= n; ++i) {

            cin >> arr[i];

            vis[i] = 0;

        }

        iota(h + 1, h + n + 1, 1);

        for (int k = n; k >= 1; --k) {

            int i = 1;

            for (int j = 1; j <= n; ++j) {

                if (h[j] == arr[k]) {

                    i = j;

                    break;

                }

            }

            int p = i;

            for (int j = i - 1; j >= 1; --j) {

                v.push_back({ h[i], h[j] });

            }

            for (int j = 1; j < i; ++j) {

                v.push_back({ h[j], h[i] });

            }

            while (h[p] != arr[p]) {

                v.push_back({ h[p + 1], h[p] });

                swap(h[p], h[p + 1]);

                p++;

            }

            if (h[i] != arr[i])

                i--;

        }

        cout << v.size() << endl;

        for (auto i : v) cout << i.first << " " << i.second << endl;

    }

    return 0;

}