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

Solution 1 (runtime: 202 ms):
/*Author: justsurfing
Go hard or go home
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define pb push_back
#define mod 1000000007
#define inf 100000000000000000
#define CHAR 256
#define all(x) x.begin(), x.end()
#define limit 100005
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define N  200005
ll fact[N + 1];
ll inv[N + 1];
ll invFact[N + 1];
bool isComputed = false;
void compute() {
    inv[0] = inv[1] = 1;

    for (int i = 2; i <= N; i++) {
        inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;
    }

    invFact[0] = invFact[1] = 1;
    for (int i = 2; i <= N; i++) {
        invFact[i] = (invFact[i - 1] * inv[i]) % mod;
    }

    fact[0] = fact[1] = 1;
    for (int i = 2; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    isComputed = true;
}
ll ncr(ll n, ll k) {
    if (!isComputed) {
        printf("Call compute function, you idiot");
    }
    else {
        return (((fact[n] * invFact[k]) % mod) * invFact[n - k]) % mod;
    }
    return -1;
}
ll power( int x, int y)
{
    ll temp = x;
    ll result = 1;
    while (y > 0) {
        if ((y & 1) == 1) // y is odd
        {
            result = (result * temp) % mod;
        }
        temp = (temp * temp) % mod;
        y = y >> 1; // y=y/2;
    }
    return result % mod;
}
void SieveOfEratosthenes(int n, vector<int>&get)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++) {

        if (prime[p] == true) {

            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p = 2; p <= n; p++)
        if (prime[p])
            // cout << p << " ";
            get.pb(p);
}
#include <vector>


int main() {
    /*Uncommment for the sieve */
    //  vector<int>get;
    //     SieveOfEratosthenes(1000005,get);
    // compute();
    //uncomment this for calc nCr
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int t, n;
    // cin >> t;?
    t = 1;
    // 1. brute force | 2. two pointers | 3. Prefix sum | 4. Binary search
    // 5. DSA | 6. Graphs | 7. DP
    // constructive fucks //string
    while (t--)
    {
        // int mod=1e9+7;
        cin >> n;
        vector<int>arr(n);
        for (auto &i : arr)cin >> i;
        vector<pair<int, int>>ans;
        vector<int>ou(n);
        for (int i = 0; i < n; i++)ou[i] = i + 1;
        for (int i = n; i >= 2; i--)
        {
            for (int j = i - 1; j >= 1; j--)
            {
                ans.pb({i, j});
            }
        }
        // for (auto i : ans)
        // {
        //     cout << i.first << " " << i.second << endl;
        // }
        map<int, int>mp;
        int c = 0;
        for (auto i : arr)
        {
            mp[i] = c;
            c++;
        }
        // for()
        for (int i = n - 1; i > 0; i--)
        {
            int cur = i;
            for (int j = n - 1; j >= mp[i] + 1; j--)
            {
                if (arr[j] > cur)
                {
                    ans.pb({cur, arr[j]});
                }
            }
        }

        cout << ans.size();
        cout << endl;
        for (auto i : ans)cout << i.first << " " << i.second << endl;


    }
    return 0;
}

Solution 2 (runtime: 1249 ms):
#include<bits/stdc++.h>
using namespace std;
const int N=230000;
int n,a[N],ans,vis[N];
struct fa{
	int x,y;
}as[N*20];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		vis[a[i]]=1;
		for(int j=a[i]+1;j<=n;j++)if(!vis[j])as[++ans]={j,a[i]};
		for(int j=n;j>=1;j--)if(!vis[j])as[++ans]={a[i],j};
//		for(int j=a[i]-1;j>=1;j--)if(!vis[j])as[++ans]={a[i],j};
	}
	cout<<ans<<endl;
	for(int i=1;i<=ans;i++){
		cout<<as[i].x<<' '<<as[i].y<<endl;
	}
	return 0;
}