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

Solution 1 (runtime: 233 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD18 = 1e18;
const ll MOD9  = 1e9+7;
const ll MOD = 998244353;
#define _endl "\n"
#define p2(num) (1LL << (num))
#define _ceil(a, b) (ceil((double)(a) / (b)))
#define _floor(a, b) (floor((double)(a) / (b)))
#define all(a) a.begin(),a.end()
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN
#define printVec(vec) for (auto &x : (vec)) cout << x << " "; cout << '\n';
#define printRev(vec) for (auto it = (vec).rbegin(); it != (vec).rend(); ++it) cout << *it << " "; cout << '\n';
#define f(i,start,end) for(int i=(start);i<(end);++i)
#define fe(i,start,end) for(int i=(start);i>=(end);--i)
#define CTB(num) ([](long long n) { vector<int> bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } reverse(bin.begin(), bin.end()); return bin; }(num))
#define CTB32(num) ([](long long n) { vector<int> bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } while(bin.size() < 33) bin.push_back(0); reverse(bin.begin(), bin.end()); return bin; }(num))
#define CTB64(num) ([](long long n) { vector<int> bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } while(bin.size() < 64) bin.push_back(0); reverse(bin.begin(), bin.end()); return bin; }(num))
#define getUnique(arr) ([](auto& a) { sort(begin(a), end(a)); a.erase(unique(begin(a), end(a)), end(a)); return vector<long long>(begin(a), end(a)); })(arr)
#define checkPrime(num) ((num)<=1 ? false : (num)==2 || (num)==3 ? true : (num)%2==0 || (num)%3==0 ? false : ([](int n){for(int i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}(num)))
#define intn(p1, p2) ((p2.first < p1.first ? swap(p1, p2), 0 : 0), (p2.first > p1.second ? make_pair(LL_MAX, LL_MIN) : make_pair(max(p1.first, p2.first), min(p1.second, p2.second))))
#define pof(b, exp, MOD) ({ long long ans = 1, base = (b) % (MOD), exp_copy = (exp); while (exp_copy) { if (exp_copy % 2) ans = (ans * base) % (MOD); base = (base * base) % (MOD); exp_copy /= 2; } ans; })
#define IS_POWER(n) ([](long long n)->bool{if(n<=1)return false;for(long long b=2;b<=sqrt(n);++b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return true;return false;}(n))
#define LARGEST_BASE(n) ([](long long n)->long long{if(n<=1)return -1;for(long long b=sqrt(n);b>=2;--b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return b;return -1;}(n))
#define SMALLEST_BASE(n) ([](long long n)->long long{if(n<=1)return -1;for(long long b=2;b<=sqrt(n);++b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return b;return -1;}(n))



// using a>=b is more favourable as compared to a-b>=0, one problem gave TLE
// vector's size is returned in unsigned int and hence in minimum and maximum functions subtracting int from size can give error
// xor donot follow distributive property over +  and - , but do follow over and and or operators
// in a multiset erasing a number directly using the ms.erase(num), will remove all the occurences, while  doing that ms.erase(it.find(num)) will remove just one of the occurences
// also dont remove and erase while iterating using the auto it : method in a set or multiset
void solve() {
    int n;cin>>n;
    vector<int>v(n);
    set<int>s;
    f(i,0,n){
        cin>>v[i];
        s.insert(v[i]);
    }
    vector<pair<int,int>>ans;
   f(i,0,n){
    vector<int>v_;
     for(auto it : s){
         if(it==v[i]){
            vector<int>v1;
            int k=it+1;
            while(k<=*(s.rbegin())){
                if(s.find(k)==s.end()){k++;continue;}
                ans.push_back({k,v[i]});
                v1.push_back(k);
                k++;
            }
            fe(j,v1.size()-1,0) ans.push_back({v[i],v1[j]});
            break;
         }
         else v_.push_back(it);
     }
     fe(j,v_.size()-1,0) {ans.push_back({v[i],v_[j]});}
     s.erase(v[i]);
   }
    cout<<ans.size()<<_endl;
    for(auto it : ans){
        cout<<it.first<<" "<<it.second<<_endl;
    }
}



signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("lmaoinp.txt", "r", stdin); freopen("lmaooutput_.txt", "w", stdout);
#endif
    int test=1; //cin >> test; 
    while (test--) solve();
}

Solution 2 (runtime: 1140 ms):
////// {qovoq - forever}
//////code by Temur Daminov
#include <bits/stdc++.h>
#define sz size()
#define str string
#define bg begin()
#define ed end()
#define fr first
#define sc second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define gg exit(0);
#define bg begin()
#define nd end()
#define sz size()
#define SpeedOfMaximumUgency ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef double ld;
const long long LMAX = 1e18 + 7;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const int N = 1e6;
const int mod = 1e9 + 7;
const long long ultra_mod = (1 << 32);
using ull = unsigned long long int;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a, ll x)
{
    if(!x)
        return 1;
    if(x & 1)
        return a * binpow(a, x - 1);
    ll p = binpow(a, x / 2);
        return (p * p);
}
void open(string s) {
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
int a[1000], b[N - 1000];
bool used[1000];
signed main()
{
    SpeedOfMaximumUgency
////      open("");
    ll t = 1;
//    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int m = 0;
        for(int h = 0 ; h < n ; ++h){
            int i;
            cin >> i,
            i--;
            for(int j = i + 1 ; j < n ; ++j){
                if(!used[j]){
                    a[m] = j;
                    b[m] = i;
                    ++m;
                }
            }
            for (int j = n - 1; j > i; j--)
                if (!used[j])
                    a[m] = i, b[m] = j, m++;
            for (int j = i - 1; j >= 0; j--)
                if (!used[j])
                    a[m] = i, b[m] = j, m++;
            used[i] = true;
        }
        cout << m << "\n";
        for(int i = 0; i < m; i++)
            cout << a[i] + 1 << ' ' << b[i] + 1 << "\n";
        return 0;
    }
}
/**

**/