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

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

#ifdef DEBUG
#include <debug.h>
#else
#define dbg(x...)
#endif


using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pil = std::pair<int, ll>;
using pll = std::pair<ll, ll>;
using pli = std::pair<ll, int>;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
typedef std::vector<pii> vpii;
typedef std::vector<pil> vpil;
typedef std::vector<pli> vpli;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vb;

#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int) (x).size()
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= b; i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define nl cout << "\n"
#define ins insert
#define RET return






int main() {
        ios::sync_with_stdio(false), cin.tie(nullptr);
        int n;
        cin >> n;
        vector<int> p(n);
        vector<pair<int, int>> ans;
        for (int &x: p) cin >> x;
        for (int i = 1; i <= n; i++) {
                set<int> s;
                int j = 0;
                while (j < n && p[j] != i) {
                        if (p[j] < i) s.insert(p[j]);
                        j++;
                }
                vpii tmp;
                for (int x : s) {
                        tmp.push_back({i, x});
                }
                reverse(all(tmp));
                for (auto x : tmp) ans.pb(x);
                for (int k = sz(tmp)-1; k >= 0; k--) ans.pb({tmp[k].se, tmp[k].fi});
        }
        dbg(ans);
        for (int i = 0; i < n; i++) {
                set<int> s;
                for (int j = i + 1; j < n; j++) {
                        if (p[j] < p[i]) {
                                s.insert(p[j]);
                        }
                }
                vpii tmp;
                for (int x : s) {
                        tmp.push_back({p[i], x});
                }
                reverse(all(tmp));
                for (auto x : tmp) ans.pb(x);
        }
        dbg(sz(ans));
        dbg(ans);

}


Submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>

#ifdef DEBUG
#include <debug.h>
#else
#define dbg(x...)
#endif


using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pil = std::pair<int, ll>;
using pll = std::pair<ll, ll>;
using pli = std::pair<ll, int>;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
typedef std::vector<pii> vpii;
typedef std::vector<pil> vpil;
typedef std::vector<pli> vpli;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vb;

#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int) (x).size()
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= b; i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define nl cout << "\n"
#define ins insert
#define RET return






int main() {
        ios::sync_with_stdio(false), cin.tie(nullptr);
        int n;
        cin >> n;
        vector<int> p(n);
        vector<pair<int, int>> ans;
        for (int &x: p) cin >> x;
        for (int i = 1; i <= n; i++) {
                set<int> s;
                int j = 0;
                while (j < n && p[j] != i) {
                        if (p[j] < i) s.insert(p[j]);
                        j++;
                }
                vpii tmp;
                for (int x : s) {
                        tmp.push_back({i, x});
                }
                reverse(all(tmp));
                for (auto x : tmp) ans.pb(x);
                for (int k = sz(tmp)-1; k >= 0; k--) ans.pb({tmp[k].se, tmp[k].fi});
        }
        dbg(ans);
        for (int i = 0; i < n; i++) {
                set<int> s;
                for (int j = i + 1; j < n; j++) {
                        if (p[j] < p[i]) {
                                s.insert(p[j]);
                        }
                }
                vpii tmp;
                for (int x : s) {
                        tmp.push_back({p[i], x});
                }
                reverse(all(tmp));
                for (auto x : tmp) ans.pb(x);
        }
        dbg(sz(ans));
        dbg(ans);
        cout << ans.size() << "\n";
        for (auto [x, y] : ans) cout << x << " " << y << "\n";

}