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

Previous submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pair<int,int>> vp_int;
typedef vector<vector<int>> vii;
typedef vector<long long> vlong;
typedef vector<vector<long long>> vlonglong;
typedef long long ll;
typedef vector<pair<ll,ll>> vp_ll;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define nl cout<<"\n"
#define MOD 1000000007
#define no cout<<"NO\n"
#define yes cout<<"YES\n"

ll binexp(ll a, ll n,ll M) {
    if (n == 0) return 1LL;
    if (n % 2) {
        ll temp = binexp(a, (n - 1) / 2,M);
        return ((a * temp)%M * temp)%M;
    }
    ll q = binexp(a, n / 2,M);
    return (q * q)%M;
}
ll lcm(ll a,ll b) {return a*(b/__gcd(a,b));}
ll pmmi(ll a,ll M) {return binexp(a,M-2,M);}

ll msb(ll n) {ll ans=-1;while(n){ans++;n=n>>1;}return ans;}
ll lsb(ll n){for(ll i=0;i<64;i++){if(n&(1<<i)) return i;}return -1;}

// bitcomplement till msb only
// for 1's complement use ~
ll bitcomplement(ll n){return n^((1<<(msb(n)+1))-1);}

void solve() {
    ll n;cin>>n;
    vlong arr(n);
    for(auto &i:arr){
        cin>>i;i--;
    }
    
    vp_ll swap;
    vlong ans(n);
    for(ll i=0;i<n;i++) ans[i]=i;
    for(ll i=0;i<n;i++){
        ll j=i;
        while(ans[j]!=arr[i]) j++;
        
        j++;
        while(j<n){
            swap.pb({ans[j],arr[i]});
            j++;
        }
        
        for(ll k=n-1;k>=i;k--){
            if(ans[k]==arr[i]) continue;
            swap.pb({arr[i],ans[k]});
        }
        
        

        j=i+1;
        while(j<n && ans[j]!=arr[i]){
            ans[j]=ans[j-1];j++;
        }
        ans[j]=ans[j-1];
        ans[i]=arr[i];
    }
    cout<<swap.size()<<"\n";
    for(auto &i:swap) cout<<i.first+1<<" "<<i.second+1<<"\n";
    
    
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t START = clock();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {solve();}

#ifndef ONLINE_JUDGE
    cout << "\nTime : " << ((float)(clock() - START)) / CLOCKS_PER_SEC << " sec\n";
#endif

    return 0;
}

Submission (verdict: Wrong answer on test 5):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pair<int,int>> vp_int;
typedef vector<vector<int>> vii;
typedef vector<long long> vlong;
typedef vector<vector<long long>> vlonglong;
typedef long long ll;
typedef vector<pair<ll,ll>> vp_ll;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define nl cout<<"\n"
#define MOD 1000000007
#define no cout<<"NO\n"
#define yes cout<<"YES\n"

ll binexp(ll a, ll n,ll M) {
    if (n == 0) return 1LL;
    if (n % 2) {
        ll temp = binexp(a, (n - 1) / 2,M);
        return ((a * temp)%M * temp)%M;
    }
    ll q = binexp(a, n / 2,M);
    return (q * q)%M;
}
ll lcm(ll a,ll b) {return a*(b/__gcd(a,b));}
ll pmmi(ll a,ll M) {return binexp(a,M-2,M);}

ll msb(ll n) {ll ans=-1;while(n){ans++;n=n>>1;}return ans;}
ll lsb(ll n){for(ll i=0;i<64;i++){if(n&(1<<i)) return i;}return -1;}

// bitcomplement till msb only
// for 1's complement use ~
ll bitcomplement(ll n){return n^((1<<(msb(n)+1))-1);}

void solve() {
    ll n;cin>>n;
    vlong arr(n);
    for(auto &i:arr){
        cin>>i;i--;
    }
    
    vp_ll swap;
    vlong ans(n);
    for(ll i=0;i<n;i++) ans[i]=i;
    for(ll i=0;i<n;i++){
        ll j=i;
        while(ans[j]!=arr[i]) j++;
        
        j++;
        while(j<n){
            swap.pb({ans[j],arr[i]});
            j++;
        }
        
        for(ll k=n-1;k>=i;k--){
            if(ans[k]==arr[i]) continue;
            swap.pb({arr[i],ans[k]});
        }
        
        

        j=i;
        while(j<n && ans[j]!=arr[i]){
            if(j==i){
                j++;continue;
            }
            ans[j]=ans[j-1];j++;
        }
        
        ans[j]=ans[j-1];
        ans[i]=arr[i];
        
        // return;
    }
    cout<<swap.size()<<"\n";
    for(auto &i:swap) cout<<i.first+1<<" "<<i.second+1<<"\n";
    
    
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t START = clock();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {solve();}

#ifndef ONLINE_JUDGE
    cout << "\nTime : " << ((float)(clock() - START)) / CLOCKS_PER_SEC << " sec\n";
#endif

    return 0;
}