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

Solution 1 (runtime: 405 ms):
#include "bits/stdc++.h" 
using namespace std; 
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++) 
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++) 
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--) 
#define dbg(x) cout << #x << '=' << x << endl;
#define int long long
#define inc(v) sort(v.begin() , v.end()) 
#define dec(v) sort(v.rbegin() , v.rend()) 
typedef long double ld; 
typedef vector<int> vi; 
typedef pair<int, int> pi; 
#define F first 
#define S second 
#define pb push_back 
#define pob pop_back 
#define mp make_pair 

void solve()
{
    int n ;
    cin >> n ;
    vi v(n) ;
    int ans = n*(n-1) ;
    int c = 0 ;
    for(int i=0 ; i<n ; i++){
        cin >> v[i];
    }
    for(int i=0 ; i<n ; i++){
        for(int j=i+1 ; j<n ; j++){
            if(v[i] > v[j]){
                c++;
            }
        }
    }
    if(n==1){
        cout << 0 << '\n';
        return;
    }
    cout << ans-c << '\n';

    for(int i=n-1 ; i>=0 ; i--){
        set<int>st;
        for(int j=i ; j<n ; j++){
            st.insert(v[j]);
        }
        if(v[i] != 1){
            for(int j=v[i]-1 ; j>=1 ; j--){
                if(st.find(j) == st.end()){
                    cout <<v[i] << " " << j << '\n' ;
                }
            }
        }
        for(int j=n-1 ; j>i ; j--){
            cout << v[i] << " " << v[j] << '\n' ;
        }
    }

    return;


}

int32_t main() 
{ 
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0); 
    int T = 1 ;
    while (T--) { 
        solve();
    } 
    return 0; 
} 

Solution 2 (runtime: 280 ms):
#include <bits/stdc++.h>
#define ll long long int 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define vl vector <ll>
#define pl pair <ll,ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define big_prime 1000000000+7
struct P {
    ll x;
    ll y;
    bool operator<(const P& other) const {
        return y < other.y || (y == other.y && x < other.x);
    }
    
};

bool comp(const P &p1, const P &p2) {
    if (p1.y != p2.y) return p1.y < p2.y;
    else return p1.x < p2.x;
}
#define yon(pass) if(pass){cout << "YES" << "\n";}else{cout << "NO" << "\n";}
ll gcd(ll a, ll b) {
    while (b != 0) {
    ll tmp = a % b;
    a = b;
    b = tmp;
    }
    return a;
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
 
long long binExpo(long long base, long long exponent, long long mod) {
long long result = 1;
base = base % mod;
 
while (exponent > 0) {
 
    if (exponent % 2 == 1) {
        result = (result * base) % mod;
    }
 
 
    base = (base * base) % mod;
    exponent /= 2;
}
 
return result;
}
 
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //ll t;
    //cin >> t;
    //while (t--) {
        ll n;
        cin >> n;
        vl v(n), v2(n);
        rep(i, 0, n){ cin >> v[i]; v2[i] = (i+1);}
        vector<P> overtakes;
        for(ll i=n-1;i>0;i--){
            ll ind = -1;
            rep(j,0,n){
                if(v2[j] == v[i]){
                    ind = j;
                    break;
                }
            }
            for(ll j = ind;j>0;j--){
                P p;
                p.x = v2[j], p.y = v2[j-1];
                overtakes.PB(p);
                swap(v2[j],v2[j-1]);

            }
            rep(j,0,i){
                P p;
                p.x = v2[j+1], p.y = v2[j];
                overtakes.PB(p);
                swap(v2[j], v2[j+1]);
            }
        }
        cout << overtakes.size() << "\n";
        for(auto a : overtakes){
            cout << a.x << " " << a.y << "\n"; 
        }


    //}
    return 0;
}