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


Submission (verdict: Wrong answer on test 1):
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
// using Unordered_map = unordered_map<int, unordered_map<int, unordered_map<int, int>>>;

#define int long long
#define inf 1e18
#define MAXN 100005

int MOD = 1e9 + 7;
int tc;
vector<int> spf(MAXN + 1, 1);

void sieve(){spf[0] = 0;for (int i = 2; i <= MAXN; i++) {if (spf[i] == 1) {for (int j = i; j <= MAXN; j += i) {if (spf[j]== 1) spf[j] = i;}}}}
set<int> getPrimeFactors(int x){int num = x;set<int> factors;while (x != 1) {factors.insert(spf[x]);x = x / spf[x];} return factors;}
int mod_add(int a, int b, int m) { return (a % m + b % m + m) % m; }
int mod_substract(int a, int b, int m){ return (a % m - b % m + m) % m; }
int mod_mult(int a, int b) { return ((a % MOD) * (b % MOD)) % MOD; }
int mod_power(int x, unsigned int y, unsigned int m){if (y == 0){return 1;}int p = mod_power(x, y / 2, m) % m;p = (p % m * p % m) % m;return (y % 2 == 0) ? p : (x % m * p % m) % m;}
int mod_inverse(int a) { return mod_power(a, MOD - 2, MOD); }
int ceil(int a, int b) { return a / b + ((a ^ b) > 0 && a % b); }
int mod_exp(int a, int b, int m){a %= m;int res = 1;while (b > 0){if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;}return res;}
int ithbit(int num, int i){return (num & (1ll << i));}
int digsum(int n){int sum = 0;while(n > 0){sum += (n % 10);n /= 10;}return sum;}
int findXor(int num){ int mod = num%4;if(mod == 0) return num;if(mod == 1) return 1;if(mod == 2) return num+1;if(mod == 3) return 0;}
int rangeXor(int first, int last){return findXor(last) ^ findXor(first - 1);}
int highestPowerof2(int x){x |= x >> 1;x |= x >> 2;x |= x >> 4;x |= x >> 8;x |= x >> 16;return x ^ (x >> 1);}
const auto start_time = chrono::high_resolution_clock::now();
void timeTaken(){auto end_time = chrono::high_resolution_clock::now();chrono::duration<double> diff = end_time - start_time;cerr << "---------------------" << "\n";cerr << "Time Taken : " << diff.count() << " s\n";}
void showans() { cerr << "------ For test case : " << tc << " || ANS : "; }

// prefix/suffix ?


void Solve()
{
    int n; cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++) cin>>arr[i];
    map<int, int> place;
    vector<int> ahead;
    int ans = 0;
    vector<pair<int,int>> over;
    map<int, bool> before;
    map<int, set<int>> overtakes;
    for(int i=1;i<=n;i++) {
        int car = arr[i];
        int starting = car, ending = i;
        for(int j = 1; j < car; j++){
            if(before.find(j) != before.end()) continue;
            over.push_back({car, j});
            overtakes[j].insert(car);
            overtakes[car].insert(j);
            ans++;
            // times[i]++;
        }
        before[car] = true;
    }
    for(int i=1;i<=n;i++){
        for(int j = i+1; j<=n; j++){
            if(i == j) continue;
            if(overtakes[i].find(j) == overtakes[i].end()){
                over.push_back({i, j});
                over.push_back({j, i});
                ans+=2;
            }
        }
    }
    cout<<ans<<endl;
    for(auto &p : over) cout<<p.first<<" "<<p.second<<endl;
}





signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int testcase = 1;
    // cin >> testcase; cerr<<"Multiple TCs"<<endl;
    // sieve();
    for (tc = 1; tc <= testcase; tc++)
    {
        Solve();
    }

    timeTaken();
    return 0;
}