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

Solution 1 (runtime: 342 ms):
/*'ॐ नमः शिवाय'*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int mod = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), c(n);
    map<int, int>ind, m;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        ind[c[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        a[i] = i + 1;
        m[a[i]] = i;
    }
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++)a[i] = i + 1;
    int i = n - 1;
    int ans = 0;
    while (i >= 0) {
        int j = m[c[i]];
        while (j < i) {
            v.push_back({a[j + 1], a[j]});
            swap(a[j], a[j + 1]);
            ans++;
            j++;
        }
        for (int i = 0; i < n; i++) {
            m[a[i]] = i;
        }
        i--;
    }
    vector<pair<int, int>> temp;
    for (int i = n; i >= 1; i--) {
        int j = ind[i];
        while (j >= 0) {
            if (c[j - 1] < i) {
                v.push_back({i, c[j - 1]});
                temp.push_back({i, c[j - 1]});
                ans += 2;
            }
            j--;
        }
    }
    int size = temp.size();
    for (int j = size - 1; j >= 0; j--) {
        int x = temp[j].first;
        int y = temp[j].second;
        v.push_back({y, x});
    }
    cout << ans << endl;
    for (int i = 0; i < v.size(); i++) {
        cout << v[i].first << " " << v[i].second << endl;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt",  "r",  stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}

Solution 2 (runtime: 1421 ms):
#pragma GCC optimize("Ofast","unroll-loops")

#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 fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define int long long

#define N 10000005

#define pYES cout<<"YES"<<endl;

#define pNO cout<<"NO"<<endl;



#define debug(x) cerr<<#x<<" "<<x<<endl;



template<typename T>

ostream& operator<<(ostream& os, const vector<T>& v) {

    os << "[ ";

    for (const auto& elem : v) os << elem << " ";

    os << "]";

    return os;

}



template<typename T>

ostream& operator<<(ostream& os, const set<T>& s) {

    os << "{ ";

    for (const auto& elem : s) os << elem << " ";

    os << "}";

    return os;

}



template<typename K, typename V>

ostream& operator<<(ostream& os, const map<K, V>& m) {

    os << "{ ";

    for (const auto& pair : m) os << "(" << pair.first << ": " << pair.second << ") ";

    os << "}";

    return os;

}



template<typename T>

ostream& operator<<(ostream& os, const unordered_set<T>& us) {

    os << "{ ";

    for (const auto& elem : us) os << elem << " ";

    os << "}";

    return os;

}



template<typename K, typename V>

ostream& operator<<(ostream& os, const unordered_map<K, V>& um) {

    os << "{ ";

    for (const auto& pair : um) os << "(" << pair.first << ": " << pair.second << ") ";

    os << "}";

    return os;

}



template<typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;



template<typename T>

using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;



int MOD=1e9+7;



struct pair_hash {

    inline std::size_t operator()(const std::pair<int,int> & v) const {

        return v.first*31+v.second;

    }

};



// ^^^^^^^^^^^^ MODULAR EXPO ^^^^^^^^^^^^^^



int modExp(int a,int b,int mod=MOD){

    int ans=1;

    while(b>0){

        if(b&1){

            ans=(ans*1LL*a)%mod;

        }

        a=(a*1LL*a)%mod;

        b=b>>1;

    }

    return ans;

}



// ^^^^^^^^^^^^ PRIME CHECK ^^^^^^^^^^^^^^



bool checkPrime(int a){

    for(int i=2;i*i<=a;i++){

        if(a%i==0) return false;

    }

    return true;

}



// ^^^^^^^^^^^^ SIEVE OF ERASTOSTHENES ^^^^^^^^^^^^^^



void sievePrime(int n){

    // prime vector stores prime check boolean

    vector<bool> prime(n+1,true);

    prime[1]=false;

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

        if(prime[i] && i*i<=n){

            for(int j=i*i;j<=n;j+=i){

                prime[j]=false;

            }

        }

    }



}



// ^^^^^^^^^^^^ EUCLID GCD ^^^^^^^^^^^^^^

int gcd(int a,int b)

{

    if(a==0) return b;

    return gcd(b%a,a);

}



int lcm(int a, int b) { return a / gcd(a, b) * b; }



long long mod=1e9+7;

int nCrModp(int n, int r, int p=mod)

{

    if (r > n - r)

        r = n - r;

    int C[r + 1];

    memset(C, 0, sizeof(C));

 

    C[0] = 1;

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

        for (int j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j - 1]) % p;

    }

    return C[r];

}



// ^^^^^^^^^^^^ TO CHECK IF NUMBER IS POWER OF TWO ^^^^^^^^^^^^^^



bool isPowerOfTwo(int x)

{

    return x && (!(x & (x - 1)));

}



void dfs(vector<set<int>>& adj,int node,vector<bool>& vis){

    vis[node]=true;

    for(auto i : adj[node]){

        if(!vis[i]){

            dfs(adj,i,vis);

        }

    }

}



void solve(){

    int n;

    cin>>n;

    vector<int> c(n);

    for(int i=0;i<n;i++) cin>>c[i];

    vector<vector<int>> ans;

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

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

    //         if(c[j]>c[i]){

    //             ans.push_back({c[j],c[i]});

    //         }

    //     }

    //     // for(int j=i+1;j<n;j++){

    //     //     if(c[j]>c[i]){

    //     //         ans.push_back({c[j],c[i]});

    //     //         ans.push_back({c[i],c[j]});

    //     //     }

    //     // }

    // }

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

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

    //     //     if(c[j]>c[i]){

    //     //         ans.push_back({c[j],c[i]});

    //     //     }

    //     // }

    //     for(int j=i+1;j<n;j++){

    //         if(c[j]>c[i]){

    //             ans.push_back({c[j],c[i]});

    //             ans.push_back({c[i],c[j]});

    //         }

    //     }

    // }

    set<int> st;

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

        for(int j=c[i]+1;j<=n;j++){

            if(st.find(j)==st.end()) ans.push_back({j,c[i]});

            //cout<<j<<" "<<c[i]<<endl;

        }

        for(int j=n;j>=1;j--){

            if(st.find(j)==st.end() && j!=c[i]) ans.push_back({c[i],j});

            // cout<<c[i]<<" "<<j<<endl;

        }

        st.insert(c[i]);

    }

    cout<<ans.size()<<endl;

    for(auto i : ans){

        cout<<i[0]<<" "<<i[1]<<endl;

    }

}



signed main(){

    fastio;

    #ifndef ONLINE_JUDGE

    freopen("input.txt","r",stdin);

    freopen("output.txt","w",stdout);

    #endif

    int t=1;

    // cin>>t;

    for(int i=1;i<=t;i++){

        solve();

    }

    return 0;

}