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

Solution 1 (runtime: 1437 ms):
// #include<bits/stdc++.h>
// using namespace std;

// vector<pair<int, int>> find_max_overtakes(int n, vector<int>& c) {
//     vector<pair<int, int>> overtakes;
//     for (int i = 0; i < n; i++) {
//         for (int j = 0; j < n -i- 1; j++) {
//             if (c[j] > c[j + 1]) {
//                 overtakes.emplace_back(c[j], c[j + 1]);
//                 swap(c[j], c[j + 1]);
//             }
//             if(c[j]<c[j+1]){
//                 overtakes.emplace_back(c[j],c[j+1]);
//                 overtakes.emplace_back(c[j+1],c[j]);
//             }
//         }
//     }

//     return overtakes;
// }

// int main() {
//     int n;
//     cin >> n;
//     vector<int> c(n);
//     for (int i = 0; i < n; ++i) {
//         cin >> c[i];
//     }
//     vector<pair<int, int>> overtakes = find_max_overtakes(n, c);
//     for(int i=0;i<overtakes.size();i++){
//         for(int j=i+1;j<overtakes.size();j++){
//             if(overtakes[i].first==overtakes[j].first && overtakes[i].second==overtakes[j].second){
//                 overtakes.erase(overtakes.begin()+j);
//                 overtakes.erase(overtakes.begin()+j-1);
//             }
//         }
//     }
//     cout << overtakes.size() << endl;
//     for (int i=overtakes.size()-1;i>=0;i--){
//         cout<<overtakes[i].first<<" "<<overtakes[i].second<<endl;
//     }

//     return 0;
// }
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int count=0;
    vector<int>c(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-i-1;j++){
            if (c[j]<c[j+1]){
                count++;
                ans.emplace_back(c[j],c[j+1]);
                swap(c[j],c[j+1]);
            }
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-i-1;j++){
            if (c[j]>c[j+1]){
                count++;
                ans.emplace_back(c[j],c[j+1]);
                swap(c[j],c[j+1]);
            }
        }
    }
    cout<<count<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

Solution 2 (runtime: 264 ms):
#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!
*/