Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

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

#define int long long
#define Int __int128_t
#define bpc(x) __builtin_popcountll(x)
#define msb(x) (63-__builtin_clzll(x))

#ifdef DEBUG
#define dbg(x) cout<<"["<< #x <<"] : "<<(x)<<endl;
#else
#define dbg(x)
#endif

int bpow(int a, int b, long long mod=LLONG_MAX){
	int res=1;while(b){if(b%2)res=res*a%mod;a=a*a%mod;b/=2;}return res;
}
int inv(int a, int mod=1e9+7){ return bpow(a, mod-2, mod); }

void doumo_same_desu(); int TC, ALLTC;
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(5);

	// cin >> ALLTC; for(TC=1;TC<=ALLTC;TC++)
  doumo_same_desu();
}


void doumo_same_desu(){
  int n;
  cin >> n;
  vector<int> st(n+1), final(n+1);;
  vector<vector<bool>> used(n + 1, vector<bool>(n + 1, 0));
  for(int i = 1; i <= n; i++){
    cin >> final[i];
    st[i] = i;
  }

  vector<pair<int,int>> res;
  for(int i = 1; i <= n; i++){ // order by final pos
    int now = final[i];

    // cout << "mundur " << i << '\n';;
    // bawa mundur
    while(now + 1 <= n && !used[st[now + 1]][st[now]]){
      res.push_back({st[now + 1], st[now]});
      // cout << res.back().first << ' ' << res.back().second << '\n';
      used[st[now + 1]][st[now]] = 1;
      swap(st[now + 1], st[now]);
      now++;
    }

    // cout <<"maju " << i << '\n';
    // bawa maju lagi
    while(now - 1 >= i && !used[st[now]][st[now - 1]]){
      res.push_back({st[now], st[now - 1]});
      // cout << res.back().first << ' ' << res.back().second << '\n';
      used[st[now]][st[now - 1]] = 1;
      swap(st[now], st[now - 1]);
      now--;
    }
  }
  cout << (int)res.size() << '\n';
  for(auto[x,y]:res) cout << x << ' ' << y << '\n';
}

/*

*/


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

#define int long long
#define Int __int128_t
#define bpc(x) __builtin_popcountll(x)
#define msb(x) (63-__builtin_clzll(x))

#ifdef DEBUG
#define dbg(x) cout<<"["<< #x <<"] : "<<(x)<<endl;
#else
#define dbg(x)
#endif

int bpow(int a, int b, long long mod=LLONG_MAX){
	int res=1;while(b){if(b%2)res=res*a%mod;a=a*a%mod;b/=2;}return res;
}
int inv(int a, int mod=1e9+7){ return bpow(a, mod-2, mod); }

void doumo_same_desu(); int TC, ALLTC;
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(5);

	// cin >> ALLTC; for(TC=1;TC<=ALLTC;TC++)
  doumo_same_desu();
}


void doumo_same_desu(){
  int n;
  cin >> n;
  vector<int> st(n+1), final(n), pos(n + 1);// posisi suatu bilangan di st
  vector<vector<bool>> used(n + 1, vector<bool>(n + 1, 0));
  for(int i = 1; i <= n; i++){
    cin >> final[i - 1];
    pos[i] = i;
    st[i] = i;
  }

  vector<pair<int,int>> res;
  int rank = 1;
  for(int now : final){ // order by final pos
    int p = pos[now];
    // dbg(now);
    // dbg(p);
    // cout << "mundur\n";
    // bawa mundur
    while(p + 1 <= n){
      res.push_back({ st[p + 1], st[p] });
      // cout << res.back().first << ' ' << res.back().second << "\n";
      swap(pos[st[p]], pos[st[p+1]]);
      swap(st[p], st[p+1]);
      p++;
    }
    // cout << "pos:\n";
    // for(int i = 1; i <= n; i++){
    //   cout << i << ' ' << pos[i] << '\n';
    // }

    // cout << "maju\n";
    // bawa maju
    while(p - 1 >= rank){
      res.push_back({ st[p], st[p - 1] });
      // cout << res.back().first << ' ' << res.back().second << "\n";
      swap(pos[st[p]], pos[st[p-1]]);
      swap(st[p], st[p-1]);
      p--;
    }

    // cout << "pos:\n";
    // for(int i = 1; i <= n; i++){
    //   cout << i << ' ' << pos[i] << '\n';
    // }

    rank++;
  }

  cout << (int)res.size() << '\n';
  for(auto[x,y]:res) cout << x << ' ' << y << '\n';
}

/*

*/