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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
void solve()
{
    int n; cin >> n;
    vector<int>cars(n);
    map<int, int>mp;
    for(int i = 0; i < n; i++){
        cin >> cars[i];
    }

    int count = 0;
    vector<pair<int, int>>v;
    
    pair<int, int>temp;
    for(int i = 0; i < n; i++){
        vector<int>overtakes;
        for(int j = cars[i] + 1; j <= n; j++){
            if(mp[j] == 0){
                overtakes.push_back(j);
                overtakes.push_back(cars[i]);
            }
        }
        for(int j = overtakes.size() - 1; j >= 0; j--){
            overtakes.push_back(overtakes[j]);
        }
        for(int j = cars[i] - 1; j >= 1; j--){
            if(mp[j] == 0){
                overtakes.push_back(cars[i]);
                overtakes.push_back(j);
            }
        }
        for(int j = 0; j < overtakes.size(); j+=2){
            // cout << overtakes[j] << " " << overtakes[j + 1] << endl;
            pair<int, int>p(overtakes[j], overtakes[j + 1]);
            v.push_back(p);
        }
        mp[cars[i]]++;
    }
    for(int i = 0; i < v.size(); i++){
        int j = i + 1; 
        while(j < v.size()){
            if(v[j].second < v[i].second){
                swap(v[i], v[j]);
            }
            j++;
        }
    }
    for(auto i: v) cout << i.first << " " << i.second << endl;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll test = 1;
    // cin >> test;
    while(test--)
    {
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
void solve()
{
    int n; cin >> n;
    vector<int>cars(n);
    map<int, int>mp;
    for(int i = 0; i < n; i++){
        cin >> cars[i];
    }

    int count = 0;
    vector<pair<int, int>>v;
    
    pair<int, int>temp;
    for(int i = 0; i < n; i++){
        vector<int>overtakes;
        for(int j = cars[i] + 1; j <= n; j++){
            if(mp[j] == 0){
                overtakes.push_back(j);
                overtakes.push_back(cars[i]);
            }
        }
        for(int j = overtakes.size() - 1; j >= 0; j--){
            overtakes.push_back(overtakes[j]);
        }
        for(int j = cars[i] - 1; j >= 1; j--){
            if(mp[j] == 0){
                overtakes.push_back(cars[i]);
                overtakes.push_back(j);
            }
        }
        for(int j = 0; j < overtakes.size(); j+=2){
            // cout << overtakes[j] << " " << overtakes[j + 1] << endl;
            pair<int, int>p(overtakes[j], overtakes[j + 1]);
            v.push_back(p);
        }
        mp[cars[i]]++;
    }
    for(int i = 0; i < v.size(); i++){
        int j = i + 1; 
        while(j < v.size()){
            if(v[j].second < v[i].second){
                swap(v[i], v[j]);
            }
            j++;
        }
    }
    cout << v.size() << endl;
    for(auto i: v) cout << i.first << " " << i.second << endl;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll test = 1;
    // cin >> test;
    while(test--)
    {
        solve();
    }
    return 0;
}