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;

#define int long long
#define INF LLONG_MAX
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define all(v) v.begin(),v.end()

void solve() {
    int n;
    cin>>n;
    vi a(n);
    map<int,int>pos;
    for(int i=0;i<n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    if(n==1){
        cout<<0<<endl;
        return;
    }
    map<pair<int,int>,int>flag;
    int cnt=0;
    int n1=n*n;
    vi temp(n);
    // for(auto i : pos){
    //     cout<<i.first<<" "<<i.second<<endl;
    // }
    for(int i=0;i<n;i++)temp[i]=i+1;
    // for(auto i : temp)cout<<i<<" ";
    // cout<<endl;
    vp ans;
    while(n1--){
        for(int i=0;i<n-1;i++){
            int x=min(temp[i],temp[i+1]);
            int y=max(temp[i],temp[i+1]);
            if(flag.find({x,y})==flag.end()){
                if(temp[i]<temp[i+1]){
                    if(pos[temp[i]]<pos[temp[i+1]]){
                        cnt+=2;
                        ans.pb({temp[i+1],temp[i]});
                        ans.pb({temp[i],temp[i+1]});

                        flag[{temp[i],temp[i+1]}]=1;
                    }else{
                        cnt++;
                        ans.pb({temp[i+1],temp[i]});
                        swap(temp[i],temp[i+1]);
                    }
                }
            }
        }
    }
    cout<<cnt<<endl;
    for(auto i : ans){
        cout<<i.first<<" "<<i.second<<endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    // cin >> t;
    t=1;

    while(t--) {
        solve();
    }

    return 0;
}


Submission (verdict: Time limit exceeded on test 38):
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define INF LLONG_MAX
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define all(v) v.begin(),v.end()

void solve() {
    int n;
    cin>>n;
    vi a(n);
    map<int,int>pos;
    for(int i=0;i<n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    if(n==1){
        cout<<0<<endl;
        return;
    }
    map<pair<int,int>,int>flag;
    int cnt=0;
    int n1=n*n;
    vi temp(n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]<a[j]){
                flag[{a[i],a[j]}]=2;
                cnt+=2;
            }else{
                flag[{a[j],a[i]}]=1;
                cnt++;
            }
        }
    }
    for(int i=0;i<n;i++)temp[i]=i+1;
    // for(auto i : temp)cout<<i<<" ";
    // cout<<endl;
    vp ans;
    cout<<cnt<<endl;
    while(n1--){
        for(int i=0;i<n-1;i++){
            int mn=min(temp[i],temp[i+1]);
            int mx=max(temp[i],temp[i+1]);
            if(flag[{mn,mx}]>0){
                // cout<<"dhdh"<<endl;
                flag[{mn,mx}]--;
                ans.pb({temp[i+1],temp[i]});
                swap(temp[i],temp[i+1]);
            }
            
        }
        // for(auto i : temp)cout<<i<<" ";
        // cout<<endl;
    }
    // cout<<cnt<<endl;
    // for(auto i : flag){
    //     cout<<i.first.first<<" "<<i.first.second<<endl;
    //     cout<<i.second<<endl;
    // }
    for(auto i : ans){
        cout<<i.first<<" "<<i.second<<endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    // cin >> t;
    t=1;

    while(t--) {
        solve();
    }

    return 0;
}