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

Solution 1 (runtime: 265 ms):
//One piece is Real
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(n) push_back(n)
#define _sort(v) sort(v.begin(),v.end())
#define REP(i,a,y)  for(int i = int(a); i < int(y); i++)
#define REPL(i,a,y)  for(ll i = ll(a); i < ll(y); i++)
// Declaring ordered set
// #include <ext/pb_ds/assoc_container.hpp> 
#define vi vector <int>
#define vll vector <long long>
#define printv(v, n) for(int i=0;i<n;i++){cout<<v[i]<<" ";}cout<<endl;
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int size=1e5;
const ll MOD=1e9+7;
// const ll MOD=998244353;
const int N = 2e5 + 5;
 
// ll power(ll a,ll ans){
//     if(ans == 0){
//         return 1;
//     }
//     ll ans = power(a,ans/2);
//     ans *= ans;
//     ans %= MOD;
//     if(ans % 2){
//         ans *= a;
//     }
//     return ans % MOD;
// }
// ll fact(ll n){
//     if(n == 1 || n==0)return 1;
//     return n*fact(n-1);
// }
 
ll dis(ll x2,ll y2,ll x1, ll y1 ) {
    return (ll)(x2-x1)*(x2-x1) + (ll)(y2-y1)*(y2 - y1);
}  
// ll build( ll k ,ll i, ll j, ll n, ll m) {
//     ll right = min(i, n - k);
//     ll left = max(-1LL, i - k); 
//     ll up = min(j, m - k); 
//     ll down = max(-1LL, j - k);
//     return ( right - left) * (up - down); 
// }
// ll fact[N];
// ll C(ll n, ll k) {
// 	if(n < k) return 0LL;
// 	return (fact[n] * power((fact[n - k] * fact[k]) % MOD, MOD - 2)) % MOD;
// }
void pA(){

   int n;
    cin >> n;
    
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }
    
    vector<array<int, 2>> ans;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (c[j] < c[j + 1]) {
                ans.push_back({c[j + 1], c[j]});
                std::swap(c[j + 1], c[j]);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (c[j] > c[j + 1]) {
                ans.push_back({c[j + 1], c[j]});
                std::swap(c[j + 1], c[j]);
            }
        }
    }
    reverse(ans.begin(), ans.end());
    
    cout << ans.size() << "\n";
    for (auto [x, y] : ans) {
        cout << y + 1 << " " << x + 1 << "\n";
    }

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.precision(10); cout.setf(ios::fixed);
    // a.find(ans)!=std::string::npos)
    int t;
    // cin>>t;
    // while(t--)
    pA();
}

Solution 2 (runtime: 1218 ms):
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define loop(j,n) for(int i = j; i < n;i++)
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
typedef vector<ll> vll;

const int M=998244353;



// Figuring out the Nature of an Optimal Solution. One of the most important thing in problems imo.

// Solving subtasks of the original problem and then trying to extend/generalize your solution.

// Fixing a parameter and then trying to maximise the result with respect to that fixed parameter.

// Finding necessary and sufficient conditions. Sometimes, your necessary conditions themselves become sufficient, or vice versa.

// Identifying Lower and Upper bounds, and constructing them.

// Reducing a problem into smaller subproblems, commonly used with Dynamic Programming or Inductive Proofs.

// Considering the Decision Version of the Problem instead. Especially useful in Counting problems, where you need to count number of good subsequences for example.

// Formalizing the Problem
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll ele=a*b;
    ll ele1=gcd(a,b);
    return ele/ele1;
}
int get_bit(ll n,ll pos){
    return (n&(1LL<<pos))!=0;
}
set<ll>set1;
map<ll,int>freq;
bool checker(vll &arr,int &n,ll &mid){
    
    
    for(int i=0;i<mid;i++){
        set1.insert(arr[i]);
        freq[arr[i]]++;
    }
    
    if(set1.size()==mid){
        return true;
    }
    int j=0;
    for(int i=mid;i<n;i++){
        if(freq[arr[j]]==1){
            set1.erase(arr[j]);
        }
        freq[arr[j]]--;
        j++;
        set1.insert(arr[i]);
        freq[arr[i]]++;
        if(set1.size()==mid){
            return true;
        }
    }
    return false;
}
void solve(){
    int n;
    cin>>n;
    vi arr(n);
    loop(0,n){
        cin>>arr[i];
    }
    vi idx(n+1,-1);
    loop(0,n){
        idx[arr[i]]=i;
    }
    vector<pair<int,int>>v;
    vector<pair<int,int>>tmp;
    loop(0,n){
        // cout<<i<<endl;
        tmp.clear();
        int count=0;
        for (int j = i+1; j < n; j++)
        {
            if(arr[i]<arr[j]){
                // cout<<arr[j]<<" "<<arr[i]<<endl;
                tmp.push_back({arr[j],arr[i]});
                count++;
            }
        }
        sort(tmp.begin(),tmp.end());
        for(auto i:tmp){
            v.push_back(i);
        }
        int y=v.size()-1;
        for(int j=tmp.size()-1;j>=0;j--){
            
            v.push_back({tmp[j].second,tmp[j].first});
        }
        tmp.clear();
        for (int j = i+1; j < n; j++)
        {
            if(arr[i]>arr[j]){
                // cout<<"here"<<endl;
                // cout<<arr[i]<<" "<<arr[j]<<endl;
                tmp.push_back({arr[i],arr[j]});
            }
        }
        sort(tmp.rbegin(),tmp.rend());
        for(auto i:tmp){
            v.push_back(i);
        }
    }   
    cout<<v.size()<<endl;
    if(v.size()==0){
        return;
    }
    loop(0,v.size()){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}    

int main(){ 
    int t;
    t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
}