Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
// we will be back Stronger ISA
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
const int mod = 1e9 + 7;
/*
 * Make Sure That you understand the Statment Correctly
 * try always divide and conquer approach
 * always try to look at numbers in binary
 * look at all Edge Cases before submitting any problem
 * always try to look for smart brute force approaches
 */
void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i];
    vector<pair<int , int>> ans;
    set<pair<int , int>> inv;
    for (int i = 0;i < n;i++){
        for (int j = i + 1;j < n;j++){
            if (a[j] < a[i]) inv.insert({a[j] , a[i]}) , inv.insert({a[i] , a[j]});
        }
    }
    set<pair<int , int>> now;
    iota(begin(a) , end(a) , 1);
    for (int i =0;i < n;i++){
        for (int j = n - 1;j > 0;j--){
            if (!inv.contains({a[j] , a[j - 1]})){
                if (now.contains({a[j] , a[j - 1]})|| now.contains({a[j - 1] , a[j]})) {

                }else {
                    now.insert({a[j] , a[j - 1]});
                    ans.push_back({a[j], a[j - 1]});
                    ans.push_back({a[j - 1], a[j]});
                }
            }else{
                if (now.contains({a[j] , a[j - 1]}) || now.contains({a[j - 1] , a[j]})){

                }else {
                    ans.push_back({a[j], a[j - 1]});
                    now.insert({a[j] , a[j - 1]});
                    swap(a[j], a[j - 1]);
                }
            }
        }
    }
    cout << ans.size() <<'\n';
    for(auto [x , y]: ans) cout << x << ' ' << y <<'\n';
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("text.out", "r" , stdin);
    int t = 1;
//    cin >>t;
    while(t--) solve();
}


Submission (verdict: Accepted):
// we will be back Stronger ISA
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
const int mod = 1e9 + 7;
/*
 * Make Sure That you understand the Statment Correctly
 * try always divide and conquer approach
 * always try to look at numbers in binary
 * look at all Edge Cases before submitting any problem
 * always try to look for smart brute force approaches
 */
void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i];
    vector<pair<int , int>> ans;
    map<pair<int , int> , int> cnt;
    for (int i = 0;i < n;i++){
        for (int j = i + 1;j < n;j++){
            if (a[j] < a[i]) cnt[{a[j] ,a[i]}] = 1;
            else cnt[{a[i] , a[j]}] = 1 , cnt[{a[j] ,a[i]}] = 1;
        }
    }
    set<pair<int , int>> now;
    iota(begin(a) , end(a) , 1);
    for (int i =0;i < n;i++){
        for (int j = n - 1;j > 0;j--) {
            if (cnt[{a[j - 1] , a[j]}]){
                ans.push_back({a[j] , a[j - 1]});
                cnt[{a[j - 1] , a[j]}]--;
                swap(a[j] , a[j - 1]);
            }
        }
    }
    cout << ans.size() <<'\n';
    for(auto [x , y]: ans) cout << x << ' ' << y <<'\n';
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("text.out", "r" , stdin);
    int t = 1;
//    cin >>t;
    while(t--) solve();
}