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

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

using namespace std;

#define int long long
#define deb(x) cout << #x << " = " << x << endl;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define rep(i,j,k) for(int i=j;i<k;i++)
#define sz(x) (int)(x).size()

#define imax INT_MAX
#define imin INT_MIN
#define PI 3.1415926535897932384626433832795
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+)
#define sortall(x) sort(all(x))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void setIO(string name){
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(!name.empty()){
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
#define here cout << "-----PASS-----" << endl;
const int mxN = 1e5+5;
const int MOD = 998244353;
const int INF = 4e18+50;

//*********************************************************************************


void solve(){
	int n;
	cin >> n ;
	int ar[n+5];
	
	for(int i=1;i<=n;i++) cin >> ar[i];

	VII ans;

	int tmp[n+5];
	for(int i=1;i<=n;i++) tmp[i] = i;

	int pos = 0;

	for(int i=1;i<=n;i++) {
		for(int j=i-pos-1;j>=1;j--) {
			ans.pb({i,tmp[j]});
		}

		for(int j=1;j<=i-pos-1;j++) {
			ans.pb({tmp[j],i});
		}
		//cout << " :: " << tmp[i-pos] << " " << ar[i-pos] << " " << i << " " << pos << " " << i-pos  << endl;
		if(tmp[i-pos] != ar[i-pos]) {
			for(int j=i-pos+1;j<=n;j++) {
				ans.pb({tmp[j], tmp[j-1]});
				swap(tmp[j], tmp[j-1]);
				if(tmp[j] == ar[j]) break;
			}
			
			pos++;
		}
	}
	cout << ans.size() << endl;
	for(PII a : ans) cout << a.F << " " << a.S << endl;
}

int32_t main(){
    string name = "";
    setIO(name);
    int test_cases = 1;
    //cin >> test_cases;
    while(test_cases--) {
        solve(); //cout << endl;
    }

    return 0; 
}

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

using namespace std;

#define int long long
#define deb(x) cout << #x << " = " << x << endl;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define rep(i,j,k) for(int i=j;i<k;i++)
#define sz(x) (int)(x).size()

#define imax INT_MAX
#define imin INT_MIN
#define PI 3.1415926535897932384626433832795
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+)
#define sortall(x) sort(all(x))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void setIO(string name){
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(!name.empty()){
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
#define here cout << "-----PASS-----" << endl;
const int mxN = 1e5+5;
const int MOD = 998244353;
const int INF = 4e18+50;

//*********************************************************************************


void solve(){
	int n;
	cin >> n ;
	int ar[n+5];
	
	for(int i=1;i<=n;i++) cin >> ar[i];

	VII ans;

	int tmp[n+5];
	for(int i=1;i<=n;i++) tmp[i] = i;

	int pos[n+5];
	for(int i=1;i<=n;i++) pos[ar[i]] = i;

	for(int i=n;i>=1;i--) {
		int j=pos[i]-1;
		for(;j>=1;j--) {
			ans.pb({ar[j],ar[j+1]});
			pos[ar[j]]=j+1;
			pos[ar[j+1]]=j;
			swap(ar[j],ar[j+1]);
		}
		for(int j=2;j<=n;j++) {
			if(ar[j] > ar[j-1]) break;
			ans.pb({ar[j],ar[j-1]});
			pos[ar[j]]=j-1;
			pos[ar[j-1]]=j;
			swap(ar[j],ar[j-1]);
		}
	}
	cout << ans.size() << endl;
	reverse(all(ans));
	for(PII a : ans) cout << a.F << " " << a.S << endl;
}

int32_t main(){
    string name = "";
    setIO(name);
    int test_cases = 1;
    //cin >> test_cases;
    while(test_cases--) {
        solve(); //cout << endl;
    }

    return 0; 
}