Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;


int main() {
    int n;
    cin >> n;

    vector<int> final_order(n);
    for (int i = 0; i < n; ++i) {
        cin >> final_order[i];
    }

    vector<int> initial_order(n);
    for (int i = 0; i < n; ++i) {
        initial_order[i] = i + 1;
    }

    vector<pair<int, int>> overtakes;
	set<pair<int,int>>st;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            if (final_order[j] > final_order[j + 1]) {
                overtakes.emplace_back(final_order[j], final_order[j + 1]);
                st.insert({final_order[j], final_order[j + 1]});
                swap(final_order[j], final_order[j + 1]);
            }
            else if(final_order[j] < final_order[j + 1] && !(st.count({final_order[j] , final_order[j + 1]})) && !(st.count({final_order[j + 1] , final_order[j]}))){
            	overtakes.emplace_back(final_order[j], final_order[j + 1]);
            	overtakes.emplace_back(final_order[j + 1], final_order[j]);
            	st.insert({final_order[j], final_order[j + 1]});
            	st.insert({final_order[j + 1], final_order[j]});
            }
        }
    }

    cout << overtakes.size() << endl;
    reverse(overtakes.begin(),overtakes.end());
    for (const auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;


int main() {
    int n;
    cin >> n;

    vector<int> final_order(n);
    for (int i = 0; i < n; ++i) {
        cin >> final_order[i];
    }

    // vector<int> initial_order(n);
    // for (int i = 0; i < n; ++i) {
        // initial_order[i] = i + 1;
    // }

    vector<pair<int, int>> overtakes;
	vector<bool> mask(n,false);
    for (int i = 0; i < n; ++i) {
    	mask[final_order[i]]=true;
    	for(int j=final_order[i]+1;j<=n;j++){
    		if(mask[j]==false){
    			overtakes.push_back({j,final_order[i]});
    		}
    	}
    	for(int j=n;j;j--){
    		if(mask[j]==false){
    			overtakes.push_back({final_order[i],j});
    		}
    	}
        // for (int j = 0; j < n - 1; ++j) {
            // if(final_order[j] < final_order[j + 1] && !(st.count({final_order[j] , final_order[j + 1]}))){
            	// overtakes.emplace_back(final_order[j], final_order[j + 1]);
            	// //overtakes.emplace_back(final_order[j + 1], final_order[j]);
            	// st.insert({final_order[j], final_order[j + 1]});
            	// swap(final_order[j], final_order[j + 1]);
            // }
            // else if (final_order[j] > final_order[j + 1] && !(st.count({final_order[j] , final_order[j + 1]}))) {
                // overtakes.emplace_back(final_order[j], final_order[j + 1]);
                // st.insert({final_order[j], final_order[j + 1]});
                // swap(final_order[j], final_order[j + 1]);
            // }
        // }
    }

    cout << overtakes.size() << endl;
    reverse(overtakes.begin(),overtakes.end());
    for (const auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}