Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
/*
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);
    
    vector<pair<int,int>>ans;
    vector<int>mark(n+1);
    for(int i=0;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=1;j<=n;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();
    }

}