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

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define lc(x) (x) << 1
#define rc(x) (x) << 1 | 1
#define midi(x, y) ((x) + (y)) >> 1
#define F first
#define S second
#define fast_io                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define file_io                                                                \
  freopen("in.txt", "r+", stdin);                                              \
  freopen("out.txt", "w+", stdout);
ll poww(ll a, ll b, ll md) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % md) {
    if (b & 1) {
      ans = ans * a % md;
    }
  }
  return ans % md;
}

const int MAXN = 3e3 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int c[MAXN];

int main() {
  fast_io;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  vector<pii> res;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      res.push_back({j, i});
    }
  }

  for (int i = n; i ; i--) {
    for (int j = n; j > i; j--) {
      if(c[i] < c[j]) {
        res.push_back({c[i], c[j]});
      }
    }
  }
  cout << res.size() << endl;
  for(auto x : res) {
    cout << x.F << " " << x.S << endl;
  }
}


Submission (verdict: Accepted):
#pragma GCC optimize("O2")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define lc(x) (x) << 1
#define rc(x) (x) << 1 | 1
#define midi(x, y) ((x) + (y)) >> 1
#define F first
#define S second
#define fast_io                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define file_io                                                                \
  freopen("in.txt", "r+", stdin);                                              \
  freopen("out.txt", "w+", stdout);
ll poww(ll a, ll b, ll md) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % md) {
    if (b & 1) {
      ans = ans * a % md;
    }
  }
  return ans % md;
}

const int MAXN = 3e3 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int c[MAXN];
int inv[MAXN];
int arr[MAXN];

int main() {
  fast_io;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    inv[c[i]] = i;
    arr[i] = n - i + 1;
  }
  vector<pii> res;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      res.push_back({j, i});
    }
  }

  for(int i = 1; i <= n; i++) {
    for(int j = n - 1; j; j--) {
      if(inv[arr[j + 1]] < inv[arr[j]]) {
        res.push_back({arr[j + 1], arr[j]});
        swap(arr[j + 1], arr[j]);
      }
    }
  }
  cout << res.size() << endl;
  for(auto x : res) {
    cout << x.F << " " << x.S << endl;
  }
}