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 int long long 
#define  nl "\n"
#define f first
#define s second
const int mod = 1e9 + 7, inf = 1e18;
#define all(a) a.begin(),a.end()
#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++) 
#define cin(v) for(auto &i:v){cin>>i;}
#define cout(v) for(auto &i:v){cout<<i<<" ";}cout<<nl;
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); pri(_it, args); cout<<nl;}
void pri(istream_iterator<string> it) {}
template<typename T, typename... Args>
void pri(istream_iterator<string> it, T a, Args... args) {cout << *it << "  " << a << nl;pri(++it, args...);}
string dtobin(int n,int k = 0){string res = "";while(n>0 || k>0){k--;if(n&1){res += "1";}else{res += "0";}n>>= 1;}reverse(res.begin(),res.end());return res;}
int binexp(int a,int b){if(b==0){return 1;}int res = 1;while(b){if(b&1){res*= a;}b>>=1; a *= a;}return res;}
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void solve()
{
    int n;cin>>n;std::vector<int> v(n+1), id(n+1);
    forn(i, n)cin>>v[i+1];
    if(n == 1){cout<<0<<nl;return;}
    forn(i, n){
        id[v[i+1]]  = i+1;
    }
    vector<pair<int,int>>ans;
    for(int i = 1; i <= n;i++)
    {   
        int ps = id[i];
        for(int j = ps + 1; j <= n;j++)
        {
            ans.push_back({v[j], v[ps]});
        }
        for(int j = ps + 1; j <= n;j++)
        {
            ans.push_back({v[ps], v[j]});
        }

        for(int j = ps - 1 ;j >= i;j--)
        {
            ans.push_back({i, v[j]});
            id[v[j]]++;
            v[j+1] = v[j]; 
        }
    }
    reverse(all(ans));
    cout<<ans.size()<<nl;

    for(auto &x : ans)cout<<x.f<<" "<<x.s<<nl;
}
signed main()
{
    (ios_base::sync_with_stdio(false), cin.tie(NULL));
    auto begin = std::chrono::high_resolution_clock::now();
    int t;t = 1;
    // cin>>t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}


Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define  nl "\n"
#define f first
#define s second
const int mod = 1e9 + 7, inf = 1e18;
#define all(a) a.begin(),a.end()
#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++) 
#define cin(v) for(auto &i:v){cin>>i;}
#define cout(v) for(auto &i:v){cout<<i<<" ";}cout<<nl;
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); pri(_it, args); cout<<nl;}
void pri(istream_iterator<string> it) {}
template<typename T, typename... Args>
void pri(istream_iterator<string> it, T a, Args... args) {cout << *it << "  " << a << nl;pri(++it, args...);}
string dtobin(int n,int k = 0){string res = "";while(n>0 || k>0){k--;if(n&1){res += "1";}else{res += "0";}n>>= 1;}reverse(res.begin(),res.end());return res;}
int binexp(int a,int b){if(b==0){return 1;}int res = 1;while(b){if(b&1){res*= a;}b>>=1; a *= a;}return res;}
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void solve()
{
    int n;cin>>n;std::vector<int> v(n+1), id(n+1);
    forn(i, n)cin>>v[i+1];
    if(n == 1){cout<<0<<nl;return;}
    forn(i, n){
        id[v[i+1]]  = i+1;
    }
    vector<pair<int,int>>ans;
    for(int i = 1; i <= n;i++)
    {   
        int ps = id[i];
        for(int j = ps + 1; j <= n;j++)
        {
            ans.push_back({v[j], v[ps]});
        }
        for(int j = ps + 1; j <= n;j++)
        {
            ans.push_back({v[ps], v[j]});
        }

        for(int j = ps - 1 ;j >= i;j--)
        {
            ans.push_back({i, v[j]});
            id[v[j]]++;
            v[j+1] = v[j]; 
        }
    }
    reverse(all(ans));
    cout<<ans.size()<<nl;

    for(auto &x : ans)cout<<x.s<<" "<<x.f<<nl;
}
signed main()
{
    (ios_base::sync_with_stdio(false), cin.tie(NULL));
    auto begin = std::chrono::high_resolution_clock::now();
    int t;t = 1;
    // cin>>t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}