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

Solution 1 (runtime: 281 ms):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <functional>

 

using namespace __gnu_pbds;

using namespace std;

 

#define int long long

#define F first

#define S second

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

 

const int MOD = 1e9 + 7;

int powMOD(int x, int n) {

    int res = 1;

    while(n > 0) {

        if(n % 2) {

            res *= x;

            res %= MOD;

        }

        x *= x;

        x %= MOD;

        n >>= 1;

    }

    return res;

}

 

int n;

void solve() {

    cin >> n;

    int a[n];

    bool vis[n];

    for(int i = 0; i < n; i++) {

        cin >> a[i];

        a[i]--;

        vis[i] = false;

    }

    

    vector<pair<int, int>> res;

    

    // 0 4 3 1 2

    

    for(int i = n - 1; i >= 0; i--) {

        int current = a[i];

        for(int j = current - 1; j >= 0; j--) {

            if(vis[j] == false) {

                res.push_back({current, j});

            }

        }

        for(int j = 0; j < current; j++) {

            if(vis[j] == false) {

                res.push_back({j, current});

            }

        }

        set<int> st;

        for(int j = i - 1; j >= 0; j--) {

            if(a[j] > current) {

                st.insert(a[j]);

            }

        }

        

        for(auto x: st) {

            res.push_back({x, current});

        }

        vis[current] = true;

    }

    

    cout << res.size() << "\n";

    for(int i = 0; i < res.size(); i++) {

        cout << res[i].first + 1 << " " << res[i].second + 1 << "\n";

    }

}

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t = 1;

    // cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}



Solution 2 (runtime: 1312 ms):
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
 
 
void init_code(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
    #endif 
}
bool cc(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first)
        return a.first < b.first;

    return a.second > b.second;
}
int main(){
	init_code();
	int t=1;
	while(t-->0){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		vector<pair<int,int>> vp;
		set<int> st;
		for(int i=0;i<n;i++){
			int num = arr[i] ;
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({j,arr[i]});
			}
			for(int j=n;j>arr[i];j--){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			for(int j=arr[i]-1;j>=1;j--){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			st.insert(arr[i]);
		}
		cout<<vp.size()<<endl;
		for(auto it:vp){
			cout<<it.first<<" "<<it.second<<endl;
		}
	}
}