Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1093 ms):
#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 ll long long int
#define ull unsigned long long
#define lld long double
#define input(v,n) for(ll i=0;i<n;i++){cin>>v[i];}
#define print(v) for(ll i=0;i<v.size();i++){cout<<v[i]<<" ";}cout<<endl;
const int N = 1e9 + 7;
#define pb push_back
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int qpow(int base, int exp, int mod) {
  int result = 1;
  base = base % mod;
  while (exp > 0) {
    if (exp % 2 == 1) {
      result = (result * base) % mod;
    }
    exp = exp >> 1;
    base = (base * base) % mod;
  }
  return result;
}
int invmod(int a, int m) {
  return qpow(a, m - 2LL, m);
}
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int lcm(int a, int b) {
  return (a * b) / gcd(a, b);
}
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(lld t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(ull t) { cerr << t; }
template <class T, class V> void _print(pair<T, V> p) {
  cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";
}
template <class T> void _print(vector<T> v) {
  cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";
}
template <class T> void _print(set<T> v) {
  cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";
}
template <class T> void _print(multiset<T> v) {
  cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]";
}
template <class T, class V> void _print(map<T, V> v) {
  cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]";
}
//--------------------------------------------------------------------------------------------------------------------------------
int main() {
  fastio();
  #ifndef ONLINE_JUDGE
  freopen("error.txt", "w", stderr);
  freopen("inputf.in","r",stdin);
  freopen("outputf.out","w",stdout);
  #endif
  ll t;
  // cin >> t;
  t=1;

  while (t--) {
     
  int n;
  cin>>n;
  vector<int>c(n+1);
  for(int i=1;i<=n;i++){
    cin>>c[i]; 
  }
  
  vector<pair<int,int>>v;
  for(int i=n;i>=2;i--){
    for(int j=i-1;j>=1;j--){
      v.pb({i,j});
    }
  }
  
  for(int i=1;i<=n;i++){
    vector<pair<int,int>>temp;
    for(int j=i+1;j<=n;j++){
      
      if(c[j] > c[i]){
        temp.pb({c[i],c[j]});
      }
    }
      sort(temp.begin(),temp.end());
      debug(temp)
      for(auto x:temp){
        v.pb(x);
      }
    }
  
  
  cout<<v.size()<<endl;
  for(auto x:v){
    cout<<x.first <<" "<<x.second<<endl;
  }
  

  return 0;
  }
}

Solution 2 (runtime: 311 ms):
#include <bits/stdc++.h>
using namespace std;
#ifndef DEBUGGER
    #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__);
#else
    #define debug(...);
