Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 186 ms):
#include "bits/stdc++.h"
#ifdef AlRntn
#include "debug.hpp"
#else
#define debug(...) 
#define tstr(...) 
#endif
using int64 = int64_t;
using uint64 = uint64_t;
using ll = intptr_t;
using ull = uintptr_t;
using ld = long double;
#define fi first
#define se second
#define sz(x) int64(x.size())
#define all(x) x.begin(), x.end()
#define spc ' '
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ever ;1;
constexpr int64 inf = 5e18 + 100;
constexpr int64 mod1 = 1e9+7;
constexpr int64 mod2 = 998244353;
constexpr int64 mod3 = 1e9+9;
constexpr int64 mod4 = (1ll<<31) - 1;
constexpr long double PI = 2*asinl(1.0);
int dx[4] = {0 , 1 , 0 , -1}; // clockwise from north
int dy[4] = {-1 , 0 , 1 , 0};
int dx2[8] = {0 , 1 , 1 , 1 , 0 , -1 , -1 , -1}; // clockwise from north
int dy2[8] = {-1 , -1 , 0 , 1 , 1 , 1 , 0 , -1};
const int N = 1e6 + 50, L = 25;
ll n;
std::vector<ll> A;
int32_t main(){
#ifdef AlRntn
freopen("inputf.in" , "r" , stdin); freopen("outputf.out" , "w" , stdout); freopen("errorf.out" , "w" , stderr);
#endif
    using namespace std;
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int32_t tc=1;
//#define TestCases
#ifdef TestCases
    std::cin >> tc;
#endif
    while(tc--){
        cin>>n;A.resize(n);
        for(auto &a : A) cin>>a;
        ll tot = 0;
        for(ll i = 0; i < n; i++){
            for(ll j = i+1; j < n; j++) tot += (A[i] > A[j]);
        }
        cout << n*(n-1) - tot << endl;
        std::vector<ll> B(n, 0); iota(all(B), 1);
        for(ll i = n-1; i >= 0; i--){
            ll C = A[i];
            ll pos = 0;
            for(ll j = 0; j < n; j++) if(B[j] == C) pos = j;
            for(ll k = pos-1; k >= 0; k--){
                cout << B[k+1] << spc << B[k] << endl;
                std::swap(B[k+1], B[k]);
            }
            for(ll k = 0; k < i; k++){
                cout << B[k+1] << spc << B[k] << endl;
                std::swap(B[k+1], B[k]);
            }
        }
        //assert(A == B);
    }
    return 0;
}

Solution 2 (runtime: 217 ms):
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else 
#define deb(x...)
#endif
using namespace std;
void solve();
int inv(vector<int> v){
    int ans = 0;
    int N = v.size();
    for(int i = 0;i<N;i++){
        for(int j = i + 1;j<N;j++){
            if(v[i] > v[j])ans ++;
        }
    }
    return ans;
}
signed main() {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int N;cin >> N;
    vector<int> A(N);for(auto &e : A)cin >> e;
    vector<bool> used(N + 1, false);
    vector<pair<int,int>> ans;
    for(int i = N - 1;i>=0;i--){
        for(int j = A[i] - 1;j>=1;j--){
            if(!used[j]) ans.push_back({A[i], j});
        }
        for(int j = 1;j<=A[i] - 1;j++){
            if(!used[j]) ans.push_back({j, A[i]});
        }
        for(int j = A[i] + 1;j<=N;j++){
            if(!used[j]) ans.push_back({j, A[i]});
        }
        used[A[i]] = 1;
    }
    // int val = N*(N - 1) - inv(A);
    // assert(ans.size() == val);
    cout << ans.size() << "\n";
    for(auto e : ans)cout << e.first << " " << e.second << "\n";
}