Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 358 ms):
/*JAI MAHAKAAL*/

#include <bits/stdc++.h>

using namespace std;

#define int            long long int
#define f              first
#define s              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.f << " " << x.s << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
    int x = 1;
    while (b)
    {
        if (b & 1) x *= a;
        a *= a;
        b >>= 1;
    }
    return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr (names + 1, ',');
    cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;

void solve() {
    int n;
    cin >> n;
    vi a(n), c(n);
    map<int, int>ind, m;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        ind[c[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        a[i] = i + 1;
        m[a[i]] = i;
    }
    mpi mp;
    vpi v;
    for (int i = 0; i < n; i++)a[i] = i + 1;
    int i = n - 1;
    int ans = 0;
    while (i >= 0) {
        int j = m[c[i]];
        while (j < i) {
            v.pb({a[j + 1], a[j]});
            swap(a[j], a[j + 1]);
            int mi = min(a[j], a[j + 1]);
            int ma = max(a[j], a[j + 1]);
            mp[ {mi, ma}]++;
            ans++;
            j++;
        }
        for (int i = 0; i < n; i++) {
            m[a[i]] = i;
        }
        i--;
    }
    vpi temp;
    for (int i = n; i >= 1; i--) {
        int j = ind[i];
        while (j >= 0) {
            if (c[j - 1] < i) {
                v.pb({i, c[j - 1]});
                temp.pb({i, c[j - 1]});
                ans += 2;
            }
            j--;
        }
    }
    int size = temp.size();
    for (int j = size - 1; j >= 0; j--) {
        int x = temp[j].f;
        int y = temp[j].s;
        v.pb({y, x});
    }
    cout << ans << endl;
    for (int i = 0; i < v.size(); i++) {
        cout << v[i].f << " " << v[i].s << endl;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input.txt",  "r",  stdin);
    freopen("output.txt", "w", stdout);
#endif

    clock_t z = clock();

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

    cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

    return 0;
}

Solution 2 (runtime: 546 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template <typename... Args>
void logger(string vars, Args &&...values)
{
    cout << "[ ";
    cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
    cout << " ]\n";
}
#else
#define deb(...) 0
#endif

const int MD = 1e9 + 7, INF = 1e18;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<int> to(N+5);
    vector<int> id(N+5);
    vector<int> A(N+5);
    queue<int> Q;
    for(int i = 1 ; i <= N;i++)
    {
        int t;
        cin >>t;
        to[t] = i;
        A[i]=i;
        id[i]=i;
        Q.push(t);
        // deb(to[i],i,t);

    }

    set<pii> ans;
    vector<pii> anss;
    
    int pos = 1;
    while (!Q.empty())
    {
        int u = Q.front();
        Q.pop();

        int now = id[u];
        for(int i = now+1; i <= N;i++)
        {
            ans.insert({A[i],u});
            anss.push_back({A[i],u});
            swap(id[A[i]], id[u]);
            swap(A[i],A[i-1]);
        }

        for(int i = N-1; i>= pos;i-- )
        {
            ans.insert({u,A[i]});
            anss.push_back({u,A[i]});
            swap(id[A[i]],id[u]);
            swap(A[i], A[i+1]);
        }

        pos++;
    }
    
    cout << anss.size() << "\n";
    for(auto [x,y] : anss)
    {
        cout << x << " " << y << "\n";
    }
    return 0;
}