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

Solution 1 (runtime: 1139 ms):
 #include <algorithm>
 #include <iostream>
 #include <bits/stdc++.h>
 using namespace std;
 #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 #define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//---MACROS--//
//                                                  -| JAI MAA SARASWATI |-
 #define vinput(v) for(int i=0;i<n;i++){cin>>v[i];}
 #define loop(i,m,n) for(int i=m;i<n;i++)
 #define vi vector<int>
 #define vll vector<long long int>
 #define pb push_back
 #define ppb pop_back
 #define MOD 1000000007
 #define MOD1 998244353
 #define nl "endl" 
 #define mp make_pair
 #define allr(x) (x).rbegin(),(x).rend()
 #define ff first
 #define sx(x) ((int)(x).size())
 #define ss second
 #define yes cout<<"YES"<<endl
 #define no cout<<"NO"<<endl
 #define big1 998244353
 #define big2 1000000007
 #define all(v) v.begin(),v.end()
 #define test cout<<'B A N K A I'<<endl
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
 int fact(int n) {
   if (n == 0 || n == 1)
   return 1;
   else
   return n * fact(n - 1);
 }
 int gcd(int a, int b)
 {
    return b == 0 ? a : gcd(b, a % b);
 }
 int nCr(int n, int r)
 {
    if(n<=0 || r<0) return 0;
    else if(r>n) return 0;
    return fact(n) / (fact(r) * fact(n - r));
 }
 bool prime(int n) {
    if (n < 2) return false;
    for (int x = 2; x*x <= n; x++) {
        if (n%x == 0) return false;
    }
    return true;
 }
 vector<int> factors(int n) {
    vector<int> f;
    for (int x = 2; x*x <= n; x++) {
    while (n%x == 0) {
        f.push_back(x);
        n /= x;
        }
    }
    if (n > 1) f.push_back(n);
    return f;
 }
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
 void solve()
 {
    int n;
    cin>>n;

    vector<int> v(n);
    vinput(v);

    vector<pair<int,int> > ans;
    for(int i =0;i<n;i++)
    {
      for(int j =0;j<n-1;j++)
      {
        if(v[j]<v[j+1])
        {
          ans.pb(mp(v[j],v[j+1]));
          swap(v[j],v[j+1]);
        }
      }
    }

    for(int i =0;i<n;i++)
    {
      for(int j =0;j<n-1;j++)
      {
        if(v[j]>v[j+1])
        {
          ans.pb(mp(v[j],v[j+1]));
          swap(v[j],v[j+1]);
        }
      }
    }
    reverse(all(ans));
    cout<<ans.size()<<endl;
    for(auto i: ans)
    {
      cout<<i.ff<<" "<<i.ss<<endl;
    }
 }
int main(){
    //std::cout<<std::setprecision(10)<<std::fixed;
    ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
#endif
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Solution 2 (runtime: 1233 ms):

// Author : Sarbojit Rana
// LinkTree : https://linktr.ee/sarbojit_rana


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<pll>> vvpll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef map<ll,ll> mll;

const ll MOD = 998244353;
const double eps = 1e-12;

#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define yes cout << "YES\n" ;
#define no cout << "NO\n" ;
#define iv(v,n) vector<ll> v(n); forn(i,n) cin >> v[i] ;


// unique sort :
// sort(all(v));
// v.resize(unique(all(v)) - v.begin()) ;

// Mathematical functions
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);} //__gcd 


ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}

ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}

ll powermod( ll x, ll y, ll mod){ ll ans = 1;if( y == 0) return 1;while(y){   if(y%2) ans = (1ll*ans*x)%mod;    x = (1ll*x*x)%mod;    y /= 2;}return ans;}

ll binexp(ll a , ll b , ll m){ll result = 1;while(b > 0){if( b& 1){result = ((result%m )*( a%m))%m ;}a = ((a%m)*(a%m))%m ;b >>= 1;}return result;}


vector<vector<long long>> matrixmultiply(const vector<vector<long long>>& matrix1, const vector<vector<long long>>& matrix2) {
    int rows = matrix1.size();
    int cols = matrix2[0].size();
    int common = matrix2.size();
    vector<vector<long long>> result(rows, vector<long long>(cols, 0));

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            for (int k = 0; k < common; k++) {
                result[i][j] += matrix1[i][k] * matrix2[k][j];
            }
        }
    }
    return result;
}



//Factorial by vector
//vll fact;
//void factorials(ll mod, ll maxi){fact.resize(maxi + 1, 1); for(int i = 2; i<= maxi ; i++) fact[i] = (fact[i-1]*i)%mod ;}
//ll nCr(ll n, ll r, ll mod){ if(r > n) return 0; ll x = (fact[r]*fact[n-r])%mod ;ll ans = (fact[n] * (powermod(x,mod-2, mod)))%mod;return ans;}
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}

bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}

bool isPerfectSquare(ll x){if (x >= 0) {ll sr = sqrt(x);return (sr * sr == x);}return false;}




int main() {
    fast_cin();
    ll n;
    cin >> n;
    vi v(n, 0), og(n, 0);
    vvi rec(n+1, vi(n+1, 0));
    vpii ans;
    map<int,int> mp;
    forn(i, n){
        og[i] = i+ 1;
        mp[og[i]] = i;
    }
    forn(i, n){
        cin >> v[i];
        int pos = mp[v[i]] ;
        int p = pos ;
        while((p < n-1) && (rec[og[p]][og[p+1]] == 0)){
            ans.push_back({og[p+1], og[p]});
            rec[og[p]][og[p+1]]++;
            rec[og[p+1]][og[p]]++;
            mp[og[p]] = p+1;
            mp[og[p+1]] = p;
            swap(og[p], og[p+1]);
            p++;
        }
        while(p > pos ){
            ans.push_back({og[p], og[p-1]});
            rec[og[p]][og[p-1]]++;
            rec[og[p-1]][og[p]]++;
            mp[og[p]] = p-1;
            mp[og[p-1]] = p;
            swap(og[p], og[p-1]);
            p--;
        }
        for(int j = pos ; j> i ; j--){
            rec[og[j]][og[j-1]]++;
            rec[og[j-1]][og[j]]++;
            ans.push_back({og[j], og[j-1]});
            mp[og[j]] = j-1;
            mp[og[j-1]] = j;
            swap(og[j], og[j-1]);
        }
        pos = i;
        while((pos > 0) && (rec[og[pos]][og[pos-1]] == 0)){
            ans.push_back({og[pos], og[pos-1]});
            rec[og[pos]][og[pos-1]]++;
            rec[og[pos-1]][og[pos]]++;
            mp[og[pos]] = pos-1;
            mp[og[pos-1]] = pos;
            swap(og[pos], og[pos-1]);
            pos--;
        }
        while(pos < i ){
            ans.push_back({og[pos+1], og[pos]});
            rec[og[pos]][og[pos+1]]++;
            rec[og[pos+1]][og[pos]]++;
            mp[og[pos]] = pos+1;
            mp[og[pos+1]] = pos;
            swap(og[pos], og[pos+1]);
            pos++;
        }
    }
    cout << ans.size() << endl;
    forn(i, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
    return 0;
}