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

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define ll long long
#define int long long
#define double long double
#define Int __int128
#define pb push_back
#define eb emplace_back
#define MAX_LOG 21
#define ff first
#define ss second
#define RI register int
#define CI const int&
#define ull unsigned long long
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<ll,ll> PLL;
typedef pair<int,int>PII;
ll gcd(ll a,ll b)
{
    if(b) while((a%=b)&&(b%=a));
    return a+b;
}//最大公约数函数
ll spid(ll a,ll b,ull p)
{
    ll ans=1;
    while(b)
    {
        if(b&1)ans=(Int)ans*a%p;
        b>>=1;
        a=(Int)a*a%p;
    }
    return ans;
}//快速幂函数
///泡沫在阳光下闪烁，像星辰在寂静得夜空中闪耀

///秋雨
const ll N=2e5+10;
ll mod=998244353;
void solve()
{
    ll n;
    cin>>n;
    vector<ll>a(n+1);
    vector<PLL>b(n+1);
    for(int i=1; i<=n; i++)cin>>a[i],b[i].ss=i,b[i].ff=a[i];
    sort(a.begin(),a.end());
    ll ans=0;
    vector<PLL>vec;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(a[i]==b[j].ff)continue;
            if(a[i]>b[j].ff&&i>b[j].ss)
            {
                vec.pb({a[i],b[j].ff});
                vec.pb({b[j].ff,a[i]});
            }
            else if(a[i]<b[j].ff&&i>b[j].ss)
            {
                vec.pb({b[j].ff,a[i]});
            }
            else if(a[i]>b[j].ff&&i<b[j].ss)
            {
                vec.pb({a[i],b[j].ff});
            }
            else
            {
                vec.pb({b[j].ff,a[i]});
                vec.pb({a[i],b[j].ff});
            }
        }
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    reverse(vec.begin(),vec.end());
    vector<ll>num(n+1,0);
    for(int i=1;i<=n;i++)num[i]=i;
    ll cnt=0;
    ll now=0;
    for(auto j:vec)
    {
        swap(num[j.ff],num[j.ss]);
        now++;
        bool ret=1;
        for(int j=1;j<=n;j++)
        {
            if(num[j]!=a[j])ret=0;
        }
        if(ret)cnt=now;
    }
    cout<<cnt<<'\n';
    for(auto i:vec)
    {
        if(cnt)
        cout<<i.ff<<' '<<i.ss<<'\n';
        else break;
        cnt--;
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
//    cin>>t;
    while(t--)
    {
        solve();
    }
}
///在秋天邂逅， 在春天发芽，在夏天壮大，在秋天萧瑟，在冬天萎缩，

///而后，春天再度归来。


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define ll long long
#define int long long
#define double long double
#define Int __int128
#define pb push_back
#define eb emplace_back
#define MAX_LOG 21
#define ff first
#define ss second
#define RI register int
#define CI const int&
#define ull unsigned long long
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<ll,ll> PLL;
typedef pair<int,int>PII;
ll gcd(ll a,ll b)
{
    if(b) while((a%=b)&&(b%=a));
    return a+b;
}//最大公约数函数
ll spid(ll a,ll b,ull p)
{
    ll ans=1;
    while(b)
    {
        if(b&1)ans=(Int)ans*a%p;
        b>>=1;
        a=(Int)a*a%p;
    }
    return ans;
}//快速幂函数
///泡沫在阳光下闪烁，像星辰在寂静得夜空中闪耀

///秋雨
const ll N=2e5+10;
ll mod=998244353;
void solve()
{
    ll n;
    cin>>n;
    vector<ll>a(n+1);
    vector<PLL>b(n+1);
    for(int i=1; i<=n; i++)cin>>a[i],b[i].ss=i,b[i].ff=a[i];
    sort(a.begin(),a.end());
    ll ans=0;
    vector<PLL>vec;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(a[i]==b[j].ff)continue;
            if(a[i]>b[j].ff&&i>b[j].ss)
            {
                vec.pb({a[i],b[j].ff});
                vec.pb({b[j].ff,a[i]});
            }
            else if(a[i]<b[j].ff&&i>b[j].ss)
            {
                vec.pb({b[j].ff,a[i]});
            }
            else if(a[i]>b[j].ff&&i<b[j].ss)
            {
                vec.pb({a[i],b[j].ff});
            }
            else
            {
                vec.pb({b[j].ff,a[i]});
                vec.pb({a[i],b[j].ff});
            }
        }
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    reverse(vec.begin(),vec.end());
    vector<ll>num(n+1,0),st(n+1,0);
    for(int i=1;i<=n;i++)num[i]=i,st[i]=i;
    ll cnt=0;
    ll now=0;
    for(auto j:vec)
    {
        swap(num[st[j.ff]],num[st[j.ss]]);
        swap(st[j.ff],st[j.ss]);
        now++;
        bool ret=1;
        for(int j=1;j<=n;j++)
        {
            if(num[j]!=a[j])ret=0;
        }
        if(ret)cnt=now;
    }
    cout<<cnt<<'\n';
    for(auto i:vec)
    {
        if(cnt)
        cout<<i.ff<<' '<<i.ss<<'\n';
        else break;
        cnt--;
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
//    cin>>t;
    while(t--)
    {
        solve();
    }
}
///在秋天邂逅， 在春天发芽，在夏天壮大，在秋天萧瑟，在冬天萎缩，

///而后，春天再度归来。