Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#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;

 

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

 

typedef pair<int, int> pi;

typedef pair<ll,ll> pl;

typedef pair<ld,ld> pd;

 

typedef vector<int> vi;

typedef vector<ll> vll;

 

#define all(v)       v.begin(),v.end()

#define sz(x)        (int)(x).size()

#define alr(v)       v.rbegin(),v.rend()

#define pb           push_back

#define S            second

#define F            first

#define pow2(x)      (1<<(x))

#define sp(x)        cout<<fixed<<setprecision(6)<<x

#define output(x)    cout<<(x?"YES\n":"NO\n")

#define bp(x)        __builtin_popcount(x)

//#define int long long

template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// order_of_key (k) : Number of items strictly smaller than k .

// find_by_order(k) : K-th element in a set (counting from zero).

 

template<typename T>

void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

 

void __print(int x) {cerr << x;}

void __print(long x) {cerr << x;}

void __print(long long x) {cerr << x;}

void __print(unsigned x) {cerr << x;}

void __print(unsigned long x) {cerr << x;}

void __print(unsigned long long x) {cerr << x;}

void __print(float x) {cerr << x;}

void __print(double x) {cerr << x;}

void __print(long double x) {cerr << x;}

void __print(char x) {cerr << '\'' << x << '\'';}

void __print(const char *x) {cerr << '\"' << x << '\"';}

void __print(const string &x) {cerr << '\"' << x << '\"';}

void __print(bool x) {cerr << (x ? "true" : "false");}

 

template<typename T, typename V>

void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>

void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>

void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE

#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define debug(x...)

#endif

 

const int N=5005;

const char nl='\n';

const ll mod1=1e9+7;

const ll Binf=1e18;

const ll mod2=998244353;



ll mod_pow(ll base, ll exp) {

    ll result = 1;

    while (exp > 0) {

        if (exp % 2 == 1) {

            result = (result * base) % mod1;

        }

        base = (base * base) % mod1;

        exp /= 2;

    }

    return result;

}



// void ok(vll &fac, vll &ifac){

//     int m=sz(fac);

//     for(ll i=1;i<m;i++){

//         fac[i]=(fac[i-1]*i)%mod1;

//     }

//     ifac[m-1]=mod_pow(fac[m-1],mod1-2);

//     for(int i=m-2;i>=0;i--){

//         ifac[i]=(ifac[i+1]*(i+1))%mod1;

//     }

// }



void solve101(){

    int n;

    cin>>n;

    vector<int>v(n),a(n);

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

        cin>>v[i];

        a[i]=i+1;

    }

    vector<pair<int,int>>ans;

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

        if(v[i]!=a[i]){

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

                if(a[j]==v[i]){

                    swap(a[j],a[j+1]);

                    ans.pb({a[j],v[i]});

                }

            }

        }

    }

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

        if(v[i]<v[i+1]){

            ans.pb({v[i+1],v[i]});

            ans.pb({v[i],v[i+1]});

        }

    }

    cout<<sz(ans)<<nl;

    for(auto it:ans){

        cout<<it.F<<" "<<it.S<<nl;

    }

}



signed main(){

    cin.tie(0); 

    cout.tie(0);

    

    

    int t=1;

    // cin>>t; 

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

        // cout<<"Case #"<<i<<": ";

        solve101();  

    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

    return 0;

}

// always ch-eck for binary search >.<

 

// #ifndef ONLINE_JUDGE

//     if (fopen("input.txt", "r"))

//     {

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

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

//     }

// #endif