Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 5):
// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
// In the name of Allah.
// یا علی مدد
/* 	* In the name of GOD 
	* Thanks God */
/*
    \        /      /\     ----------    /\       |\    |
     \      /      /  \        |        /  \      | \   |
      \    /      /----\       |       /----\     |  \  |
       \  /      /      \      |      /      \    |   \ |
        \/      /        \     |     /        \   |    \|
        
⠀⠀⠀⠀⠀⢀⣾⠿⢷⣤⣄⣀⣀⡀⢀⣀⣠⣤⣤⣴⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣤⣤⣄⣀⡀⠀⣀⣀⣠⣤⡾⠿⣷⡀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣸⡏⣿⣦⡈⠉⠛⠻⢿⣿⡿⠛⢉⣡⣴⣶⣿⡿⠟⠁⠈⠻⢿⣿⣷⣦⣌⡉⠛⢿⣿⡿⠟⠛⠉⠁⣠⣶⠸⣧⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣿⠀⣿⣿⣿⣦⡀⠀⢈⠏⠀⣴⣿⠟⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⣿⣧⠀⠹⡅⠀⠀⣴⣿⣿⣿⠀⣿⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣿⠀⢿⣿⣿⣿⣷⠀⠀⠀⣠⣿⠃⠀⠀⠀⠀⠀⢀⣠⣄⠀⠀⠀⠀⠀⠀⠘⢿⣄⠀⠈⠀⣼⣿⣿⣿⣿⠀⢿⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣿⠀⢸⣿⣿⣿⡿⢁⣴⡾⠛⢁⣠⣤⣶⣶⣶⣿⠿⠋⠙⠿⣿⣶⣶⣶⣤⣄⠈⠛⢷⣦⣸⣿⣿⣿⣿⣿⠄⣿⡇⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢿⣷⣄⠹⡿⠋⠀⣸⡿⠃⣰⠿⠋⠉⠉⠉⠀⢀⡤⠀⠀⢤⡀⠀⠉⠉⠉⠙⠿⣆⠐⢿⣏⠈⠻⣿⡿⣃⣾⡿⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠈⣿⣿⣻⠁⢠⠾⠋⠀⠊⠁⠀⢀⣤⣤⣤⣴⣿⠀⠀⠀⠀⣿⣦⣤⣤⣤⡀⠀⠈⠑⠀⠙⠳⡄⠉⢹⣿⣿⡁⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢠⣾⣿⣿⠁⠀⠁⠀⠀⠀⠀⠒⠚⠛⠋⠁⠀⠀⠈⢀⡀⠀⡀⠁⠀⠀⠈⠙⠛⠓⠒⠀⠀⠀⠀⠈⠀⠈⢿⣿⣿⡆⠀⠀⠀⠀
⠀⠀⠀⠀⣸⣿⣿⠇⠀⠀⠀⠀⠀⢀⣴⠞⠀⢀⣀⣠⣤⡶⠟⠉⠀⠀⠉⠻⢶⣤⣄⣀⡀⠀⠱⣦⡀⠀⠀⠀⠀⠀⠸⣿⣿⣇⠀⠀⠀⠀
⠀⠀⢀⣾⣿⠟⠁⠀⠀⣠⡖⢀⣴⡿⠋⠀⢠⡟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢿⡄⠀⠘⢿⣶⡄⢲⣄⠀⠀⠈⠻⣿⣷⡀⠀⠀
⠀⢠⣿⣿⠋⠀⠀⣠⣾⡟⢠⣿⠏⠀⠀⠀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⠀⠀⠀⠙⣿⡄⢻⣷⣄⠀⠀⠘⣿⣿⡄⠀
⢠⣿⣿⠁⠀⠀⢰⣿⣿⡇⢸⡟⠐⢿⣿⣷⣶⣦⣤⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⣤⣴⣶⣾⣿⡿⠂⢹⡇⢸⣿⣯⠀⠀⠀⠈⢿⣿⡄
⣼⣿⡇⠀⠀⠀⢸⣿⣿⣧⠀⠃⠀⠀⠸⣧⡘⠋⣹⣿⣧⡀⠀⠀⠀⠀⠀⠀⢀⣾⣿⡏⠙⢃⣾⠇⠀⠀⠘⠀⣼⣿⣿⣇⠀⠀⠀⠸⣿⣷
⣿⣿⢠⠄⠀⠀⢸⣿⣿⣿⡷⠀⠀⠀⠀⠉⠛⠛⠛⢿⣿⣷⠀⠀⠀⠀⠀⠀⣾⣿⡿⠛⠛⠛⠉⠀⠀⠀⠀⢸⣿⣿⣿⡏⠀⠀⠀⡄⣿⣿
⣿⣿⣿⡄⠀⠀⠈⠿⣿⣿⣷⣤⣀⠀⠀⠀⠀⠀⢀⣾⠿⠋⠀⠀⠀⠀⠀⠀⠙⢿⣿⠀⠀⠀⠀⠀⠀⢀⣤⣾⣿⣿⡿⠃⠀⠀⠀⣿⣿⣿
⢸⣿⣿⡇⣤⠀⠀⠀⢻⣿⣿⣆⠀⠀⠀⠀⠀⠀⣼⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣧⠀⠀⠀⠀⠀⠁⣠⣿⣿⡟⠀⠀⠀⣀⢸⣿⣿⡇
⠀⠋⢸⣿⣿⡆⠀⠀⠀⢻⣿⣿⡆⠀⠀⠀⠀⣸⡟⣠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣆⢻⣇⠀⠀⠀⠀⢠⣿⣿⡟⠀⠀⠀⢠⣿⣾⣧⠘⠀
⠀⠀⢸⣿⣿⣿⡀⣤⠀⠀⠹⣿⣿⢠⡄⠀⠀⡿⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⢿⠀⠀⢠⣆⣾⣿⠏⠀⠀⣠⠀⣾⣿⣿⡏⠀⠀
⠀⠀⠀⢻⣿⣿⣷⣿⣷⣄⠀⠉⣿⣿⣷⣄⠀⠁⢰⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣆⠈⠀⣠⣾⣿⣿⠋⠀⣠⣾⣿⣾⣿⢿⡟⠁⠀⠀
⠀⠀⠀⠀⠙⠘⢿⣿⣿⣿⣷⣄⡈⠉⠙⣿⣿⡆⢻⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡟⢸⣿⣿⠋⠉⢁⣠⣾⣿⣿⣿⡿⠃⠈⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠙⠛⠎⢿⣿⣿⣶⣶⣿⡛⢧⠈⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⠃⡼⠛⣿⣶⣶⣿⣿⡿⠁⠛⠋⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠿⣿⣧⢤⣤⣈⠙⢿⣶⣶⣦⣤⣶⣶⡿⠛⣁⣠⡤⣼⣿⡿⠍⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠐⢻⣿⡖⠶⠤⠄⠀⠀⠉⢻⡟⠉⠀⠀⠠⠤⢶⢲⣿⡟⠒⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠊⢹⣿⣝⣓⡂⠀⣀⣀⣨⣇⣀⣀⡀⢐⣚⣫⣿⡟⠉⠒⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⡛⠋⠉⠛⠛⠉⠙⢛⣻⣿⣿⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠻⠿⣶⣦⣤⣶⠾⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast") 
// #pragma GCC target("avx,avx2,fma")
using namespace std;
using ll=long long;
using ld=long double;
using V=vector<ll>;
using VP=vector<pair<ll,ll>>;
using VS=vector<string>;
using PII=pair<ll,ll>;
#define superfast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(NULL);
#define FOR(i,a)for(ll i=0; i < ll(a); i++)
#define FOR2(i,a,b) for(ll i=a; i < ll(b); i++)
#define FOR3(i,a) for(ll i=a-1; i >=0; i--)
#define FOR4(i,a,b) for(ll i=b-1; i >=a; i--)
#define FORO(i,a) for(ll i=0; i < ll(a.size()); i++)
#define FORM(i,a) for(ll i=ll(a.size())-1; i >=0; i--)
#define FORCH(i,c) for( __typeof((c).begin() ) i =(c).begin(); i !=(c).end(); ++i )
// #define FORCHM(i,c) for( __typeof((c).rbegin() ) i =(c).rbegin()-1; i >=(c).begin(); --i )
#define llc(a) ll a; cin>>a;
#define llc2(a,b) ll a,b; cin>>a>>b;
#define sc(a) string a; cin>>a;
#define chc(a) char a; cin>>a;
#define pb              push_back
#define MIN(v) min_element(v.begin(),v.end())
#define MAX(v) max_element(v.begin(),v.end())
#define fi              first
#define se              second
#define endl            "\n"
#define ub(a,m) upper_bound(a.begin(),a.end(),m)-a.begin()
#define lb(a,m) lower_bound(a.begin(),a.end(),m)-a.begin()
#define yes             cout<<"YES\n";
#define no             cout<<"NO\n";
#define baseh             cout<<"\n";
#define out(x)             cout<<x<<'\n';
#define outsp(x)             cout<<x<<' ';
#define out2(x,y)             cout<<x<<' '<<y<<'\n';
#define in(x)             cin>>x;
#define in2(x,y)             cin>>x;cin>>y;
#define all(x)      (x).begin(),(x).end()
#define md(a,b)       (a%b+b)%b
#define mp(a,b)        make_pair(a,b)
const ll inf  =       LLONG_MAX-1;
const ll ninf =       LLONG_MIN+1;
constexpr ld PI=2*asinl(1.0);
template<typename T>
void SORT(T & A){
    sort(A.begin(),A.end());
}

template<typename T>
void SORTO(T & A){
    sort(A.rbegin(),A.rend());
}

template<typename T>
void CIN(T& a,ll n=-1){
(n == -1) ? n=a.size() : n += 0;
    FOR(i,n) cin>>a[i];
}
template<typename T>
void COUT(T & a,ll n=-1){
(n == -1) ? n=a.size() : n += 0;
    FOR(i,n){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
template<typename T>
void EMPTY(T & a,ll t=0){
    FOR(i,a.size()) a[i]=t;
}
template<typename T>
ll SUM(T a ,ll l=0,ll r=-1){
(r == -1) ? r=a.size() : r += 0;
    ll s=0;
    FOR2(i,l,r) s += a[i];
    return s;
}
template<typename T>
ll FIND(T a,ll b){
    FOR(i,a.size()){
        if(a[i] == b) return i;
    }
    return -1;
}
ll GOUS(ll start,ll end,ll amount){
    return((start+end)*amount)/2;
}
bool ISPRIME(ll n){
  if(n<2)return false;
  for(int i=2;i<=sqrt(n);i++){
    if(n%i==0 && i!=0 && n!=i){
      return false;
    }
  }
  return true;
}
ll GCD(ll a,ll b){
    if(b==0){
      return a;
    }
    return GCD(b,a%b);
}
ll LCM(ll a,ll b){ return(a / GCD(a,b)) * b; }

bool ISDIGIT(char f){
  return(f>='0'&&f<='9');
}

string ADDBIN(string a,string b){
  string result="";
  ll hal=0;
  ll size_a=a.size() - 1;
  ll size_b=b.size() - 1;
  while(size_a >= 0 || size_b >= 0 || hal == 1){
    hal +=((size_a >= 0) ? a[size_a] - '0' : 0);
    hal +=((size_b >= 0) ? b[size_b] - '0' : 0);
    result=char(hal % 2+'0')+result;
    hal /= 2;
    size_a--;
    size_b--;
  }
  return result;
}


ld EVAL(string s){
  string ma;
  FORO(i,s){
    if(s[i]!=' '){
      ma+=s[i];
    }
  }
  V adad;
  vector<char> amal;
  FORO(i,ma){
    if(ma[i]=='('){
      ld iter=0;
      iter++;
      string e="";
      i++;
      while(true){
        if(ma[i]==')'){
          iter--;
          if(iter==0){
            adad.pb(EVAL(e));
            break;
          }
        }
        if(ma[i]=='(')iter++;
        e+=ma[i];
        i++;
      }
    }
    else if(ISDIGIT(ma[i])){
      string r="";
      r+=ma[i];
      while(ISDIGIT(ma[i+1])){
        r+=ma[i+1];
        i++;
      }
      adad.pb(stoi(r));
    }
    else{
      amal.pb(ma[i]);
    }
  }
  FORO(i,amal){
    if(amal[i]=='/'){
      if(adad[i+1]==0){
        return ninf;
      }
      adad[i]=adad[i]/adad[i+1];
      adad.erase(adad.begin()+i+1);
      amal.erase(amal.begin()+i);
      i--;
    }
    else if(amal[i]=='*'){
      adad[i]=adad[i]*adad[i+1];
      adad.erase(adad.begin()+i+1);
      amal.erase(amal.begin()+i);
      i--;
    }
  }
  if(adad.size()==1){
    return adad[0];
  }
  ld javab=adad[0];
  FORO(i,amal){
    if(amal[i]=='+'){
      javab+=adad[i+1];
    }
    else{
      javab-=adad[i+1];
    }
  }

  return javab;
}

string BIN_TO(ll n,ll m){  
    if(n == 0) return "";  
    if(n%m < 10)  
        return BIN_TO(n/m,m)+(char)('0'+n%m);  
    else  
        return BIN_TO(n/m,m)+(char)('A'+(n%m-10));  
}

ll POWM(ll n,ll k,ll MOD){
    if(k == 0)
        return 1;
    ll half=POWM(n,k / 2,MOD);
    half =(half * half) % MOD;
    if(k % 2 != 0)
        half =(half * n) % MOD;
    return half;
}

ll POW(ll n,ll k){
    if(k == 0)
        return 1;
    ll half=POW(n,k / 2);
    half =(half * half);
    if(k % 2 != 0)
        half =(half * n);
    return half;
}

V DIVISIOR(ll n){
  V a;
  startn:
  FOR2(i,2,n+1){
    if(n%i==0){
      a.pb(i);
      n/=i;
      break;
    }
  }
  if(n!=1){
    goto startn;
  }
  return a;
}




ll FACT(ll n){
  ll ans=1;
  FOR2(i,2,n+1){
    ans*=i;
  }
  return ans;
}

ll CHOICE(ll n,ll k){
    vector<vector<ll>> C(n+1,vector<ll>(k+1,0));
    for(ll i=0; i <= n; ++i){
        for(ll j=0; j <= min(i,k); ++j){
            if(j == 0 || j == i){
                C[i][j]=1;
            } else{
                C[i][j]=C[i - 1][j - 1]+C[i - 1][j];
            }
        }
    }
    return C[n][k];
}

ll LOG(ll a,ll b){
  return log(a)/log(b);
}

bool ISSORTED(V a){
  FORO(i,a){
    if(i>0&&a[i]<a[i-1])return false;
  }
  return true;
}

bool MORBAKAMEL(ll num){
    if(num < 0) return false;
    ll root=static_cast<ll>(sqrt(num));
    return num == root * root;
}

string TO_UPPER(string a){ FORO(i,a) if(a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string TO_LOWER(string a){ FORO(i,a) if(a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }

string TO_BIN(ll x,ll y){
  string ans;
  while(x>0){
    ans=to_string(x%y)+ans;
    x/=y;
  }
  return ans;
}

ll sumdigit(ll n){
  ll ans=0;
  while(n){
    ans+=n%10;
    n/=10;
  }
  return ans;
}

void shiftElement(V& arr, ll pos, ll shift) {
  // cout<<pos<<' '<<shift<<'|';
  ll n = arr.size();
  if (shift == 0) return;
  ll newPos = (pos + shift) % n;
  if (newPos < 0) newPos += n;
  ll temp = arr[pos];
  if (shift > 0) {
      for (ll i = pos; i < newPos; ++i) {
          arr[i] = arr[i + 1];
      }
  } 
  else {
      for (ll i = pos; i > newPos; --i) {
          arr[i] = arr[i - 1];
      }
  }
  arr[newPos] = temp;
}

const ll MOD=998244353,MAXN=3008;

void SOLVE(){
  llc(n);
  V a(n);
  map<ll,ll> b;
  vector<PII> ans;
  CIN(a);
  FORO(i,a){
    b[a[i]-1]=i;
  }
  FOR(i,n){
    vector<PII> hal;
    FOR2(j,b[i]+1,n){
      if(a[j]<=i+1)continue;
      hal.pb({i+1,a[j]});
    }
    FOR4(j,i,n){
      if(a[j]==i+1)continue;
      hal.pb({a[j],i+1});
    }
    FOR2(j,min(i,b[i]),max(b[i],i)){
      // cout<<a[j]<<'/';
      if(i>b[i]){
        b[a[j]-1]--;
      }
      else if(i<b[i]){
        b[a[j]-1]++;
      }
    }
    // COUT(a);
    shiftElement(a,b[i],i-(b[i]));
    FOR3(j,hal.size()){
      ans.pb(hal[j]);
    }
    // COUT(a);
  }
  out(ans.size());
  FORO(i,ans){
    out2(ans[i].fi,ans[i].se);
  }
}

int main(){
  // precompute();
  // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  superfast;
  // llc(t);
  // while(t--)
    SOLVE();
  cerr <<endl<< "Time elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC<<" s.\n";
}



//use pop_back bejai erase

Submission (verdict: Wrong answer on test 3):
// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
// In the name of Allah.
// یا علی مدد
/* 	* In the name of GOD 
	* Thanks God */
