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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rep(i,a,b) for(ll i=(a); i<(b); ++i)
#define repc(i,a,b,c) for(ll i=(a); i<(b); i+=c)
#define repn(i,a,b) for(ll i=(a); i>(b); --i)
#define trav(a,x) for(auto& a: x)
#define travm(a,x) for(const auto& [a, v]: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define tmod(a) ((a%MOD)+MOD)%MOD
#define tmod2(a) ((a%MOD2)+MOD2)%MOD2
#define tmodc(a,b) ((a%b)+b)%b
#define madd(a,b) (tmod(a)+tmod(b))%MOD
#define madd2(a,b) (tmod2(a)+tmod2(b))%MOD2
#define maddc(a,b,c) (tmodc(a,c)+tmodc(b,c))%c
#define pb push_back
#define mp make_pair
#define cauto const auto
using ll = long long;
int iINF = numeric_limits<int>::max();
int MOD = 1e9+7;
int MOD2 = 1e9+22;
#define int ll
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vd = vector<double>;
using vll = vector<ll>;
using vpii = vector<pii>;

ll lINF = numeric_limits<ll>::max();
ll negINF = lINF+1;
double EPS = .00001;
cauto maxn = 200001;

/*
3 1 4 2

4 3 >3notseen inc

3 4 allbutseen dec
3 2
3 1

2 1 >1notseen inc
4 1 

1 4 allbutseen dec
1 2

4 2 allbutseen dec
*/
void solve()
{
  int n;
  cin >> n;
  vi a(n+1);
  rep(i,1,n+1) cin >> a[i];
  vpii moves;
  vi seen(n+1);
  rep(i,1,n)
  { 
    seen[a[i]] = 1;
    rep(j,a[i]+1,n+1) if(!seen[j]) moves.pb({j,a[i]});
    repn(j,n,0) if(!seen[j]) moves.pb({a[i],j});
  }
  cout << sz(moves) << "\n";
  trav(move,moves) cout << move.first << " " << move.second << "\n";
}
void pre()
{
  
}
int32_t main() 
{
  ios::sync_with_stdio(false);
  pre();
  int t=1; //cin >> t;
  while(t--) solve();
}
/*
When flooring double that has been divided, add .00000000001
Careful mixing subtracting and mod!
*/

Code 2:
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rep(i,a,b) for(ll i=(a); i<(b); ++i)
#define repc(i,a,b,c) for(ll i=(a); i<(b); i+=c)
#define repn(i,a,b) for(ll i=(a); i>(b); --i)
#define trav(a,x) for(auto& a: x)
#define travm(a,x) for(const auto& [a, v]: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define tmod(a) ((a%MOD)+MOD)%MOD
#define tmod2(a) ((a%MOD2)+MOD2)%MOD2
#define tmodc(a,b) ((a%b)+b)%b
#define madd(a,b) (tmod(a)+tmod(b))%MOD
#define madd2(a,b) (tmod2(a)+tmod2(b))%MOD2
#define maddc(a,b,c) (tmodc(a,c)+tmodc(b,c))%c
#define pb push_back
#define mp make_pair
#define cauto const auto
using ll = long long;
int iINF = numeric_limits<int>::max();
int MOD = 1e9+7;
int MOD2 = 1e9+22;
#define int ll
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vd = vector<double>;
using vll = vector<ll>;
using vpii = vector<pii>;

ll lINF = numeric_limits<ll>::max();
ll negINF = lINF+1;
double EPS = .00001;
cauto maxn = 200001;

/*
4 3
4 2
4 1
3 2
3 1
2 1

1 2
1 3
1 4
2 3
2 4
3 4
*/
void solve()
{
  int n;
  cin >> n;
  vi a(n+1);
  rep(i,1,n+1) cin >> a[i];
  vpii groups;
  int st = a[1];
  int sz = 1;
  rep(i,2,n+1)
  {
    if(a[i]==st+sz) sz++;
    else groups.pb({st,sz}), st = a[i], sz = 1;
  }
  groups.pb({st,sz});
  vpii moves;
  vi seen(n+1);
  rep(i,1,n+1)
  {
    repn(j,a[i]-1,0) if(!seen[j]) moves.pb({a[i],j});
    seen[a[i]] = 1;
  }
  trav(group,groups)
  {
    if(group.second==1) continue;
    repn(i,group.first+group.second-1,group.first) repn(j,i-1,group.first-1) moves.pb({i,j});
    rep(i,group.first,group.first+group.second-1) rep(j,i+1,group.first+group.second) moves.pb({i,j});
  }
  cout << sz(moves) << "\n";
  trav(move,moves) cout << move.first << " " << move.second << "\n";
}
void pre()
{
  
}
int32_t main() 
{
  ios::sync_with_stdio(false);
  pre();
  int t=1; //cin >> t;
  while(t--) solve();
}
/*
When flooring double that has been divided, add .00000000001
Careful mixing subtracting and mod!
*/

Answer: 1