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

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
//#define ll int
#define ld long double
#define pb push_back
#define endl '\n'
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(int i=b-1;i>=a;i--)
#define go(a,x) for(auto &a:x)
#define inn(a) go(x,a)cin>>x
#define print(v) go(x,v){cout<<x<<" ";}cout<<endl;
//const ll inf=9223372036854775807;
void yes(){cout <<"YES"<<endl;}
void no(){cout <<"NO"<<endl;}
void ne(){cout <<-1<<endl;}
#define ter(a, b, c) ((a) ? (b) : (c))
#define yn(a) cout<<((a)?"YES\n":"NO\n")
typedef pair<ll, ll> pii;
using pq = priority_queue<ll>;
using vi = vector<ll>;
using vii = vector<pair<ll,ll>>;
using mii = map<ll,ll>;
using umii = unordered_map<ll,ll>;
using si = set<ll>;
using usi = unordered_set<ll>;
using msi = multiset<ll>;

#ifdef MYPC2835
#include "debug2.txt"
#else
#define dbg(...)
#endif

void solve(){
        int n;cin>>n;
        vector<int> a(n);
        for(int &x:a)cin>>x;

        vii ans;

        vi vis(n+1,0);

        go(x,a){
          fr(i,x+1,n+1){
            if(!vis[i])
            ans.pb({i,x});
          }
          fr(i,x+1,n+1){
            if(!vis[i])
            ans.pb({x,i});
          }

          fr(i,1,x){
            if(!vis[i])
            ans.pb({x,i});
          }
          vis[x]=1;
        }

        cout<<ans.size()<<endl;
        go(x,ans){
          cout<<x.F<<" "<<x.S<<endl;
        }



}

int32_t main(){
#ifdef MYPC2835
   freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
   freopen("error.txt", "w", stderr);
#endif
ios::sync_with_stdio(0); cin.tie(0);
  ll tt=1;

    // cin>>tt;

  while(tt--){
   solve();
  }
   
return 0;
}

Submission (verdict: Wrong answer on test 5):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
//#define ll int
#define ld long double
#define pb push_back
#define endl '\n'
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(int i=b-1;i>=a;i--)
#define go(a,x) for(auto &a:x)
#define inn(a) go(x,a)cin>>x
#define print(v) go(x,v){cout<<x<<" ";}cout<<endl;
//const ll inf=9223372036854775807;
void yes(){cout <<"YES"<<endl;}
void no(){cout <<"NO"<<endl;}
void ne(){cout <<-1<<endl;}
#define ter(a, b, c) ((a) ? (b) : (c))
#define yn(a) cout<<((a)?"YES\n":"NO\n")
typedef pair<ll, ll> pii;
using pq = priority_queue<ll>;
using vi = vector<ll>;
using vii = vector<pair<ll,ll>>;
using mii = map<ll,ll>;
using umii = unordered_map<ll,ll>;
using si = set<ll>;
using usi = unordered_set<ll>;
using msi = multiset<ll>;

#ifdef MYPC2835
#include "debug2.txt"
#else
#define dbg(...)
#endif

void solve(){
        int n;cin>>n;
        vector<int> a(n);
        for(int &x:a)cin>>x;

        vii ans;

        vi vis(n+1,0);

        go(x,a){
          fr(i,x+1,n+1){
            if(!vis[i])
            ans.pb({i,x});
          }
          for(int i=n;i>x;i--){
            if(!vis[i])
            ans.pb({x,i});
          }

          fr(i,1,x){
            if(!vis[i])
            ans.pb({x,i});
          }
          vis[x]=1;
        }

        cout<<ans.size()<<endl;
        go(x,ans){
          cout<<x.F<<" "<<x.S<<endl;
        }



}

int32_t main(){
#ifdef MYPC2835
   freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
   freopen("error.txt", "w", stderr);
#endif
ios::sync_with_stdio(0); cin.tie(0);
  ll tt=1;

    // cin>>tt;

  while(tt--){
   solve();
  }
   
return 0;
}