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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ar(n) int a[n]; for(int i=0;i<n;i++){cin>>a[i];}
#define br(n) int b[n]; for(int i=0;i<n;i++){cin>>b[i];}
//stalk mt kr bkl 
typedef tree<int, null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
// ye tree vale me first vala datatype h less means ascending order rkhna h greater se descending order hojaega, less_equal se ascending+multiple values
// XOR(l,r) can be found as XOR(0,r)⊕XOR(0,l−1) this is in O(1).
// fibonnaci me agar koi number k se modulo ho toh a,b,c sequence h agar, then c=a+b or c=(a+b)%k dono ka %k same hoga throughout
bool comp(pair<int,int> p1, pair<int,int> p2) {
        if(p1.first > p2.first) return true;
        if(p1.first < p2.first) return false;
        if(p1.first == p2.first){
            if(p1.second<p2.second) return true;

            return false;
        }
    }
    
int mod_exp(int base, int exp, int mod) {
    int result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {  
            result = (result * base) % mod;
        }
        base = (base * base) % mod;  
        exp /= 2;
    }
    return result;
}
int modinv(int a, int mod) {
    return mod_exp(a, mod - 2, mod); 
}
int ap(int a,int n,int d){
  int sum=n*(2*a+(n-1)*d)/2;
  return sum;
}
bool isPrime(int n) {
    // 1 is not prime
    if (n <= 1) return false;
    
    // 2 and 3 are prime numbers
    if (n == 2 || n == 3) return true;
    
    // Check for divisibility by 2 or 3 to handle even and multiples of 3
    if (n % 2 == 0 || n % 3 == 0) return false;

    // Check divisibility from 5 to sqrt(n), skipping even numbers
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) {
            return false;
        }
    }
    
    return true;
}
bool isSorted(vector<int>& b) {
    for (int i = 0; i < b.size() - 1; ++i) {
        if (b[i] > b[i + 1]) return false;
    }
    return true;
}
int findMex(const int arr[], int start, int end) {
    std::unordered_set<int> elements;  // To store unique elements for O(1) lookup
    
    // Insert all elements from the array into the set
    for (int i = start; i <= end; ++i) {
        elements.insert(arr[i]);
    }

    int mex = 0;
    // Increment mex until we find a value not in the set
    while (elements.find(mex) != elements.end()) {
        ++mex;
    }
    //int mex = findMex(arr, size);
    return mex;
}
vector<int> computeSuffixMex(const int arr[], int n) {
    unordered_set<int> seen;
    vector<int> suffixMex(n);
    int mex = 0;
    
    for (int i = n - 1; i >= 0; --i) {
        seen.insert(arr[i]);
        
        // Update mex to be the smallest non-negative integer not in the seen set
        while (seen.find(mex) != seen.end()) {
            ++mex;
        }
        
        suffixMex[i] = mex;
    }
    
    return suffixMex;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    //cin>>t;
    int modu=(1e9)+7;
    while (t--) {
        int n;
        cin>>n;
        ar(n);
        vector<pair<int,int>> v;
        for(int i=0;i<n;i++){
            vector<pair<int,char>>bona;
            for(int j=i+1;j<n;j++){
                if(a[j]>a[i]){
                    bona.push_back({a[j],'b'});
                }else{
                    bona.push_back({a[j],'c'});
                }
            }
            sort(bona.rbegin(),bona.rend());
            for(int k=0;k<bona.size();k++){
                if(bona[k].second=='b'){
                    v.push_back({bona[k].first,a[i]});
                    v.push_back({a[i],bona[k].first});
                }else{
                    v.push_back({a[i],bona[k].first});
                }
            }
        }
        for(int i=0;i<v.size();i++){
            cout<<v[i].first<<' '<<v[i].second<<endl;
        }
    }
    return 0;
}


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ar(n) int a[n]; for(int i=0;i<n;i++){cin>>a[i];}
#define br(n) int b[n]; for(int i=0;i<n;i++){cin>>b[i];}
//stalk mt kr bkl 
typedef tree<int, null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
// ye tree vale me first vala datatype h less means ascending order rkhna h greater se descending order hojaega, less_equal se ascending+multiple values
// XOR(l,r) can be found as XOR(0,r)⊕XOR(0,l−1) this is in O(1).
// fibonnaci me agar koi number k se modulo ho toh a,b,c sequence h agar, then c=a+b or c=(a+b)%k dono ka %k same hoga throughout
bool comp(pair<int,int> p1, pair<int,int> p2) {
        if(p1.first > p2.first) return true;
        if(p1.first < p2.first) return false;
        if(p1.first == p2.first){
            if(p1.second<p2.second) return true;

            return false;
        }
    }
    
int mod_exp(int base, int exp, int mod) {
    int result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {  
            result = (result * base) % mod;
        }
        base = (base * base) % mod;  
        exp /= 2;
    }
    return result;
}
int modinv(int a, int mod) {
    return mod_exp(a, mod - 2, mod); 
}
int ap(int a,int n,int d){
  int sum=n*(2*a+(n-1)*d)/2;
  return sum;
}
bool isPrime(int n) {
    // 1 is not prime
    if (n <= 1) return false;
    
    // 2 and 3 are prime numbers
    if (n == 2 || n == 3) return true;
    
    // Check for divisibility by 2 or 3 to handle even and multiples of 3
    if (n % 2 == 0 || n % 3 == 0) return false;

    // Check divisibility from 5 to sqrt(n), skipping even numbers
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) {
            return false;
        }
    }
    
    return true;
}
bool isSorted(vector<int>& b) {
    for (int i = 0; i < b.size() - 1; ++i) {
        if (b[i] > b[i + 1]) return false;
    }
    return true;
}
int findMex(const int arr[], int start, int end) {
    std::unordered_set<int> elements;  // To store unique elements for O(1) lookup
    
    // Insert all elements from the array into the set
    for (int i = start; i <= end; ++i) {
        elements.insert(arr[i]);
    }

    int mex = 0;
    // Increment mex until we find a value not in the set
    while (elements.find(mex) != elements.end()) {
        ++mex;
    }
    //int mex = findMex(arr, size);
    return mex;
}
vector<int> computeSuffixMex(const int arr[], int n) {
    unordered_set<int> seen;
    vector<int> suffixMex(n);
    int mex = 0;
    
    for (int i = n - 1; i >= 0; --i) {
        seen.insert(arr[i]);
        
        // Update mex to be the smallest non-negative integer not in the seen set
        while (seen.find(mex) != seen.end()) {
            ++mex;
        }
        
        suffixMex[i] = mex;
    }
    
    return suffixMex;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    //cin>>t;
    int modu=(1e9)+7;
    while (t--) {
        int n;
        cin>>n;
        ar(n);
        vector<pair<int,int>> v;
        for(int i=0;i<n;i++){
            vector<pair<int,char>>bona;
            for(int j=i+1;j<n;j++){
                if(a[j]>a[i]){
                    bona.push_back({a[j],'b'});
                }else{
                    bona.push_back({a[j],'c'});
                }
            }
            sort(bona.rbegin(),bona.rend());
            for(int k=0;k<bona.size();k++){
                if(bona[k].second=='b'){
                    v.push_back({bona[k].first,a[i]});
                    v.push_back({a[i],bona[k].first});
                }else{
                    v.push_back({a[i],bona[k].first});
                }
            }
        }
        cout<<v.size()<<endl;
        for(int i=0;i<v.size();i++){
            cout<<v[i].first<<' '<<v[i].second<<endl;
        }
    }
    return 0;
}