Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;

void Solve() 
{
	int n;
	cin >> n;
	vector<int> a(n + 1), pos(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]] = i;
	}
	vector<pair<int, int> > overtakes;
	vector<int> current_positioning;
	current_positioning.push_back(1);
	for(int i = 2; i <= n; i++) {
		for(int j = current_positioning.size() - 1; j >= 0; j--) {
			overtakes.push_back({i, current_positioning[j]});
		}
		for(int j = 0; j < current_positioning.size(); j++) {
			if(current_positioning[j] < pos[i]) {
				overtakes.push_back({current_positioning[j], i});
			}
			else {
				current_positioning.insert(current_positioning.begin() + j, i);
				break;
			}
		}

		if(current_positioning.size() == i - 1) {
			current_positioning.push_back(i);
		}
	}

	// for(int i = 0; i < n; i++) {
	// 	for(int j = i + 1; j < n; j++) {
	// 		if(a[i] < a[j]) {
	// 			overtakes.push_back({a[j], a[i]});
	// 			overtakes.push_back({a[i], a[j]});
	// 		}
	// 		else {
	// 			overtakes.push_back({a[i], a[j]});
	// 		}
	// 	}
	// }
	
	cout << overtakes.size() << "\n";
	for(auto p: overtakes) {
		cout << p.first << " " << p.second << "\n";
	}
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

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

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;

void Solve() 
{
	int n;
	cin >> n;
	vector<int> a(n + 1), pos(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]] = i;
	}
	vector<pair<int, int> > overtakes;
	vector<int> current_positioning;
	current_positioning.push_back(1);
	for(int i = 2; i <= n; i++) {
		for(int j = current_positioning.size() - 1; j >= 0; j--) {
			overtakes.push_back({i, current_positioning[j]});
		}
		for(int j = 0; j < current_positioning.size(); j++) {
			if(pos[current_positioning[j]] < pos[i]) {
				overtakes.push_back({current_positioning[j], i});
			}
			else {
				current_positioning.insert(current_positioning.begin() + j, i);
				break;
			}
		}

		if(current_positioning.size() == i - 1) {
			current_positioning.push_back(i);
		}

		// for(int j = 0; j < current_positioning.size(); j++) {
		// 	cout << current_positioning[j] << " ";
		// }
		// cout << "\n";
	}

	// for(int i = 0; i < n; i++) {
	// 	for(int j = i + 1; j < n; j++) {
	// 		if(a[i] < a[j]) {
	// 			overtakes.push_back({a[j], a[i]});
	// 			overtakes.push_back({a[i], a[j]});
	// 		}
	// 		else {
	// 			overtakes.push_back({a[i], a[j]});
	// 		}
	// 	}
	// }
	
	cout << overtakes.size() << "\n";
	for(auto p: overtakes) {
		cout << p.first << " " << p.second << "\n";
	}
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}