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

Solution 1 (runtime: 1280 ms):
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
// using Unordered_map = unordered_map<int, unordered_map<int, unordered_map<int, int>>>;

#define int long long
#define inf 1e18
#define MAXN 100005

int MOD = 1e9 + 7;
int tc;
vector<int> spf(MAXN + 1, 1);

void sieve(){spf[0] = 0;for (int i = 2; i <= MAXN; i++) {if (spf[i] == 1) {for (int j = i; j <= MAXN; j += i) {if (spf[j]== 1) spf[j] = i;}}}}
set<int> getPrimeFactors(int x){int num = x;set<int> factors;while (x != 1) {factors.insert(spf[x]);x = x / spf[x];} return factors;}
int mod_add(int a, int b, int m) { return (a % m + b % m + m) % m; }
int mod_substract(int a, int b, int m){ return (a % m - b % m + m) % m; }
int mod_mult(int a, int b) { return ((a % MOD) * (b % MOD)) % MOD; }
int mod_power(int x, unsigned int y, unsigned int m){if (y == 0){return 1;}int p = mod_power(x, y / 2, m) % m;p = (p % m * p % m) % m;return (y % 2 == 0) ? p : (x % m * p % m) % m;}
int mod_inverse(int a) { return mod_power(a, MOD - 2, MOD); }
int ceil(int a, int b) { return a / b + ((a ^ b) > 0 && a % b); }
int mod_exp(int a, int b, int m){a %= m;int res = 1;while (b > 0){if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;}return res;}
int ithbit(int num, int i){return (num & (1ll << i));}
int digsum(int n){int sum = 0;while(n > 0){sum += (n % 10);n /= 10;}return sum;}
int findXor(int num){ int mod = num%4;if(mod == 0) return num;if(mod == 1) return 1;if(mod == 2) return num+1;if(mod == 3) return 0;}
int rangeXor(int first, int last){return findXor(last) ^ findXor(first - 1);}
int highestPowerof2(int x){x |= x >> 1;x |= x >> 2;x |= x >> 4;x |= x >> 8;x |= x >> 16;return x ^ (x >> 1);}
const auto start_time = chrono::high_resolution_clock::now();
void timeTaken(){auto end_time = chrono::high_resolution_clock::now();chrono::duration<double> diff = end_time - start_time;cerr << "---------------------" << "\n";cerr << "Time Taken : " << diff.count() << " s\n";}
void showans() { cerr << "------ For test case : " << tc << " || ANS : "; }

// prefix/suffix ?


void Solve()
{
    int n; cin>>n;
    int arr[n+1];
    map<int, int> place;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        place[arr[i]] = i;
    }
    vector<int> ahead;
    int ans = 0;
    vector<pair<int,int>> over;
    map<int, bool> before;
    map<int, set<int>> overtakes;
    for(int i=1;i<=n;i++) {
        for(int j = place[i] + 1; j <= n; j++){
            over.push_back({arr[j], i});
            ans++;
        }
        for(int j = n; j > place[i]; j--){
            over.push_back({i, arr[j]});
            ans++;
        }
        for(int j = place[i]; j > i; j--){
            swap(arr[j], arr[j-1]);
            swap(place[arr[j]], place[arr[j-1]]);
            over.push_back({arr[j-1], arr[j]});
            ans++;
        }
    }
    cout<<ans<<endl;
    reverse(over.begin(), over.end());
    for(auto &p : over) cout<<p.second<<" "<<p.first<<endl;
}





signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int testcase = 1;
    // cin >> testcase; cerr<<"Multiple TCs"<<endl;
    // sieve();
    for (tc = 1; tc <= testcase; tc++)
    {
        Solve();
    }

    timeTaken();
    return 0;
}



Solution 2 (runtime: 1171 ms):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define show(x) cout<<(x)<<endl;
#define sz(x) (int)(x).size()
#define int long long int
#define all(x) (x).begin(),(x).end()
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int MAX_N = 2e5 + 1;
const int MOD = 1e9 + 7;


int modInverse(int A, int M) {
    int m0 = M;
    int y = 0, x = 1;

    if (M == 1)
        return 0;

    while (A > 1) {
        // q is quotient
        int q = A / M;
        int t = M;

        // m is remainder now, process same as
        // Euclid's algo
        M = A % M, A = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

vi seg;
vi lazy;

void lazyUpdate(int ind,int start,int end){
    if(lazy[ind]!=INT64_MAX){
        seg[ind]  = min(seg[ind],lazy[ind]);
        if(start!=end){
            lazy[2*ind+1] = min(lazy[2*ind+1],lazy[ind]);
            lazy[2*ind+2] = min(lazy[2*ind+2],lazy[ind]);
        }
        lazy[ind] = INT64_MAX;
    }
}

void build(int ind, int start, int end,vi & arr) {
    if (start == end) {
        seg[ind] = arr[start];
        return;
    }
    int mid = (start + end) / 2;
    build(2 * ind+1, start, mid,arr);
    build(2 * ind + 2, mid + 1, end,arr);
    seg[ind] = min(seg[2 * ind+1], seg[2 * ind + 2]);
}

void rangeUpdate(int ind, int start, int end, int l,int r, int val) {
    lazyUpdate(ind,start,end);
    if(r<start||l>end) return;
    if(start>=l && end<=r){
        lazy[ind] = min(lazy[ind],val);
        lazyUpdate(ind,start,end);
        return;
    }
    int mid = (start+end)/2;
    rangeUpdate(2 * ind + 1, start, mid, l,r, val);
    rangeUpdate(2 * ind + 2, mid + 1, end, l,r, val);
    seg[ind] = min(seg[2 * ind+1], seg[2 * ind + 2]);

}

int query(int ind, int start, int end, int l, int r) {
    lazyUpdate(ind,start,end);
    if(r<start||l>end) return INT64_MAX;
    if(start>=l && end<=r){
        return seg[ind];
    }
    int mid = (start + end) / 2;
    return min(query(2 * ind+1, start, mid, l, r), query(2 * ind + 2, mid + 1, end, l, r)); 
}


void solve(){
    int n;
    cin>>n;
    vi c(n),b(n);
    rep(i,n){
    	cin>>c[i];
        b[i] = i+1;
    }	
    int res=0;
    vector<P> ans;
    vi visited(n+1,0);
    for(int i=n-1;i>=0;i--){
        for(int j=c[i]-1;j>=1;j--){
            if(!visited[j]){
                ans.pb({c[i],j});
                // ans.pb({j,c[i]});
            }
        }
        for(int j=1;j<c[i];j++){
            if(!visited[j]){
                ans.pb({j,c[i]});
                // ans.pb({j,c[i]});
            }
        }
        for(int j=c[i]+1;j<=n;j++){
            if(!visited[j]){
                ans.pb({j,c[i]});
            }
        }
        visited[c[i]]=1;
    }
    cout<<ans.size()<<endl;
    for(auto it:ans){
        cout<<it.fi<<" "<<it.se<<endl;
    }
}

int32_t main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}