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

Previous submission (verdict: Wrong answer on test 7):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> final(n);
    for(auto& val : final)  
        cin >> val;
    vector<int> initial;
    vector<vector<bool>> taken(n+1, vector<bool>(n+1, false));
    for(int i=1;i<=n;i++)
        initial.push_back(i);
    int ans = 0;
    vector<pair<int,int>> order;
    for(int i=0;i<n;i++) {
        int j = i;
        for(;j<n;j++) {
            if(initial[j] == final[i]) {
                break;
            }
        }
        for(int k=j-1;k>=i;k--) {
            swap(initial[k], initial[k+1]);
            order.push_back({initial[k], initial[k+1]});
            taken[initial[k]][initial[k+1]] = true;
            ++ans;
        }
    }
    for(int i=0;i<n;i++) {
        int j = i+1;
        for(;j<n;j++) {
            int& num1 = initial[j-1];
            int& num2 = initial[j];
            if(taken[num1][num2] == false && taken[num2][num1] == false) {
                ++ans;
                swap(num1, num2);
                order.push_back({num1, num2});
            } else {
                break;
            }
        }
        j--;
        for(;j>i;j--) {
            int& num1 = initial[j];
            int& num2 = initial[j-1];
            swap(num1, num2);
            ++ans;
            order.push_back({num2, num1});
        }
    }
    cout << ans << "\n";
    for(auto& val : order) 
        cout << val.first << " " << val.second << "\n";
    return 0;
}

Submission (verdict: Wrong answer on test 12):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> final(n);
    for(auto& val : final)  
        cin >> val;
    vector<int> initial;
    vector<vector<bool>> taken(n+1, vector<bool>(n+1, false));
    for(int i=1;i<=n;i++)
        initial.push_back(i);
    int ans = 0;
    vector<pair<int,int>> order;
    for(int i=0;i<n;i++) {
        int j = i;
        for(;j<n;j++) {
            if(initial[j] == final[i]) {
                break;
            }
        }
        for(int k=j-1;k>=i;k--) {
            swap(initial[k], initial[k+1]);
            order.push_back({initial[k], initial[k+1]});
            taken[initial[k]][initial[k+1]] = true;
            ++ans;
        }
    }
    for(int i=0;i<n;i++) {
        int j = i+1;
        for(;j<n;j++) {
            int& num1 = initial[j-1];
            int& num2 = initial[j];
            if(taken[num1][num2] == false && taken[num2][num1] == false) {
                ++ans;
                swap(num1, num2);
                taken[num1][num2] = true;
                order.push_back({num1, num2});
            } else {
                break;
            }
        }
        j--;
        for(;j>i;j--) {
            int& num1 = initial[j];
            int& num2 = initial[j-1];
            swap(num1, num2);
            ++ans;
            order.push_back({num2, num1});
        }
    }
    vector<pair<int,int>> firstorder;
    vector<int> finitial;
    for(int i=1;i<=n;i++)
        finitial.push_back(i);
    for(int i=0;i<n;i++) {
        int j = i+1;
        for(;j<n;j++) {
            int& num1 = finitial[j-1];
            int& num2 = finitial[j];
            if(taken[num1][num2] == false && taken[num2][num1] == false) {
                ++ans;
                swap(num1, num2);
                firstorder.push_back({num1, num2});
            } else {
                break;
            }
        }
        j--;
        for(;j>i;j--) {
            int& num1 = finitial[j];
            int& num2 = finitial[j-1];
            swap(num1, num2);
            ++ans;
            firstorder.push_back({num2, num1});
        }
    }
    cout << ans << "\n";
    for(auto& val : firstorder)
        cout << val.first << " " << val.second << "\n";
    for(auto& val : order) 
        cout << val.first << " " << val.second << "\n";
    return 0;
}