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

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
//unsigned long long mod = 998244353;
const int mod = (1e9) + 7;
#define MAXN 100000
#define int long long
#define sort(v) sort(v.begin(), v.end())
#define print_with_spaces(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << " ";}
#define print_with_lines(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << "\n";}
#define itr(i,a,b) for (unsigned int i = a; i < b; i++)
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define is_possible cout << ((possible) ? "YES\n": "NO\n")
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pi pair<unsigned long long, unsigned long long>
#define pii pair<int,int>
#define vi vector<int>
#define mp make_pair
#define read(v, n) for (unsigned int i = 0; i < n; i++){cin>>v[i];}

int32_t main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n;cin >> n;
	vi a(n + 1);
	for (int i = 1;i <= n;i++)cin >> a[i];
	int c = 0;
	for (int i = 1;i <= n;i++)
		for (int j = i + 1;j <= n;j++){
			if (a[i] > a[j])c++;
}
	int ans = 0;
	for (int i = 1;i <= n;i++) {
		set<int, greater<int>> st;
		for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]);
		for (auto& p : st) {
			//cout << a[i] << " " << p << '\n';
			ans++;
		}
	}
	
	for (int i = 1;i < n;i++)
		 if (a[i] < a[i+1]) {
			 //cout << a[j] << " " << a[i] << '\n';
			 //cout << a[i] << " " << a[j] << '\n';
			 ans+=2;
		}
	cout << ans << endl;
	for (int i = 1;i <= n;i++) {
		set<int, greater<int>> st;
		for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]);
		for (auto& p : st) {
			cout << a[i] << " " << p << '\n';
			//ans++;
		}
	}
	
	for (int i = 1;i < n;i++)
		if (a[i] < a[ i + 1]) {
			int j = i + 1;
			cout << a[j] << " " << a[i] << '\n';
			cout << a[i] << " " << a[j] << '\n';
			//ans += 2;
		}

	return 0;
}


Submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
//unsigned long long mod = 998244353;
const int mod = (1e9) + 7;
#define MAXN 100000
#define int long long
#define sort(v) sort(v.begin(), v.end())
#define print_with_spaces(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << " ";}
#define print_with_lines(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << "\n";}
#define itr(i,a,b) for (unsigned int i = a; i < b; i++)
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define is_possible cout << ((possible) ? "YES\n": "NO\n")
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pi pair<unsigned long long, unsigned long long>
#define pii pair<int,int>
#define vi vector<int>
#define mp make_pair
#define read(v, n) for (unsigned int i = 0; i < n; i++){cin>>v[i];}

int32_t main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n;cin >> n;
	vi a(n + 1);
	for (int i = 1;i <= n;i++)cin >> a[i];
	int c = 0;
	for (int i = 1;i <= n;i++)
		for (int j = i + 1;j <= n;j++){
			if (a[i] > a[j])c++;
}
	int ans = 0;
	for (int i = 1;i <= n;i++) {
		set<int, greater<int>> st;
		for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]);
		for (auto& p : st) {
			//cout << a[i] << " " << p << '\n';
			ans++;
		}
	}
	vi temp;

	for (int i = n;i >= 2;i--) {
		int k = i - 1;

		while (k >= 1 && a[k] < a[i]) {
			//cout << a[i] << " " << a[k] << '\n';
			temp.pb(a[k]);
			k--;
			ans += 1;
		}
		while (!temp.empty()) {
			//cout << temp.back() << " " << a[i] << '\n';
			temp.pop_back();
			ans++;
		}
		temp.clear();
	}

	cout << ans << endl;
	for (int i = 1;i <= n;i++) {
		set<int, greater<int>> st;
		for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]);
		for (auto& p : st) {
			cout << a[i] << " " << p << '\n';
			//ans++;
		}
	}
	for (int i = n;i >= 2;i--) {
		int k = i-1;
		
		while (k>=1&& a[k ] < a[i]) {
			cout << a[i] << " " << a[k] << '\n';
			temp.pb(a[k]);
			k--;
			//ans += 1;
		}
		while (!temp.empty()) {
			cout << temp.back() << " " << a[i] << '\n';
			temp.pop_back();
			//ans++;
		}
		temp.clear();
	}
		

	return 0;
}