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

Previous submission (verdict: Wrong answer on test 7):
/*Author: justsurfing

Go hard or go home

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define endl "\n"

#define pb push_back

#define mod 1000000007

#define inf 100000000000000000

#define CHAR 256

#define all(x) x.begin(), x.end()

#define limit 100005

#define loop(i, s, l, j) for(int i = s; i < l; i += j)

#define N  200005

ll fact[N + 1];

ll inv[N + 1];

ll invFact[N + 1];

bool isComputed = false;

void compute() {

    inv[0] = inv[1] = 1;



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

        inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;

    }



    invFact[0] = invFact[1] = 1;

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

        invFact[i] = (invFact[i - 1] * inv[i]) % mod;

    }



    fact[0] = fact[1] = 1;

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

        fact[i] = (fact[i - 1] * i) % mod;

    }

    isComputed = true;

}

ll ncr(ll n, ll k) {

    if (!isComputed) {

        printf("Call compute function, you idiot");

    }

    else {

        return (((fact[n] * invFact[k]) % mod) * invFact[n - k]) % mod;

    }

    return -1;

}

ll power( int x, int y)

{

    ll temp = x;

    ll result = 1;

    while (y > 0) {

        if ((y & 1) == 1) // y is odd

        {

            result = (result * temp) % mod;

        }

        temp = (temp * temp) % mod;

        y = y >> 1; // y=y/2;

    }

    return result % mod;

}

void SieveOfEratosthenes(int n, vector<int>&get)

{

    bool prime[n + 1];

    memset(prime, true, sizeof(prime));



    for (int p = 2; p * p <= n; p++) {



        if (prime[p] == true) {



            for (int i = p * p; i <= n; i += p)

                prime[i] = false;

        }

    }



    // Print all prime numbers

    for (int p = 2; p <= n; p++)

        if (prime[p])

            // cout << p << " ";

            get.pb(p);

}

#include <vector>





int main() {

    /*Uncommment for the sieve */

    //  vector<int>get;

    //     SieveOfEratosthenes(1000005,get);

    // compute();

    //uncomment this for calc nCr

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(0);

    int t, n;

    // cin >> t;?

    t = 1;

    // 1. brute force | 2. two pointers | 3. Prefix sum | 4. Binary search

    // 5. DSA | 6. Graphs | 7. DP

    // constructive fucks //string

    while (t--)

    {

        // int mod=1e9+7;

        cin >> n;

        vector<int>arr(n);

        for (auto &i : arr)cin >> i;

        vector<pair<int, int>>ans;

        for (int i = n; i >= 2; i--)

        {

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

            {

                ans.pb({i, j});

            }

        }

        // for (auto i : ans)

        // {

        //     cout << i.first << " " << i.second << endl;

        // }

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

        {

            int cur = arr[i];

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

            {

                if (arr[j] > cur)

                {

                    ans.pb({cur, arr[j]});

                }

            }

        }

        // 1 2 3

        // let's try to sort them they are already sorted

        // assume they remain sorted

        vector<pair<int, int>>s;

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

        {

            int cur = arr[i];

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

            {

                if (arr[j] < cur)

                {

                    s.pb({cur, arr[j]});

                }

            }

        }

        // second option hai ke we assume they remain the same

        // 2 1

        // can we do it

        int x = s.size();

        int y = ans.size();

        if (y < x)

        {

            swap(ans, s);

        }



        cout << ans.size();

        cout << endl;

        for (auto i : ans)cout << i.first << " " << i.second << endl;

        // cout << endl;

        // for (auto i : s)cout << i.first << " " << i.second << endl;





    }

    return 0;

}

Submission (verdict: Accepted):
/*Author: justsurfing
Go hard or go home
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define pb push_back
#define mod 1000000007
#define inf 100000000000000000
#define CHAR 256
#define all(x) x.begin(), x.end()
#define limit 100005
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define N  200005
ll fact[N + 1];
ll inv[N + 1];
ll invFact[N + 1];
bool isComputed = false;
void compute() {
    inv[0] = inv[1] = 1;

    for (int i = 2; i <= N; i++) {
        inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;
    }

    invFact[0] = invFact[1] = 1;
    for (int i = 2; i <= N; i++) {
        invFact[i] = (invFact[i - 1] * inv[i]) % mod;
    }

    fact[0] = fact[1] = 1;
    for (int i = 2; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    isComputed = true;
}
ll ncr(ll n, ll k) {
    if (!isComputed) {
        printf("Call compute function, you idiot");
    }
    else {
        return (((fact[n] * invFact[k]) % mod) * invFact[n - k]) % mod;
    }
    return -1;
}
ll power( int x, int y)
{
    ll temp = x;
    ll result = 1;
    while (y > 0) {
        if ((y & 1) == 1) // y is odd
        {
            result = (result * temp) % mod;
        }
        temp = (temp * temp) % mod;
        y = y >> 1; // y=y/2;
    }
    return result % mod;
}
void SieveOfEratosthenes(int n, vector<int>&get)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++) {

        if (prime[p] == true) {

            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p = 2; p <= n; p++)
        if (prime[p])
            // cout << p << " ";
            get.pb(p);
}
#include <vector>


int main() {
    /*Uncommment for the sieve */
    //  vector<int>get;
    //     SieveOfEratosthenes(1000005,get);
    // compute();
    //uncomment this for calc nCr
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int t, n;
    // cin >> t;?
    t = 1;
    // 1. brute force | 2. two pointers | 3. Prefix sum | 4. Binary search
    // 5. DSA | 6. Graphs | 7. DP
    // constructive fucks //string
    while (t--)
    {
        // int mod=1e9+7;
        cin >> n;
        vector<int>arr(n);
        for (auto &i : arr)cin >> i;
        vector<pair<int, int>>ans;
        vector<int>ou(n);
        for (int i = 0; i < n; i++)ou[i] = i + 1;
        for (int i = n; i >= 2; i--)
        {
            for (int j = i - 1; j >= 1; j--)
            {
                ans.pb({i, j});
            }
        }
        // for (auto i : ans)
        // {
        //     cout << i.first << " " << i.second << endl;
        // }
        map<int, int>mp;
        int c = 0;
        for (auto i : arr)
        {
            mp[i] = c;
            c++;
        }
        // for()
        for (int i = n - 1; i > 0; i--)
        {
            int cur = i;
            for (int j = n - 1; j >= mp[i] + 1; j--)
            {
                if (arr[j] > cur)
                {
                    ans.pb({cur, arr[j]});
                }
            }
        }

        cout << ans.size();
        cout << endl;
        for (auto i : ans)cout << i.first << " " << i.second << endl;


    }
    return 0;
}