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

Previous submission (verdict: Wrong answer on test 7):
// Problem: A. Adrenaline Rush
// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/2052/A
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;

const int M = 1e9+7;
const int N = 2e6 + 10;
int a[N], b[N];
int l[N], r[N];
char g[110][110];
char mapp[110][110];
bool st[110][110];
int n, m;

void solve() {
	cin >> n;
	map<int, int> h;
	for(int i = 1;i <= n;i ++) {
		cin >> a[i];
		b[i] = i;
		h[i] = i;
	}
	
	vector<pii> ans;
	
	for(int i = n;i >= 1;i --) {
		if(a[i] < b[i]) {
			for(int j = h[a[i]];j < i;j ++) {
				ans.push_back({b[j + 1],b[j]});
				h[b[j]] = j + 1;
				h[b[j + 1]] = j;
				swap(b[j + 1],b[j]);
			}
		} else {
			if(i == 1) break;
			int idx = -1;
			for(int j = i - 1;j >= 1;j --) {
				if(a[j] < b[j]) {
					idx = j + 1;
					break;
				}
			}
			if(idx == -1) idx = 1;
			// cout << idx << endl;
			vector<pii> tmp;
			int len = i - idx;
			int cnt = 0;
			while(cnt < len) {
				int j = i;
				for(;j > idx + cnt;j --) {
					tmp.push_back({a[j], a[j - 1]});
					ans.push_back({a[j], a[j - 1]});
					swap(a[j], a[j - 1]);
				}
				cnt ++;
			}
			reverse(tmp.begin(), tmp.end());
			for(auto t : tmp) {
				ans.push_back({t.second, t.first});
			}
			i = idx;
		}
		
		// for(int i = 1;i <= n;i ++) {
			// cout << b[i] << " ";
		// }
		// cout << endl;
	}
	
	cout << ans.size() << endl;
	for(auto t : ans) {
		cout << t.first << " " << t.second << endl;
	}
}

int main() {
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}



Submission (verdict: Wrong answer on test 4):
// Problem: A. Adrenaline Rush
// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/2052/A
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;

const int M = 1e9+7;
const int N = 2e6 + 10;
int a[N], b[N];
int l[N], r[N];
char g[110][110];
char mapp[110][110];
bool st[110][110];
int n, m;

void solve() {
	cin >> n;
	set<int> S;
	for(int i = 1;i <= n;i ++) {
		cin >> a[i];
		S.insert(i);
	}
	
	vector<pii> ans;
	
	for(int i = n;i >= 1;i --) {
		for(int j = 1;j < a[i];j ++) {
			if(S.count(j) == 0) continue;
			ans.push_back({a[i], j});
		}
		S.erase(a[i]);
		for(auto t : S) {
			ans.push_back({t, a[i]});
		}
	}
	
	cout << ans.size() << endl;
	for(auto t : ans) {
		cout << t.first << " " << t.second << endl;
	}
}

int main() {
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}