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

Solution 1 (runtime: 312 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using ld = long double;
const int N = 1e6+ 10;
int mod = 1e9 + 7;
ll n,m;
ll a[N], b[N];
// int tree[N];
string s;
char c1,c2,c3;
priority_queue<ll, vector<ll>, greater<ll>> qmin;
priority_queue<ll> qmax;
ll max(ll aa, ll bb){return aa > bb?aa:bb;}
ll min(ll aa, ll bb){return aa < bb?aa:bb;}
ll qm(ll x, ll y){
    ll ret = 1;
    while(y){
        if(y&1) ret = ret * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ret;
}
// int find(int x){
//     return fa[x] == x?x:fa[x] = find(fa[x]);
// }

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    vector<pi> st;
    for(int i = n; i >= 1; i--) {
        for(int j = i - 1; j >= 1; j--) {
            st.push_back({i, j});
        }
    }
    map<int, int> mp;
    for(int i = 1; i <= n; i++) b[i] = n + 1 - i, mp[n + 1 - i] = i;
    for(int i = 1; i <= n; i++) {
        int index = -1;
        for(int j = 1; j <= n; j++) if(b[j] == a[i]) index = j;
        for(int j = index - 1; j >= i; j--) {
            st.push_back({b[j + 1], b[j]});
            swap(b[j + 1], b[j]);
        }
    }
    cout << st.size() << '\n';
    for(auto i: st) cout << i.first << ' ' << i.second << '\n';
}
int main()
{
  // 请在此输入您的代码
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
//     cin >> _;
    while(_--) solve();
}

Solution 2 (runtime: 1125 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 ld long double
#define nl "\n"
#define py cout << "YES" << nl;
#define pn cout << "NO" << nl;
#define PI 3.141592653589793238
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define ff first
#define ss second
#define fastio()                    \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
ll MOD = 1e9 + 7;
ll MOD1 = 998244353;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << x << nl;
#else
#define debug(x)
#endif
void printarr(vector<ll> &arr)
{
  for (auto i : arr)
    cout << i << " ";
  cout << nl;
}
ll power(ll n, ll p)
{
  if (p == 0)
    return 1;
  if (p == 1)
    return n;
  if (p % 2 == 0)
  {
    ll smallans = power(n, p / 2);
    return (smallans * smallans);
  }
  else
  {
    ll smallans = power(n, p / 2);
    return ((smallans * smallans) * n);
  }
}
// (a^b)%m here m=modulo
//(a#b)%m=((a%m)#(b%m))%m  #-> (+ or *)
// (a-b)%m=((a%m)-(b%m)+m)%m
//(a/b)%m=((a%m)*(inverse(b,m)))%m

/*
    // 1 2 4 5 5 5 7 8 25
   // lower_bound(5)= index 3 if the ele present then first occurance
   // lower_bound(6)= index 6 if not present then the value greater than that present on the array
   // upper_bound(5)= index 6 the value which is greater than the element present on the array
   // upper_bound(6)=index 6
  //  it1=lower_bound(v.begin(),v.end(),7);
   // it2=upper_bound(v.begin(),v.end(),7);
   // cout<<(it1-v.begin())<<endl;
   // cout<<(it2-v.begin())<<endl;
*/

ll powermod(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;
}

// (1/a)%m
ll inverse(ll a, ll MOD)
{
  return powermod(a, MOD - 2, MOD);
}

ll GCD(ll a, ll b)
{
  if (a == 0)
  {
    return b;
  }
  return GCD(b % a, a);
}
// calculate how many set bit in n
int cal_setbit(int n)
{
  int c = 0, x;
  while (n > 0)
  {
    x = n & (-n); // This calculate the  right most set bit
    c++;
    n = n - x;
  }
  return c;
}
ll nCr(ll n, ll r, ll m)
{
  if (n < r)
    return 0;
  if (r == 0)
    return 1;
  vector<ll> fact(n + 1, 0);
  fact[0] = 1;
  for (ll i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * i) % m;
  return ((((fact[n] % m) * inverse(fact[r], m)) % m) * inverse(fact[n - r], m)) % m;
}

vector<ll> sieve()
{
  ll n = 1e6 + 1;
  vector<ll> arr(n, 1);
  for (ll i = 2; i <= n; i++)
  {
    if (arr[i] == 1)
    {
      for (ll j = i * i; j <= n; j += i)
      {
        arr[j] = 0;
      }
    }
  }
  arr[1] = 0;

  return arr;
}

void solve()
{
    ll n;
    cin>>n;
    vector<ll>a(n),b(n),c(n);
    vector<pair<ll,ll>>ans;
    for(ll i=0;i<n;i++)
    cin>>a[i];
    for(ll i=0;i<n;i++)
    {
    b[i]=i+1;
    }
    if(n>2)
    c[1]=1;
    for(ll i=2;i<=n;i++)
    {
        ll cnt=0;
        for(ll j=0;j<n;j++)
        {
            if(a[j]<i)
            cnt++;
            if(a[j]==i)
            break;
        }
        //cnt=i-1+cnt;
        for(ll j=i-2;j>=0;j--)
        ans.push_back({i,b[j]});
        for(ll j=0;j<cnt;j++)
        {
           ans.push_back({b[j],i});
           c[j]=b[j];
        }
        c[cnt]=i;
        for(ll j=cnt+1;j<i;j++)
        c[j]=b[j-1];
        b=c;

    }
    cout<<ans.size()<<endl;
    for(auto it:ans)
    {
    //  if(it.first==0)
    //  it.first=1;
    //  if(it.second==0)
    //  it.second=1;
    cout<<it.first<<" "<<it.second<<endl;
    }
}
int main()
{
  fastio();
  cout << setprecision(12) << fixed;

  

   solve();
  
}