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


Submission (verdict: Wrong answer on test 1):
#pragma GCC optimize("Ofast","unroll-loops")

#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 fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define int long long

#define N 10000005

#define pYES cout<<"YES"<<endl;

#define pNO cout<<"NO"<<endl;



#define debug(x) cerr<<#x<<" "<<x<<endl;



template<typename T>

ostream& operator<<(ostream& os, const vector<T>& v) {

    os << "[ ";

    for (const auto& elem : v) os << elem << " ";

    os << "]";

    return os;

}



template<typename T>

ostream& operator<<(ostream& os, const set<T>& s) {

    os << "{ ";

    for (const auto& elem : s) os << elem << " ";

    os << "}";

    return os;

}



template<typename K, typename V>

ostream& operator<<(ostream& os, const map<K, V>& m) {

    os << "{ ";

    for (const auto& pair : m) os << "(" << pair.first << ": " << pair.second << ") ";

    os << "}";

    return os;

}



template<typename T>

ostream& operator<<(ostream& os, const unordered_set<T>& us) {

    os << "{ ";

    for (const auto& elem : us) os << elem << " ";

    os << "}";

    return os;

}



template<typename K, typename V>

ostream& operator<<(ostream& os, const unordered_map<K, V>& um) {

    os << "{ ";

    for (const auto& pair : um) os << "(" << pair.first << ": " << pair.second << ") ";

    os << "}";

    return os;

}



template<typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;



template<typename T>

using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;



int MOD=1e9+7;



struct pair_hash {

    inline std::size_t operator()(const std::pair<int,int> & v) const {

        return v.first*31+v.second;

    }

};



// ^^^^^^^^^^^^ MODULAR EXPO ^^^^^^^^^^^^^^



int modExp(int a,int b,int mod=MOD){

    int ans=1;

    while(b>0){

        if(b&1){

            ans=(ans*1LL*a)%mod;

        }

        a=(a*1LL*a)%mod;

        b=b>>1;

    }

    return ans;

}



// ^^^^^^^^^^^^ PRIME CHECK ^^^^^^^^^^^^^^



bool checkPrime(int a){

    for(int i=2;i*i<=a;i++){

        if(a%i==0) return false;

    }

    return true;

}



// ^^^^^^^^^^^^ SIEVE OF ERASTOSTHENES ^^^^^^^^^^^^^^



void sievePrime(int n){

    // prime vector stores prime check boolean

    vector<bool> prime(n+1,true);

    prime[1]=false;

    for(int i=2;i<=n;i++){

        if(prime[i] && i*i<=n){

            for(int j=i*i;j<=n;j+=i){

                prime[j]=false;

            }

        }

    }



}



// ^^^^^^^^^^^^ EUCLID GCD ^^^^^^^^^^^^^^

int gcd(int a,int b)

{

    if(a==0) return b;

    return gcd(b%a,a);

}



int lcm(int a, int b) { return a / gcd(a, b) * b; }



long long mod=1e9+7;

int nCrModp(int n, int r, int p=mod)

{

    if (r > n - r)

        r = n - r;

    int C[r + 1];

    memset(C, 0, sizeof(C));

 

    C[0] = 1;

    for (int i = 1; i <= n; i++) {

        for (int j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j - 1]) % p;

    }

    return C[r];

}



// ^^^^^^^^^^^^ TO CHECK IF NUMBER IS POWER OF TWO ^^^^^^^^^^^^^^



bool isPowerOfTwo(int x)

{

    return x && (!(x & (x - 1)));

}



void dfs(vector<set<int>>& adj,int node,vector<bool>& vis){

    vis[node]=true;

    for(auto i : adj[node]){

        if(!vis[i]){

            dfs(adj,i,vis);

        }

    }

}



void solve(){

    int n;

    cin>>n;

    vector<int> c(n);

    for(int i=0;i<n;i++) cin>>c[i];

    vector<vector<int>> ans;

    for(int i=0;i<n;i++){

        for(int j=i-1;j>=0;j--){

            if(c[j]>c[i]){

                ans.push_back({c[j],c[i]});

            }

        }

        for(int j=i+1;j<n;j++){

            if(c[j]>c[i]){

                ans.push_back({c[j],c[i]});

                ans.push_back({c[i],c[j]});

            }

        }

    }

    cout<<ans.size()<<endl;

    for(auto i : ans){

        cout<<i[0]<<" "<<i[1]<<endl;

    }

}



signed main(){

    fastio;

    #ifndef ONLINE_JUDGE

    freopen("input.txt","r",stdin);

    freopen("output.txt","w",stdout);

    #endif

    int t=1;

    // cin>>t;

    for(int i=1;i<=t;i++){

        solve();

    }

    return 0;

}