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

Previous submission (verdict: Wrong answer on test 4):
//https://codeforces.com/problemset/problem/2052/A
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m, k;
int a[N];
int b[N];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        b[i] = i;
    }
    set<pair<int, int>> s;
    vector<pair<int, int>> ans;
    for (int i = 1; i <= n; ++i) {
        int  p = 0;
        for (int j = i; j <= n; ++j) {
            if (b[j] == a[i]) {
                p = j;
                break;
            }
        }
        for (int j = p; j > i; --j) {
            int jj = j - 1;
            int t1 = b[j], t2 = b[jj];
            ans.push_back({ t1,t2 });
            if (t2 > t1) swap(t1, t2);
            swap(b[j], b[jj]);
            s.insert({ t1,t2 });
        }
    }
    int t = 0;
    vector<int> tt;
    for (int i = 1; i <= n; ++i) {
        if (b[i] > t) {
            t = b[i];
        } else {
            t = b[i];
            tt.clear();
        }
        tt.push_back(t);
        if (tt.size() >= 2) {
            int pp = tt.size();
            while (pp--)
                for (int j = tt.size() - 1; j >= 1; --j) {
                    ans.push_back({ tt[j],tt[j - 1] });
                    swap(tt[j], tt[j - 1]);
                }
        }
    }
    cout << ans.size() << "\n";
    for (auto [x, y] : ans) {
        cout << x << ' ' << y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}

Submission (verdict: Wrong answer on test 7):
//https://codeforces.com/problemset/problem/2052/A
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m, k;
int a[N];
int b[N];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        b[i] = i;
    }
    set<pair<int, int>> s;
    vector<pair<int, int>> ans;
    for (int i = 1; i <= n; ++i) {
        int  p = 0;
        for (int j = i; j <= n; ++j) {
            if (b[j] == a[i]) {
                p = j;
                break;
            }
        }
        for (int j = p; j > i; --j) {
            int jj = j - 1;
            int t1 = b[j], t2 = b[jj];
            ans.push_back({ t1,t2 });
            if (t2 > t1) swap(t1, t2);
            swap(b[j], b[jj]);
            s.insert({ t1,t2 });
        }
    }
    int t = 0;
    vector<int> tt;
    for (int i = 1; i <= n; ++i) {
        if (b[i] > t) {
            t = b[i];
        } else {
            if (tt.size() >= 2) {
                int pp = tt.size();
                while (pp--)
                    for (int j = tt.size() - 1; j >= 1; --j) {
                        ans.push_back({ tt[j],tt[j - 1] });
                        swap(tt[j], tt[j - 1]);
                    }
            }
            t = b[i];
            tt.clear();
        }
        tt.push_back(t);
       
    }
    if (tt.size() >= 2) {
        int pp = tt.size();
        while (pp--)
            for (int j = tt.size() - 1; j >= 1; --j) {
                ans.push_back({ tt[j],tt[j - 1] });
                swap(tt[j], tt[j - 1]);
            }
    }
    cout << ans.size() << "\n";
    for (auto [x, y] : ans) {
        cout << x << ' ' << y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}