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

Solution 1 (runtime: 1140 ms):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int MAXN = 3e5 ;
const int INF = 1e9;
#define int long long

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            if(a[j]<a[j+1]){
                swap(a[j],a[j+1]);
                ans.push_back({a[j],a[j+1]});
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            if(a[j]>a[j+1]){
                swap(a[j],a[j+1]);
                ans.push_back({a[j],a[j+1]});
            }
        }
    }
    reverse(all(ans));
    cout<<ans.size()<<endl;
    for(auto it:ans){
        cout<<it.second<<" "<<it.first<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 218 ms):
/*
Author:
Shivam Kumar
*/
#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 ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long int
#define pb push_back
const int mod=1e9+7;
ll binaryExponentiation(ll n,ll m,ll b){ll result=1;ll power=n;if(m==0)return 1;if(m==1)return n;while(m>0){if((m&1)==1){result=(result*power)%b;}power=(power*power)%b; m=m>>1;}return result;}
ll binaryExponentiation(ll n,ll m){ll result=1;ll power=n;if(m==0)return 1;if(m==1)return n;while(m>0){if((m&1)==1){result=(result*power);}power=(power*power); m=m>>1;}return result;}
ll minv(ll a,ll b){return binaryExponentiation(a,b-2,b);}
ll add_mod(ll a,ll b,ll m){return ((a%m)+(b%m))%m;}
ll sub_mod(ll a,ll b,ll m){return ((a%m)-(b%m)+m)%m;}
ll mul_mod(ll a,ll b,ll m){return ((a%m)*(b%m))%m;}
bool isSet(ll n,ll i){ if(n & (1<<i)){return true;}return false;}
ll lcm(ll a,ll b){ return ((a*b)/__gcd(a,b));}
vector<int>get_all_digits(int x){vector<int>ans;while(x>9){ans.push_back(x%10);x/=10;}ans.push_back(x);return ans;}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
class StringHashing{
    public:
        vector<ll>powers;
        vector<ll>stringPrefixes;
        ll p=50;
       
       void calculatePrefixes(string s,ll m){
            int n=s.length();
            powers.clear();
            stringPrefixes.clear();
            powers.resize(n);
            stringPrefixes.resize(n);
            powers[0]=1;
            for(int i=1;i<n;i++){
                powers[i]=((powers[i-1]%m)*(p%m))%m;
           }
            stringPrefixes[0]=(s[0]-'a'+1)%m;

            for(int i=1;i<n;i++){
                ll t=(stringPrefixes[i-1]+(((s[i]-'a'+1)%m)*(powers[i]%m))%m)%m;
                stringPrefixes[i]=t;
                }
        }
  ll substringhash(int l,int r,ll m){
        if(l==0){
            return stringPrefixes[r];
        }

        ll a=(stringPrefixes[r]%m-stringPrefixes[l-1]%m)%m;
        a+=m;
        a%=m;
       
        ll b=powers[l];
        ll modinverse_b=binaryExponentiation(b,m-2,m);

        return (a*modinverse_b)%m;
}
};
class dsu{
    vector<int>parent,size,rank;
    public:
    dsu(int n){
        for(int i=0;i<n;i++){
        parent.push_back(i);
        size.push_back(1);
        rank.push_back(0);
        }
    }
    int findparent(int node){
        if(parent[node]==node){
            return node;
        }
        return parent[node]=findparent(parent[node]);
    }

    void unionSize(int u,int v){
        int pu=findparent(u);
        int pv=findparent(v);
        if(pu==pv){
            return;
        }
        if(size[pu]<size[pv]){
            parent[pu]=pv;
            size[pv]+=size[pu];
        }else{
            parent[pv]=pu;
            size[pv]+=size[pu];
        }
    }
  
    void unionRank(int u,int v){
        int pv=parent[v];
        int pu=parent[u];
        if(pu==pv){
            return;
        }
        if(rank[pu]==rank[pv]){
            parent[pu]=pv;
            rank[pv]++;
        }else if(rank[pv]<rank[pu]){
            parent[pv]=pu;
        }else{
            parent[pu]=pv;
        }
    }
    };
/*Z-algorithm*/

vector<int> z_function(string s){
    int n=(int)s.length();
    vector<int>z(n);
    z[0]=0;
    for(int i=1,l=0,r=0;i<n;i++){
        if(i<=r){
            z[i]=min(r-l+1,z[i-l]);
        }
        while(i+z[i]<n && s[z[i]]==s[i+z[i]]){
            z[i]++;
        }
        if(i+z[i]-1>r){
            l=i;
            r=i+z[i]-1;
        }

    }
    return z;
}
void solve(){
    int n;
    cin>>n;
    vector<int>c(n+1);
    
    vector<pair<int,int>>ans;
    vector<int>mark(n+1);
    for(int i=1;i<=n;i++){
        cin>>c[i];
        mark[c[i]]=1;
        for(int j=c[i]+1;j<=n;j++){
            if(!mark[j]){
                ans.push_back({j,c[i]});
            }

        }
        for(int j=n;j>=1;j--){
            if(!mark[j]){
                ans.push_back({c[i],j});

            }
        }
    }
    cout<<ans.size()<<'\n';
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].first<<' '<<ans[i].second<<"\n";
    }



    
    

    
    
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int t=1;
   // cin>>t;
    while(t--){
        solve();
    }

}