#endif
template <typename T> std::ostream &operator<<(std::ostream &stream, const vector<T> &vec) {for(size_t i = 0; i < vec.size(); i++) { stream << vec[i]; if (i != vec.size() - 1) stream << ' '; }; return stream; } template <typename T> std::istream &operator>>(std::istream &stream, vector<T> &vec) {for (T &x : vec) stream >> x; return stream; } template <typename T, typename U> std::ostream &operator<<(std::ostream &stream, const pair<T, U> &pr) {stream << pr.first << ' ' << pr.second; return stream; } template <typename T, typename U> std::istream &operator>>(std::istream &stream, pair<T, U> &pr) {stream >> pr.first >> pr.second; return stream; } template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(char c) {string s; s += c; return s; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "1" : "0"); } string to_string(vector<bool> v) {bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) {if (!first) {res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) {string res = ""; for (size_t i = 0; i < N; i++) {res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) {bool first = true; string res = "{"; for (const auto &x : v) {if (!first) {res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...); }
using ll = long long;
using ld = long double;
#define in(a, b) for (ll i = (a); i <= (b); i++)                 // in using i
#define inj(a, b) for (ll j = (a); j <= (b); j++)                // in using j
#define ink(a, b) for (ll k = (a); k <= (b); k++)                // in using k
#define inl(a, b) for (ll l = (a); l <= (b); l++)                // in using l
#define inr(a, b) for (ll i = (a); i >= (b); i--)                // in reverse
#define inrj(a, b) for(ll j = (a); j >= (b); j--)                // in reverse
#define inrk(a, b) for(ll k = (a); k >= (b); k--)                // in reverse
#define inrl(a, b) for(ll l = (a); l >= (b); l--)                // in reverse
#define tt ll tcs; cin>>tcs; while(tcs--)                        // include test cases
#define ina(arr,n) ll arr[(n+1)]={0}; in(1,n) cin>>arr[i]        // input arr of n elements
#define inv(vec,n) vector<ll> vec(n+1); vec[0]=0; in(1,n) cin>>vec[i]; // input vector of n elements
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pll pair <ll,ll>
#define vpll vector <pll>
#define sll set <ll>
#define spll set<pll>
#define qll queue<ll>
#define qpll queue<pll>
#define vll vector<ll>
#define mll map <ll,ll>
#define fi first
#define se second
#define vvll vector<vll>
#define vvpll vector<vpll>
#define endl    '\n'
#define all(x)  x.begin(), x.end()
const ll mod=1e9+7;
const ll INF=1e18;
const ll N=1e6;






// //pushes all primes till n in a vector
// void PrimeSieve(ll n,vll &prime){
//     ll CNT=0;
//     ll a[n+1];
//     in(1,n) a[i]=i;
//     in(2,n){
//         if(a[i]!=0){
//             CNT++;
//             prime.pb(i);
//             //cout<<i<<' ';
//             // cout<<i<<endl;
//             for(ll j=i;j<=n;j+=i){
//                 a[j]=0;
//             }
//         }
//     }
//     // cout<<CNT;
// }






// // returns a to power b mod m in log b time
// ll binexp(ll a, ll b,ll m) {
//     ll res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = (res * a)%m;
//         a = (a * a)%m;
//         b >>= 1;
//     }
//     return res;
// }






// // inserts lowest prime factor of i in a[i] till i=n in O(nlogn)
// void insertlp(vll &v,ll n){
//     v.assign(n+1,1);
//     in(2,n){
//         if(v[i]==1){
//             for(ll j=i;j<=n;j+=i){
//                 if(v[j]==1) v[j]=i;
//             }
//         }
//     }
// }






// // converts integer i to binary string of 'bits' bits
// string toBinary(ll i, ll bits)
// {
//     string s = "";
//     while (i > 0)
//     {
//         if (i%2)
//         {
//             s += '1';
//         }
//         else
//             s += '0';
//         i/=2;
//     }
//     // cout<<s.length()<<' '<<bits<<endl;
//     while (s.length() < bits)
//         s += '0';
//     reverse(s.begin(),s.end());
//     return s;
// }






// // converts binary string to decimal number
// ll toDecimal(string &n)
// {
//     ll s=n.length();
//     ll dec_value = 0;
 
//     // Initializing base value to 1, i.e 2^0
//     ll base = 1;
 
//     inr(s-1,0) if(n[i]=='1') dec_value+=pow(2,s-1-i); 
//     return dec_value;
// }






// ll gcd(ll a,ll b){
//     int x = min({a,b});  int y = max({a,b});
//     int modf = y%x;
//     if(modf==0)
//     {
//         return x;
//     }
//     else{
//         while(modf>0){
//             y=x;
//             x=modf;
//             modf = y%x;
//         }
//         return x;
//     }
// }






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






// void swap(ll &x, ll &y){
//     ll temp = x;
//     x = y;
//     y = temp;
// }





// ===================================================
// ||                //------------\                ||
// ||               //              \               ||
// ||              //   O        O   \              ||
// ||              \        !       //              ||
// ||               \              //               ||
// ||                \ ---------- //                ||
// ||                 L___________J                 ||
// ===================================================




// Jab bhi koi naya vector ya array banao toh uska size define karo.




void solve() {
    int n; cin>>n;
    inv(vec, n);
    sll s;
    in(1, n) s.insert(i);
    int c = 1;
    int ans = 0;
    while(c<n)
    {
        int q = vec[c];
        auto it = s.find(q);
        ans += distance(it, s.end())-1+s.size()-1;
        // cout<<distance(it, s.end())-1<<endl<<"//"<<endl;
        s.erase(q);
        c++;
    }
    cout<<ans<<endl;
    in(1, n) s.insert(i);
    s.insert(0);
    c = 1;
    while(c<n)
    {
        int q = vec[c];
        auto it = s.find(q);
        for(auto itt = next(it); itt!=s.end(); itt++)
        {
            if(*itt!=0) cout<<*itt<<" "<<q<<endl;
        }
        for(auto itt = prev(s.end()); itt!= it; itt--)
        {
            if(*itt!=0) cout<<q<<" "<<*itt<<endl;
        }
        for(auto itt = prev(it); itt!=prev(s.begin()); itt--)
        {
            if(*itt!=0) cout<<q<<" "<<*itt<<endl;
        }
        s.erase(q);
        c++;
    }
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    // tt{
    //     solve();
    // }

    solve();
}