Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 10):
/*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;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        ind[c[i]] = i;
    }
    mpi mp;
    vpi v;
    for (int i = 0; i < n; i++)a[i] = i + 1;
    int ans = 0;
    int i = 0;
    while (i < n) {
        if (a[i] == c[i]) {
            i++;
            continue;
        }
        int j = i;
        int id = ind[a[i]];
        while (j < id) {
            int mi = min(a[j], a[j + 1]);
            int ma = max(a[j], a[j + 1]);
            mp[ {mi, ma}]++;
            v.pb({a[j + 1], a[j]});
            swap(a[j], a[j + 1]);
            ans++;
            j++;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        vpi temp;
        for (int j = i - 1; j >= 0; j--) {
            int mi = min(a[j], a[i]);
            int ma = max(a[j], a[i]);
            if (mp.find({mi, ma}) == mp.end()) {
                mp[ {mi, ma}]++;
                ans += 2;
                temp.pb({a[i], a[j]});
                v.pb({a[i], a[j]});
            }
            else break;
        }
        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;
}

Submission (verdict: Wrong answer on test 10):
/*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;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        ind[c[i]] = i;
    }
    mpi mp;
    vpi v;
    for (int i = 0; i < n; i++)a[i] = i + 1;
    int ans = 0;
    int i = 0;
    while (i < n) {
        if (a[i] == c[i]) {
            i++;
            continue;
        }
        int fl = 0;
        int j = i;
        int id = ind[a[i]];
        if (id > i) {
            while (j < id) {
                int mi = min(a[j], a[j + 1]);
                int ma = max(a[j], a[j + 1]);
                if (mp[ {mi, ma}] == 2 || (mp[ {mi, ma}] == 1 && ind[a[j]] < ind[a[j + 1]])) {
                    fl = 1;
                    break;
                }
                mp[ {mi, ma}]++;
                v.pb({a[j + 1], a[j]});
                swap(a[j], a[j + 1]);
                ans++;
                j++;
            }
        }
        else {
            while (j > id) {
                int mi = min(a[j], a[j - 1]);
                int ma = max(a[j], a[j - 1]);
                if (mp[ {mi, ma}] == 2 || (mp[ {mi, ma}] == 1 && ind[a[j]] > ind[a[j - 1]])) {
                    fl = 1;
                    break;
                }
                mp[ {mi, ma}]++;
                v.pb({a[j - 1], a[j]});
                swap(a[j], a[j - 1]);
                ans++;
                j--;
            }
        }
        if (fl) {
            i++;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        vpi temp;
        for (int j = i - 1; j >= 0; j--) {
            int mi = min(a[j], a[i]);
            int ma = max(a[j], a[i]);
            if (mp.find({mi, ma}) == mp.end()) {
                mp[ {mi, ma}]++;
                ans += 2;
                temp.pb({a[i], a[j]});
                v.pb({a[i], a[j]});
            }
            else break;
        }
        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;
}