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


Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long 
#define ld long double
#define pb push_back
#define PI 3.1415926535897932384626433832795l 
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ld EPS = 1e-9;
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define EACH(x, a) for(auto& x: a)
#define max_all *max_element
#define min_all *min_element 
#define vll std::vector<ll>
#define str std::string
bool is_prime(ll x){for(ll i=2;i*i<=x;i++) if(x%i==0) return 0; return 1;}
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);} 
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
void vin(vector<int> &v,int m){for (int i = 0; i < m; ++i){int x;cin>>x;v.push_back(x);}}
void vin(vector<ll> &v,int m){for (int i = 0; i < m; ++i){ll x;cin>>x;v.push_back(x);}}
void vin(vector<char> &v,int m){for (int i = 0; i < m; ++i){char x;cin>>x;v.push_back(x);}}
void vout(vector<int> &v){for (int i = 0; i < int(v.size()); ++i){cout<<v[i]<<" ";}}
void vout(vector<ll> &v){for (int i = 0; i < int(v.size()); ++i){cout<<v[i]<<" ";}}
void vout(vector<char> &v){for (int i = 0; i < int(v.size());
 ++i){cout<<v[i]<<" ";}}
std::string trim(const std::string &s){auto start = s.begin();while (start != s.end() && std::isspace(*start)) {start++;}auto end = s.end();do {end--;} while (std::distance(start, end) > 0 && std::isspace(*end));return std::string(start, end + 1);}
void showset(set<int> &s){for(auto x:s){cout<<x<<" ";}cout<<endl;}
void showunset(unordered_set <int> &u){for(auto x:u){cout<<x<<" ";}cout<<endl;}
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
// https://csacademy.com/app/graph_editor/ --->Graph visualizer 

// const int n=1e5+10;
// vector<bool> isprime(n+1, true);
// void sieve(){
//  isprime[0] = isprime[1] = false;
//  for (int i = 2; i * i <= n; i++) {
//      if (isprime[i]) {
//          for (int j = i * i; j <= n; j += i)
//              isprime[j] = false;
//          }
//  }
// }
// void give_prime(int n){
//  for (int i = 1; i <=n; ++i)
//  {
//      if(isprime[i]) cout<<i<<" ";
//  }
//  cout<<"\n"; 
// }

bool sortbysecdesc(const pair<int,int> &a,const pair<int,int> &b)
{      
    if(a.first==b.first) return a.second>b.second;
    else return a.first>b.first;
}

ll BinaryExp(ll a,ll n){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans*=a;
        }
        n>>=1;
        a*=a;
    }
    return ans;

}
bool is_valid(ll i,ll j,vector<string> &v){
    if(i>=0 && j>=0 && i<v.size() && j<v[0].size()) return true;
    return false;
}

int main(){
    FAST                
    int t=1;
    // read(t);
    for(int qqq=1;qqq<=t;qqq++){
        // cout<<"Case #"<<qqq<<": ";
        ll n;
        read(n);
        vll v;
        vin(v,n);
        vector<pair<ll,ll>> ans;
        for(ll i=0;i<n-1;i++){
            set<ll> less,more;
            for(ll j=i+1;j<n;j++){
                if(v[j]>v[i]){
                    more.insert(v[j]);
                }
                else less.insert(v[j]);
            }
            for(auto &x:more){
                ans.push_back({x,v[i]});
                ans.push_back({v[i],x});
            }
            for(auto &x:less){
                ans.push_back({v[i],x});
            }
        }
        cout<<ans.size()<<endl;
        for(auto &x:ans) cout<<x.first<<" "<<x.second<<endl;
    }
}