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;


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
typedef __gnu_pbds::tree<long long, __gnu_pbds::null_type, less<long long>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;




//------------------------------------------------//
#if __has_include("../files/juzar_7.cpp")
#include "../files/juzar_7.cpp"
#endif
#ifdef juzZ
#define deb(x) {cerr << #x << " "; _print(x); cerr << "\n";}
#else
#define deb(x)
#endif
#define rep(i, a, b) for (int i = a; i < b; i++)
#define precision(a) cout << setprecision(a) << fixed
#define MSB(x) (63 - __builtin_clzll(x))
#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)
#define MP make_pair
#define all(a) a.begin(), a.end()
template <class T> ostream &operator<<(ostream &os, const vector<T> a){ for (auto ele : a) os << ele << " "; return os;} 
template <class T> istream &operator>>(istream &is, vector<T> &a){ for (auto &ele : a) is >> ele; return is; }
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vl; typedef vector<vector<long long>> vvl; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef map<int, int> mii; typedef map<long long, long long> mll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef unsigned long long ull; typedef long double ld; typedef long long ll;
//------------------------------------------------//



ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll binExp(ll a, ll b) {ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; }
ll MOD = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};




void solve(int loop)
{
    int n;
    cin>>n;
    vector<int> v(n+1);
    for (int i=1; i<n+1; i++) cin>>v[i];
    // int ans = 0;
    set<pair<int, int>> st;
    vector<int> ini(n+1);
    for (int i=1; i<=n; i++) ini[i] = i;
    vector<pair<int, int>> ans;
    for (int i=1; i<=n; i++)
    {
        int curr = v[i];
        int idx = -1;
        for (int j=1; j<=n; j++)
        {
            if (ini[j]==curr) 
            {
                idx = j;
                break;
            }
        }
        if (idx==i) continue;
        for (int j=idx; j>i; j--) 
        {
            ans.push_back({ini[j], ini[j-1]});
            swap(ini[j], ini[j-1]);
            st.insert({min(ini[j], ini[j-1]), max(ini[j], ini[j-1])});
        }
    }
    for (int i=1; i<n; i++)
    {
        
        int x = min(ini[i], ini[i+1]);
        int y = max(ini[i], ini[i+1]);
        if (st.find({x, y})==st.end())
        {
            ans.push_back({ini[i+1], ini[i]});
            ans.push_back({ini[i], ini[i+1]});
            st.insert({x, y});
        }
    
    }
    cout << ans.size() << "\n";
    for (auto it : ans) cout << it.first << " " << it.second << "\n";
}
 
 


int32_t main()
{
// #define DEBUG_MODE
#ifndef DEBUG_MODE
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#ifdef juzZ
    freopen("../files/input.txt", "r", stdin); freopen("../files/output.txt", "w", stdout); freopen("../files/error.txt", "w", stderr);
#endif
#else
#ifdef juzZ
    freopen("../files/input.txt", "r", stdin);
#endif
#endif




    int tc = 1;
    // cin >> tc;
    for (int loop = 1; loop <= tc; loop++)
    {
        // cout << "Case #" << loop << ": ";
        solve(loop);
        // bool as = solve(); cout << (as ? "YES\n" : "NO\n");
        // int as = solve(); cout << as << "\n";
    }
    return 0;
}

/*
    Wed Mar  1 19:52:06 2023
    File : C.cpp
*/


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
typedef __gnu_pbds::tree<long long, __gnu_pbds::null_type, less<long long>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;




//------------------------------------------------//
#if __has_include("../files/juzar_7.cpp")
#include "../files/juzar_7.cpp"
#endif
#ifdef juzZ
#define deb(x) {cerr << #x << " "; _print(x); cerr << "\n";}
#else
#define deb(x)
#endif
#define rep(i, a, b) for (int i = a; i < b; i++)
#define precision(a) cout << setprecision(a) << fixed
#define MSB(x) (63 - __builtin_clzll(x))
#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)
#define MP make_pair
#define all(a) a.begin(), a.end()
template <class T> ostream &operator<<(ostream &os, const vector<T> a){ for (auto ele : a) os << ele << " "; return os;} 
template <class T> istream &operator>>(istream &is, vector<T> &a){ for (auto &ele : a) is >> ele; return is; }
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vl; typedef vector<vector<long long>> vvl; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef map<int, int> mii; typedef map<long long, long long> mll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef unsigned long long ull; typedef long double ld; typedef long long ll;
//------------------------------------------------//



ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll binExp(ll a, ll b) {ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; }
ll MOD = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};




void solve(int loop)
{
    int n;
    cin>>n;
    vector<int> v(n+1, 0);
    for (int i=1; i<=n; i++) cin>>v[i];
    reverse(v.begin()+1, v.end());
    vector<int> ini(n+1, 0);
    for (int i=1; i<=n; i++) ini[i] = i;
    vector<pair<int, int>> ans;
    for (int i=1; i<=n; i++)
    {
        int curr = v[i];
        int idx = -1;
        for (int j=i; j<=n; j++)
        {
            if (ini[j]==curr)
            {
                idx = j;
                break;
            }
        }
        for (int j=idx; j>i; j--)
        {
            ans.push_back({ini[j], ini[j-1]});
            swap(ini[j], ini[j-1]);
        }
    }
    reverse(v.begin()+1, v.end());
    for (int i=1; i<=n; i++)
    {
        int curr = v[i];
        int idx = -1;
        for (int j=i; j<=n; j++)
        {
            if (ini[j]==curr)
            {
                idx = j;
                break;
            }
        }
        for (int j=idx; j>i; j--)
        {
            ans.push_back({ini[j], ini[j-1]});
            swap(ini[j], ini[j-1]);
        }
    }
    cout << ans.size() << "\n";
    for (auto it : ans) cout << it .first << " " << it.second << "\n";
}
 
 


int32_t main()
{
// #define DEBUG_MODE
#ifndef DEBUG_MODE
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#ifdef juzZ
    freopen("../files/input.txt", "r", stdin); freopen("../files/output.txt", "w", stdout); freopen("../files/error.txt", "w", stderr);
#endif
#else
#ifdef juzZ
    freopen("../files/input.txt", "r", stdin);
#endif
#endif




    int tc = 1;
    // cin >> tc;
    for (int loop = 1; loop <= tc; loop++)
    {
        // cout << "Case #" << loop << ": ";
        solve(loop);
        // bool as = solve(); cout << (as ? "YES\n" : "NO\n");
        // int as = solve(); cout << as << "\n";
    }
    return 0;
}

/*
    Wed Mar  1 19:52:06 2023
    File : C.cpp
*/