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

Previous submission (verdict: Wrong answer on test 4):
/*
  卫风·芄兰
芄兰之支,童子佩觿.
虽则佩觿,能不我知?
容兮遂兮,垂带悸兮.
芄兰之叶,童子佩韘.
虽则佩韘,能不我甲?
容兮遂兮,垂带悸兮.
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul array<int,3>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctzll(x)
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=3e5+5,yyx=998244353;
vector<PII> to[N];
int n,m,a[N];
inline int mod(int x){
  return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
  return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
  return x<y?x=y,1:0;
}
inline void solve(){
  cin>>n;
  set<PII> s;
  map<int,vector<int>> t;
  rep(i,1,n) cin>>a[i];
  rep(i,1,n){
    rep(j,1,i-1){
        if(a[j]<a[i]) s.insert({a[i],a[j]}),s.insert({a[j],a[i]});
        else s.insert({a[j],a[i]});
    }
  }
  cout<<s.size()<<endl;
  for(auto [x,y]:s){
    if(y<x) t[x].push_back(y);
  }
  rep_(i,n,1){
    sort(all(t[i]),greater<int>());
  }
  rep_(i,n,1){
    int ok=0;
    for(auto c:t[i]){
        if(c==1) ok=1;
    }
    for(auto c:t[i]){
        if(!ok) break;
        cout<<i<<" "<<c<<endl;
        if(c==1) break;
    }
    reverse(all(t[i]));
    for(auto c:t[i]){
        if(c==1) break;
        cout<<i<<" "<<c<<endl;
    }
    rep(j,1,i-1){
        if(s.count({j,i})) t[j].push_back(i);
    }
  }
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  //freopen("D://321//in.txt","r",stdin);
  //freopen("D://321//out.txt","w",stdout);
  int _=1;
  //cin>>_;
  while(_--)
  solve();
  return 0;
}

Submission (verdict: Accepted):
/*
  卫风·芄兰
芄兰之支,童子佩觿.
虽则佩觿,能不我知?
容兮遂兮,垂带悸兮.
芄兰之叶,童子佩韘.
虽则佩韘,能不我甲?
容兮遂兮,垂带悸兮.
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul array<int,3>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctzll(x)
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=3e5+5,yyx=998244353;
vector<PII> to[N];
int n,m,a[N],b[N];
inline int mod(int x){
  return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
  return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
  return x<y?x=y,1:0;
}
vector<PII> t;
void bfs(){
   rep_(i,n,1) rep_(j,i-1,1) t.push_back({i,j});
   rep(i,1,n) b[i]=n-i+1;
   rep(i,1,n){
    int z=1;
    rep(j,1,n) if(a[i]==b[j]) z=j;
    while(z>i){
        t.push_back({b[z],b[z-1]});
        swap(b[z],b[z-1]);
        z--;
    }
   }
}
inline void solve(){
  cin>>n;
  rep(i,1,n) cin>>a[i];
  bfs();
  cout<<t.size()<<endl;
  for(auto [x,y]:t) cout<<x<<" "<<y<<endl;
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  //freopen("D://321//in.txt","r",stdin);
  //freopen("D://321//out.txt","w",stdout);
  int _=1;
  //cin>>_;
  while(_--)
  solve();
  return 0;
}