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

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

using namespace std;

void solve(){
    int64_t n;
    cin >> n;
    vector<int64_t>c(n);
    for (int i = 0; i < n; i++){
        cin >> c[i];
    }
    if (n == 1){
        cout << 0;
    }
    else{
        int ans = 0;
        vector<vector<int64_t>>matrix(n + 1, vector<int64_t>(n + 1, 0));
        vector<int64_t>start(n, n);
        for (int i = 0; i < n; i++){
            start[i] = i + 1;
        }
        vector<pair<int64_t, int64_t>>ans_;
        for (int i = 0; i < n; i++){
            while(c[i] != start[i]){
                int j = i;
                while(c[j] != start[j]){
                    matrix[min(start[j], start[j + 1])][max(start[j], start[j + 1])] = 1;
                    pair<int64_t, int64_t>temp;
                    temp.first = start[j + 1];
                    temp.second = start[j];
                    ans_.push_back(temp);
                    ans += 1;
                    swap(start[j], start[j + 1]);
                    j += 1;
                }
            }
        }
        for (int i = 1; i < n; i++){
            pair<int64_t, int64_t>temp;
            int64_t j = i - 1;
            while(j >= 0){
                if (matrix[min(c[i], c[j])][max(c[i], c[j])] == 0){
                    ans += 1;
                    temp.first = c[i];
                    temp.second = c[j];
                    ans_.push_back(temp);
                    j -= 1;
                }
                else{
                    break;
                }
            }
            j += 1;
            for (int64_t z = j; z < i; z++){
                ans += 1;
                temp.first = c[z];
                temp.second = c[i];
                ans_.push_back(temp);
            }
        }
        cout << ans << endl;
        for (int i = 0; i < ans; i++){
            cout << ans_[i].first << ' ' << ans_[i].second << endl;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(16);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
        cout << endl;
    }
}

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

using namespace std;

void solve(){
    int64_t n;
    cin >> n;
    vector<int64_t>c(n);
    for (int i = 0; i < n; i++){
        cin >> c[i];
    }
    if (n == 1){
        cout << 0;
    }
    else{
        int ans = 0;
        vector<vector<int64_t>>matrix(n + 1, vector<int64_t>(n + 1, 0));
        vector<int64_t>start(n, n);
        for (int i = 0; i < n; i++){
            start[i] = i + 1;
        }
        vector<pair<int64_t, int64_t>>ans_;
        while (start[0] != n){
            int i = 0;
            int j = n - start[0];
            while (i != j){
                pair<int64_t, int64_t>temp;
                temp.first = start[i + 1];
                temp.second = start[i];
                ans_.push_back(temp);
                ans += 1;
                swap(start[i], start[i + 1]);
                i += 1;
            }
        }
        for (int i = 0; i < n; i++){
            int j = 0;
            while (start[j] != c[i]){
                j += 1;
            }
            if (j > i){
                while(j != i){
                    matrix[min(start[j], start[j - 1])][max(start[j], start[j - 1])] = 1;
                    pair<int64_t, int64_t>temp;
                    temp.first = start[j];
                    temp.second = start[j - 1];
                    ans_.push_back(temp);
                    ans += 1;
                    swap(start[j], start[j - 1]);
                    j -= 1;
                }
            }
            else{
                while(j != i){
                    matrix[min(start[j], start[j + 1])][max(start[j], start[j + 1])] = 1;
                    pair<int64_t, int64_t>temp;
                    temp.first = start[j + 1];
                    temp.second = start[j];
                    ans_.push_back(temp);
                    ans += 1;
                    swap(start[j], start[j + 1]);
                    j += 1;
                }
            }
        }
        cout << ans << endl;
        for (int i = 0; i < ans; i++){
            cout << ans_[i].first << ' ' << ans_[i].second << endl;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(16);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
        cout << endl;
    }
}