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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define ull unsigned long long
#define lld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vi vector<int>
#define iinf (int)2e9
#define eb emplace_back
#define vb vector<bool>
#define vll vector<ll> 
#define vvll vector<vll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define nline cout<<"\n";
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define fs first
#define sc second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, x, y) for(int i=x; i<y; i++)
#define repp(i, x, y) for(int i=x; i<=y; i++)
 
#define print(k) {for(auto v : k){cout << v << " ";} cout << endl;}
 
#define fi first
#define se second
#define mp make_pair
 
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

/* =================================================== */

const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll llinf = (ll)1e18;


void solve() {
    int n ;cin>>n;
    vi final(n); 
    rep(i, 0, n) cin>>final[i];
    
    set<pii> s;
    vpii ans;

    vi initial(n); 
    rep(i, 0, n) initial[i] = i+1;

    rep(i, 0, n) {
        if(initial[i] == final[i]) continue;
        rep(j, i, n){
            if(initial[j] == final[i]) {
                swap(initial[i], initial[j]); 
                s.insert(mp(initial[i], initial[j])); 
                s.insert(mp(initial[j], initial[i]));
                ans.pb(mp(initial[j], initial[i]));
                break;
            }
        }
    }

    repp(i, 1, n) {
        repp(j, 1, n){
            if(i == j) continue;

            if(s.find(mp(i, j)) != s.end() || s.find(mp(j, i)) != s.end()){
                continue;
            }
            else {
                ans.pb(mp(i, j));
                ans.pb(mp(j, i));
                s.insert(mp(i, j));
                s.insert(mp(j, i));
            }

        }
    }

    cout<<ans.size()<<endl;
    for(auto it:ans){
        cout<<it.fi<<" "<<it.se<<endl;
    }

}

int main() {
    fastio()
    // int t;cin>>t;
    int t=1;
    while(t--) solve();

    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define ull unsigned long long
#define lld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vi vector<int>
#define iinf (int)2e9
#define eb emplace_back
#define vb vector<bool>
#define vll vector<ll> 
#define vvll vector<vll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define nline cout<<"\n";
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define fs first
#define sc second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, x, y) for(int i=x; i<y; i++)
#define repp(i, x, y) for(int i=x; i<=y; i++)
 
#define print(k) {for(auto v : k){cout << v << " ";} cout << endl;}
 
#define fi first
#define se second
#define mp make_pair
 
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

/* =================================================== */

const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll llinf = (ll)1e18;


void solve() {
    int n ;cin>>n;
    vi final(n); 
    rep(i, 0, n) cin>>final[i];
    
    set<pii> s;
    vpii ans;

    vi initial(n); 
    rep(i, 0, n) initial[i] = i+1;

    rep(i, 0, n) {
        if(initial[i] == final[i]) continue;
        rep(j, i, n){
            if(initial[j] == final[i]) {
                swap(initial[i], initial[j]); 
                s.insert(mp(initial[i], initial[j])); 
                s.insert(mp(initial[j], initial[i]));
                ans.pb(mp(initial[i], initial[j]));
                break;
            }
        }
    }

    repp(i, 1, n) {
        repp(j, 1, n){
            if(i == j) continue;

            if(s.find(mp(i, j)) != s.end() || s.find(mp(j, i)) != s.end()){
                continue;
            }
            else {
                ans.pb(mp(i, j));
                ans.pb(mp(j, i));
                s.insert(mp(i, j));
                s.insert(mp(j, i));
            }

        }
    }

    cout<<ans.size()<<endl;
    for(auto it:ans){
        cout<<it.fi<<" "<<it.se<<endl;
    }

}

int main() {
    fastio()
    // int t;cin>>t;
    int t=1;
    while(t--) solve();

    return 0;
}