/*
    \        /      /\     ----------    /\       |\    |
     \      /      /  \        |        /  \      | \   |
      \    /      /----\       |       /----\     |  \  |
       \  /      /      \      |      /      \    |   \ |
        \/      /        \     |     /        \   |    \|
        
⠀⠀⠀⠀⠀⢀⣾⠿⢷⣤⣄⣀⣀⡀⢀⣀⣠⣤⣤⣴⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣤⣤⣄⣀⡀⠀⣀⣀⣠⣤⡾⠿⣷⡀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣸⡏⣿⣦⡈⠉⠛⠻⢿⣿⡿⠛⢉⣡⣴⣶⣿⡿⠟⠁⠈⠻⢿⣿⣷⣦⣌⡉⠛⢿⣿⡿⠟⠛⠉⠁⣠⣶⠸⣧⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣿⠀⣿⣿⣿⣦⡀⠀⢈⠏⠀⣴⣿⠟⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⣿⣧⠀⠹⡅⠀⠀⣴⣿⣿⣿⠀⣿⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣿⠀⢿⣿⣿⣿⣷⠀⠀⠀⣠⣿⠃⠀⠀⠀⠀⠀⢀⣠⣄⠀⠀⠀⠀⠀⠀⠘⢿⣄⠀⠈⠀⣼⣿⣿⣿⣿⠀⢿⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣿⠀⢸⣿⣿⣿⡿⢁⣴⡾⠛⢁⣠⣤⣶⣶⣶⣿⠿⠋⠙⠿⣿⣶⣶⣶⣤⣄⠈⠛⢷⣦⣸⣿⣿⣿⣿⣿⠄⣿⡇⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢿⣷⣄⠹⡿⠋⠀⣸⡿⠃⣰⠿⠋⠉⠉⠉⠀⢀⡤⠀⠀⢤⡀⠀⠉⠉⠉⠙⠿⣆⠐⢿⣏⠈⠻⣿⡿⣃⣾⡿⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠈⣿⣿⣻⠁⢠⠾⠋⠀⠊⠁⠀⢀⣤⣤⣤⣴⣿⠀⠀⠀⠀⣿⣦⣤⣤⣤⡀⠀⠈⠑⠀⠙⠳⡄⠉⢹⣿⣿⡁⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢠⣾⣿⣿⠁⠀⠁⠀⠀⠀⠀⠒⠚⠛⠋⠁⠀⠀⠈⢀⡀⠀⡀⠁⠀⠀⠈⠙⠛⠓⠒⠀⠀⠀⠀⠈⠀⠈⢿⣿⣿⡆⠀⠀⠀⠀
⠀⠀⠀⠀⣸⣿⣿⠇⠀⠀⠀⠀⠀⢀⣴⠞⠀⢀⣀⣠⣤⡶⠟⠉⠀⠀⠉⠻⢶⣤⣄⣀⡀⠀⠱⣦⡀⠀⠀⠀⠀⠀⠸⣿⣿⣇⠀⠀⠀⠀
⠀⠀⢀⣾⣿⠟⠁⠀⠀⣠⡖⢀⣴⡿⠋⠀⢠⡟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢿⡄⠀⠘⢿⣶⡄⢲⣄⠀⠀⠈⠻⣿⣷⡀⠀⠀
⠀⢠⣿⣿⠋⠀⠀⣠⣾⡟⢠⣿⠏⠀⠀⠀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⠀⠀⠀⠙⣿⡄⢻⣷⣄⠀⠀⠘⣿⣿⡄⠀
⢠⣿⣿⠁⠀⠀⢰⣿⣿⡇⢸⡟⠐⢿⣿⣷⣶⣦⣤⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⣤⣴⣶⣾⣿⡿⠂⢹⡇⢸⣿⣯⠀⠀⠀⠈⢿⣿⡄
⣼⣿⡇⠀⠀⠀⢸⣿⣿⣧⠀⠃⠀⠀⠸⣧⡘⠋⣹⣿⣧⡀⠀⠀⠀⠀⠀⠀⢀⣾⣿⡏⠙⢃⣾⠇⠀⠀⠘⠀⣼⣿⣿⣇⠀⠀⠀⠸⣿⣷
⣿⣿⢠⠄⠀⠀⢸⣿⣿⣿⡷⠀⠀⠀⠀⠉⠛⠛⠛⢿⣿⣷⠀⠀⠀⠀⠀⠀⣾⣿⡿⠛⠛⠛⠉⠀⠀⠀⠀⢸⣿⣿⣿⡏⠀⠀⠀⡄⣿⣿
⣿⣿⣿⡄⠀⠀⠈⠿⣿⣿⣷⣤⣀⠀⠀⠀⠀⠀⢀⣾⠿⠋⠀⠀⠀⠀⠀⠀⠙⢿⣿⠀⠀⠀⠀⠀⠀⢀⣤⣾⣿⣿⡿⠃⠀⠀⠀⣿⣿⣿
⢸⣿⣿⡇⣤⠀⠀⠀⢻⣿⣿⣆⠀⠀⠀⠀⠀⠀⣼⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣧⠀⠀⠀⠀⠀⠁⣠⣿⣿⡟⠀⠀⠀⣀⢸⣿⣿⡇
⠀⠋⢸⣿⣿⡆⠀⠀⠀⢻⣿⣿⡆⠀⠀⠀⠀⣸⡟⣠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣆⢻⣇⠀⠀⠀⠀⢠⣿⣿⡟⠀⠀⠀⢠⣿⣾⣧⠘⠀
⠀⠀⢸⣿⣿⣿⡀⣤⠀⠀⠹⣿⣿⢠⡄⠀⠀⡿⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⢿⠀⠀⢠⣆⣾⣿⠏⠀⠀⣠⠀⣾⣿⣿⡏⠀⠀
⠀⠀⠀⢻⣿⣿⣷⣿⣷⣄⠀⠉⣿⣿⣷⣄⠀⠁⢰⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣆⠈⠀⣠⣾⣿⣿⠋⠀⣠⣾⣿⣾⣿⢿⡟⠁⠀⠀
⠀⠀⠀⠀⠙⠘⢿⣿⣿⣿⣷⣄⡈⠉⠙⣿⣿⡆⢻⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡟⢸⣿⣿⠋⠉⢁⣠⣾⣿⣿⣿⡿⠃⠈⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠙⠛⠎⢿⣿⣿⣶⣶⣿⡛⢧⠈⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⠃⡼⠛⣿⣶⣶⣿⣿⡿⠁⠛⠋⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠿⣿⣧⢤⣤⣈⠙⢿⣶⣶⣦⣤⣶⣶⡿⠛⣁⣠⡤⣼⣿⡿⠍⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠐⢻⣿⡖⠶⠤⠄⠀⠀⠉⢻⡟⠉⠀⠀⠠⠤⢶⢲⣿⡟⠒⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠊⢹⣿⣝⣓⡂⠀⣀⣀⣨⣇⣀⣀⡀⢐⣚⣫⣿⡟⠉⠒⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⡛⠋⠉⠛⠛⠉⠙⢛⣻⣿⣿⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠻⠿⣶⣦⣤⣶⠾⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast") 
// #pragma GCC target("avx,avx2,fma")
using namespace std;
using ll=long long;
using ld=long double;
using V=vector<ll>;
using VP=vector<pair<ll,ll>>;
using VS=vector<string>;
using PII=pair<ll,ll>;
#define superfast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(NULL);
#define FOR(i,a)for(ll i=0; i < ll(a); i++)
#define FOR2(i,a,b) for(ll i=a; i < ll(b); i++)
#define FOR3(i,a) for(ll i=a-1; i >=0; i--)
#define FOR4(i,a,b) for(ll i=b-1; i >=a; i--)
#define FORO(i,a) for(ll i=0; i < ll(a.size()); i++)
#define FORM(i,a) for(ll i=ll(a.size())-1; i >=0; i--)
#define FORCH(i,c) for( __typeof((c).begin() ) i =(c).begin(); i !=(c).end(); ++i )
// #define FORCHM(i,c) for( __typeof((c).rbegin() ) i =(c).rbegin()-1; i >=(c).begin(); --i )
#define llc(a) ll a; cin>>a;
#define llc2(a,b) ll a,b; cin>>a>>b;
#define sc(a) string a; cin>>a;
#define chc(a) char a; cin>>a;
#define pb              push_back
#define MIN(v) min_element(v.begin(),v.end())
#define MAX(v) max_element(v.begin(),v.end())
#define fi              first
#define se              second
#define endl            "\n"
#define ub(a,m) upper_bound(a.begin(),a.end(),m)-a.begin()
#define lb(a,m) lower_bound(a.begin(),a.end(),m)-a.begin()
#define yes             cout<<"YES\n";
#define no             cout<<"NO\n";
#define baseh             cout<<"\n";
#define out(x)             cout<<x<<'\n';
#define outsp(x)             cout<<x<<' ';
#define out2(x,y)             cout<<x<<' '<<y<<'\n';
#define in(x)             cin>>x;
#define in2(x,y)             cin>>x;cin>>y;
#define all(x)      (x).begin(),(x).end()
#define md(a,b)       (a%b+b)%b
#define mp(a,b)        make_pair(a,b)
const ll inf  =       LLONG_MAX-1;
const ll ninf =       LLONG_MIN+1;
constexpr ld PI=2*asinl(1.0);
template<typename T>
void SORT(T & A){
    sort(A.begin(),A.end());
}

template<typename T>
void SORTO(T & A){
    sort(A.rbegin(),A.rend());
}

template<typename T>
void CIN(T& a,ll n=-1){
(n == -1) ? n=a.size() : n += 0;
    FOR(i,n) cin>>a[i];
}
template<typename T>
void COUT(T & a,ll n=-1){
(n == -1) ? n=a.size() : n += 0;
    FOR(i,n){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
template<typename T>
void EMPTY(T & a,ll t=0){
    FOR(i,a.size()) a[i]=t;
}
template<typename T>
ll SUM(T a ,ll l=0,ll r=-1){
(r == -1) ? r=a.size() : r += 0;
    ll s=0;
    FOR2(i,l,r) s += a[i];
    return s;
}
template<typename T>
ll FIND(T a,ll b){
    FOR(i,a.size()){
        if(a[i] == b) return i;
    }
    return -1;
}
ll GOUS(ll start,ll end,ll amount){
    return((start+end)*amount)/2;
}
bool ISPRIME(ll n){
  if(n<2)return false;
  for(int i=2;i<=sqrt(n);i++){
    if(n%i==0 && i!=0 && n!=i){
      return false;
    }
  }
  return true;
}
ll GCD(ll a,ll b){
    if(b==0){
      return a;
    }
    return GCD(b,a%b);
}
ll LCM(ll a,ll b){ return(a / GCD(a,b)) * b; }

bool ISDIGIT(char f){
  return(f>='0'&&f<='9');
}

string ADDBIN(string a,string b){
  string result="";
  ll hal=0;
  ll size_a=a.size() - 1;
  ll size_b=b.size() - 1;
  while(size_a >= 0 || size_b >= 0 || hal == 1){
    hal +=((size_a >= 0) ? a[size_a] - '0' : 0);
    hal +=((size_b >= 0) ? b[size_b] - '0' : 0);
    result=char(hal % 2+'0')+result;
    hal /= 2;
    size_a--;
    size_b--;
  }
  return result;
}


ld EVAL(string s){
  string ma;
  FORO(i,s){
    if(s[i]!=' '){
      ma+=s[i];
    }
  }
  V adad;
  vector<char> amal;
  FORO(i,ma){
    if(ma[i]=='('){
      ld iter=0;
      iter++;
      string e="";
      i++;
      while(true){
        if(ma[i]==')'){
          iter--;
          if(iter==0){
            adad.pb(EVAL(e));
            break;
          }
        }
        if(ma[i]=='(')iter++;
        e+=ma[i];
        i++;
      }
    }
    else if(ISDIGIT(ma[i])){
      string r="";
      r+=ma[i];
      while(ISDIGIT(ma[i+1])){
        r+=ma[i+1];
        i++;
      }
      adad.pb(stoi(r));
    }
    else{
      amal.pb(ma[i]);
    }
  }
  FORO(i,amal){
    if(amal[i]=='/'){
      if(adad[i+1]==0){
        return ninf;
      }
      adad[i]=adad[i]/adad[i+1];
      adad.erase(adad.begin()+i+1);
      amal.erase(amal.begin()+i);
      i--;
    }
    else if(amal[i]=='*'){
      adad[i]=adad[i]*adad[i+1];
      adad.erase(adad.begin()+i+1);
      amal.erase(amal.begin()+i);
      i--;
    }
  }
  if(adad.size()==1){
    return adad[0];
  }
  ld javab=adad[0];
  FORO(i,amal){
    if(amal[i]=='+'){
      javab+=adad[i+1];
    }
    else{
      javab-=adad[i+1];
    }
  }

  return javab;
}

string BIN_TO(ll n,ll m){  
    if(n == 0) return "";  
    if(n%m < 10)  
        return BIN_TO(n/m,m)+(char)('0'+n%m);  
    else  
        return BIN_TO(n/m,m)+(char)('A'+(n%m-10));  
}

ll POWM(ll n,ll k,ll MOD){
    if(k == 0)
        return 1;
    ll half=POWM(n,k / 2,MOD);
    half =(half * half) % MOD;
    if(k % 2 != 0)
        half =(half * n) % MOD;
    return half;
}

ll POW(ll n,ll k){
    if(k == 0)
        return 1;
    ll half=POW(n,k / 2);
    half =(half * half);
    if(k % 2 != 0)
        half =(half * n);
    return half;
}

V DIVISIOR(ll n){
  V a;
  startn:
  FOR2(i,2,n+1){
    if(n%i==0){
      a.pb(i);
      n/=i;
      break;
    }
  }
  if(n!=1){
    goto startn;
  }
  return a;
}




ll FACT(ll n){
  ll ans=1;
  FOR2(i,2,n+1){
    ans*=i;
  }
  return ans;
}

ll CHOICE(ll n,ll k){
    vector<vector<ll>> C(n+1,vector<ll>(k+1,0));
    for(ll i=0; i <= n; ++i){
        for(ll j=0; j <= min(i,k); ++j){
            if(j == 0 || j == i){
                C[i][j]=1;
            } else{
                C[i][j]=C[i - 1][j - 1]+C[i - 1][j];
            }
        }
    }
    return C[n][k];
}

ll LOG(ll a,ll b){
  return log(a)/log(b);
}

bool ISSORTED(V a){
  FORO(i,a){
    if(i>0&&a[i]<a[i-1])return false;
  }
  return true;
}

bool MORBAKAMEL(ll num){
    if(num < 0) return false;
    ll root=static_cast<ll>(sqrt(num));
    return num == root * root;
}

string TO_UPPER(string a){ FORO(i,a) if(a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string TO_LOWER(string a){ FORO(i,a) if(a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }

string TO_BIN(ll x,ll y){
  string ans;
  while(x>0){
    ans=to_string(x%y)+ans;
    x/=y;
  }
  return ans;
}

ll sumdigit(ll n){
  ll ans=0;
  while(n){
    ans+=n%10;
    n/=10;
  }
  return ans;
}

void shiftElement(V& arr, ll pos, ll shift) {
  // cout<<pos<<' '<<shift<<'|';
  ll n = arr.size();
  if (shift == 0) return;
  ll newPos = (pos + shift) % n;
  if (newPos < 0) newPos += n;
  ll temp = arr[pos];
  if (shift > 0) {
      for (ll i = pos; i < newPos; ++i) {
          arr[i] = arr[i + 1];
      }
  } 
  else {
      for (ll i = pos; i > newPos; --i) {
          arr[i] = arr[i - 1];
      }
  }
  arr[newPos] = temp;
}

const ll MOD=998244353,MAXN=3008;

void SOLVE(){
  llc(n);
  V a(n);
  map<ll,ll> b,c;
  vector<PII> ans;
  CIN(a);
  FORO(i,a){
    b[a[i]-1]=i;
  }
  V g(n);
  FORO(i,g){
    g[i]=i+1;
    c[i]=i;
  }
  a=g;
  FOR(i,n){
    vector<PII> hal;
    FOR2(j,c[i]+1,n){
      if(a[j]<=i)break;
      ans.pb({i+1,a[j]});
    }
    FOR4(j,b[i]+1,n-1){
      if(a[j]<=i)continue;
      ans.pb({a[j],i+1});
    }
    if(c[i]<b[i]){
      FOR2(j,c[i]+1,b[i]+1){
        c[a[j]-1]--;
      }
    }
    else{
      FOR2(j,b[i],c[i]){
        c[a[j]-1]++;
      }
    }
    // COUT(a);
    // cout<<c[i]<<'/'<<(b[i]-c[i])<<endl;
    shiftElement(a,c[i],(b[i]-c[i]));
    // FOR3(j,hal.size()){
    //   ans.pb(hal[j]);
    // }
    // COUT(a);
  }
  out(ans.size());
  FORO(i,ans){
    out2(ans[i].se,ans[i].fi);
  }
}

int main(){
  // precompute();
  // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  superfast;
  // llc(t);
  // while(t--)
    SOLVE();
  cerr <<endl<< "Time elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC<<" s.\n";
}



//use pop_back bejai erase