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

Solution 1 (runtime: 1202 ms):
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <climits>

using namespace std;

#define pb push_back
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define LOG(n) 31 - __builtin_clz(n)
#define nl  "\n"
#define ok  cout<<"OK\n"
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define free freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define ff first
#define ss second
#define vi vector<int>
#define vvi vector<vector<int> >
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int,int> pii;
typedef long double ld;
const long long INF = 1ll << 32;
const long long MAX_N = 1e6 + 5;
const long long MOD = 1e9 + 7;
const long long N = 9999999;
long double pi = 3.1415926535;

void show(vector<int> a) {for(auto it : a) cout<<it<<","; cout<<nl;}
int gcd(int a, int b){if(a == 0) return b; if(b == 0) return a;int r = min(a, b);while(r>0){if(a%r==0 && b%r==0){break;}r--;}return r;}

int sq(int n){if(n==0)return 0LL;int l=1,r=n;while(l<=r){int m=l+(r-l)/2;int p=m*m;if(p==n)return m;if(p<n)l=m+1;else r=m-1;}return l;}
int I;


void solve()
{
    int n;
    cin>>n;
    vector<int> c(n);
    unordered_map<int , int> mark;
    for(int &it : c) cin>>it;
    vector<pair<int , int> > ans;
    for(int i = n - 1 ; i >= 0 ; i--) {
        stack<pair<int , int> > temp;
        for(int j = c[i] - 1 ; j > 0 ; j--) {
            if(mark[j] == 1) continue ;
            ans.push_back({c[i] , j});
            temp.push({j , c[i]});
        }
        while(!temp.empty()) {
            ans.push_back(temp.top());
            temp.pop();
        }
        
        for(int j = c[i] + 1 ; j <= n ; j++) {
            if(mark[j] == 1) continue ;
            ans.push_back({j , c[i]});
        }
        mark[c[i]] = 1;
    }
    cout<<ans.size()<<endl;
    for(pair<int , int> overtake : ans) {
        cout<<overtake.first<<" "<<overtake.second<<endl;
    }
    
}

int32_t main()
{
    ios;
//    freopen("visitfj.in","r",stdin);
//    freopen("visitfj.out","w",stdout);
    int Test = 1;
//    cin>>Test;
    for(I = 1 ; I <= Test ; I++)
    {
        solve();
    }
 
 
}


Solution 2 (runtime: 280 ms):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int c[1005],a[1005];
vector <pair<int,int> > res;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i=1 ; i<=n ; i++)
    {
        cin >> c[i];
        a[i]=i;
    }
    for (int i=1 ; i<=n ; i++)
    {
        int assist;
        for (int j=1 ; j<=n ; j++)
            if (a[j]==c[i])
                assist=j;
        int ss=a[assist];
        while (a[n]!=ss)
        {
            res.push_back({a[assist+1],a[assist]});
            swap(a[assist],a[assist+1]);
            assist++;
        }
        while (a[i]!=c[i])
        {
            res.push_back({a[assist],a[assist-1]});
            swap(a[assist-1],a[assist]);
            assist--;
        }
    }
    cout << res.size() << "\n";
    for (auto u : res)
        cout << u.first << " " << u.second << "\n";
    return 0;
}