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

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>

using namespace std;



int n, a[1005], b[1005];

vector<pair<int, int>> v;



int main() {

	// your code goes here

	cin >> n;

	for(int i = 0; i < n; ++i) {

		cin >> a[i]; 

		b[i] = i + 1;

	}

	

	for(int i = 0; i < n; ++i) {

		int k = 0;

		for(int j = i; j < n; ++j) 

			if(b[j] == a[i]) {

				// cout << j << '\n';

				k = j;

				break;

			}

			

			for(int j = k + 1; j < n; j++) v.push_back({b[j], b[k]});

			for(int j = n - 1; j > k; j--) v.push_back({b[k], b[j]});

			for(int j = k - 1; j >= i; j--) {

				v.push_back({b[j + 1], b[j]});

				int t = b[j];

				b[j] = b[j + 1];

				b[j + 1] = t;

			}

			

			// for(int i = 0; i < n; ++i) cout << b[i] << ' ';

			// cout << '\n';

 	}

 	

 	cout << (int)v.size() << '\n';

 	for(int i = 0; i < v.size(); ++i) cout << v[i].first << ' ' << v[i].second << '\n';

 	return 0;

}

Solution 2 (runtime: 1155 ms):
#include <bits/stdc++.h>
#define int long long
typedef long double ld;
using namespace std;
const int mod = 1e9+7;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int eps=1e-7

const ld eps=1e-6;
#define start \
    int t;    \
    cin >> t; \
    while (t--)
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vv vector<vector<int>>
#define vp vector<pair<int, int>>
#define fs(i, n) for (int i = 0; i < n; i++)
#define fs1(i, n) for (int i = 1; i < n; i++)
#define fsr(i, n) for (int i = n - 1; i >= 0; i--)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
vi getPrimeFactors(int x) {
    vi primes;
    set<int> distinctPrimes;  // To store distinct prime factors

    // Check for divisibility by 2
    while (x % 2 == 0) {
        distinctPrimes.insert(2);
        x /= 2;
    }

    // Check for divisibility by odd numbers from 3 to sqrt(x)
    for (int i = 3; i * i <= x; i += 2) {
        while (x % i == 0) {
            distinctPrimes.insert(i);
            x /= i;
        }
    }

    // If x is still a prime number greater than 2
    if (x > 2) {
        distinctPrimes.insert(x);
    }

    // Move the distinct primes to the vector
    for (auto prime : distinctPrimes) {
        primes.push_back(prime);
    }

    return primes;
}

const int maxX = 2e3 + 3;
int d[maxX + 1];
void divisors()
{
    for (int i = 1; i <= maxX; i++)
        for (int j = i; j <= maxX; j += i)
            d[j]++;
}

bool isPalindrome(const string& s) {
    int left = 0;
    int right = s.size() - 1;

    while (left < right) {
        if (s[left] != s[right]) {
            return false;
        }
        left++;
        right--;
    }

    return true;
}
bool is_prime(int p){
    for(int i = 2; i*i <= p; i++){
        if(p % i == 0) return false;
    }
    return true;
}

vi z_func(string s)
{
    int n = s.size();
    vi z(n);
    for (int i = 1, l = 0, r = 0; i < n; i++)
    {
        if (i < r)
            z[i] = min(z[i - l], r - i);
        while (i + z[i] < n && s[i + z[i]] == s[z[i]])
            z[i]++;
        if (i + z[i] > r)
            l = i, r = i + z[i];
    }
    return z;
}
vi computeLps(string &s){
    vi p(s.size());
    fs1(i,s.size()){
        int j=p[i-1];
        if(s[i]==s[j]) {p[i]=j+1;continue;}
        else{
            while(j>0 && s[i]!=s[j]) {j--,j=p[j];}
            if(s[i]==s[j]) p[i]=j+1;
        }
    }
    return p;
}

string rotateRightByOne(const string& str) {
    if (str.empty()) {
        return str;
    }
    return str.back() + str.substr(0, str.size() - 1);
}

int lcm(int a, int b)
{
    return a / __gcd(a, b) * b;
}

bool comp(pair<int, int> &a,pair<int, int> &b)
{
    if (a.second == b.second)
        return a.first < b.first;
    return a.second < b.second;
}

int sq(int a, int b,int mod)
{
    // a%=mod;
    int st = 1;
    while (b)
    {
        if (b & 1)
        {
            st = (st % mod) * (a % mod) % mod;
        }
        a = (a % mod) * (a % mod) % mod;
        b >>= 1;
    }
    return st % mod;
}

int sq_inverse(int a, int mod)
{
    return sq(a, mod - 2, mod);
}

vi fact(1e6+5);
void factorial(){
    fact[0]=1,fact[1]=1;
    for(int i=2;i<1e6+5;i++) fact[i]=(fact[i-1]*i)%mod;
}

int ncr(int n,int r){
    if(n<r || r<0) return 0;
    int ans=fact[n]%mod;
    ans=(ans*sq_inverse(fact[r],mod))%mod;
    ans=(ans*sq_inverse(fact[n-r],mod))%mod;
    return ans%mod;
}
const int Mi=(1<<17);
const int N=1e5+3;
int a[N],seg[4*N][2],lazy[4*N];
void build(int ind,int low,int high){
    if(low==high) {seg[ind][0]=a[low];seg[ind][1]=a[low];return;}
    int mid=(low+high)>>1;
    build(2*ind+1,low,mid);
    build(2*ind+2,mid+1,high);
    seg[ind][0]=max(seg[2*ind+1][0],seg[2*ind+2][0]);
    seg[ind][1]=min(seg[2*ind+1][1],seg[2*ind+2][1]);
}
pair<int,int> query(int ind,int low,int high,int l,int r){
    if(high<l || low>r) return {LLONG_MIN,LLONG_MAX};
    if(low>=l && high<=r) return {seg[ind][0],seg[ind][1]};
    int mid=(low+high)>>1;
    pair<int,int> left=query(2*ind+1,low,mid,l,r);
    pair<int,int> right=query(2*ind+2,mid+1,high,l,r);
    return {max(left.first,right.first),min(left.second,right.second)};
}
void pointUpdate(int ind, int left, int right, int node, int val){
    // if(left>right) return;
    // if(node<left || node>right) return;
    if(left == right){
        seg[ind][0]=val;
        seg[ind][1]=val;
        return;
    }
        int mid = (left + right)/2;
        if(node<=mid) pointUpdate(2*ind+1,left,mid,node,val);
        else pointUpdate(2*ind+2,mid+1,right,node,val);
        seg[ind][0]=max(seg[2*ind+1][0],seg[2*ind+2][0]);
        seg[ind][1]=min(seg[2*ind+1][1],seg[2*ind+2][1]);
}
// int querySum(int ind, int low, int high, int l, int r) {
//     if (high < l || low > r) return 0; // Completely outside range
//     if (low >= l && high <= r) return seg[ind]; // Completely inside range
//     int mid = (low + high) / 2;
//     int left = querySum(2 * ind + 1, low, mid, l, r);
//     int right = querySum(2 * ind + 2, mid + 1, high, l, r);
//     return left + right;
// }

// void rangeUpdate(int ind, int left, int right, int l, int r, int val){
//     if(lazy[ind]){
//         seg[ind] += (right-left+1) * lazy[ind];
//         if(left!=right){
//             lazy[2*ind+1] += lazy[ind]; 
//             lazy[2*ind+2] += lazy[ind]; 
//         }
//         lazy[ind] = 0;
//     }

//     if(r < left || right < l || left > right) return ;
//     if(left>=l && right<=r){
//         seg[ind] += (right-left+1)*val;
//         if(left!=right){
//             lazy[2*ind+1] += val;
//             lazy[2*ind+2] += val;
//         }
//         return ;
//     }
//     int mid = (left + right) / 2;
//     rangeUpdate(2*ind+1, left, mid, l, r, val);
//     rangeUpdate(2*ind+2, mid+1, right, l, r, val);
//     seg[ind] = seg[ind*2+1] + seg[ind*2+2];
// }
// int querySumLazy(int ind, int left, int right, int l, int r){
//     if(lazy[ind]){
//         seg[ind] += (right - left + 1) * lazy[ind];
//         if(left!=right){
//             lazy[2*ind+1] += lazy[ind];
//             lazy[2*ind+2] += lazy[ind];
//         }
//         lazy[ind] = 0;
//     }

//     // If range is completely outside...
//     if(r < left || right < l || left > right) return 0;

//     // If range is completely inside...
//     if(left >= l && right <= r){
//         return seg[ind];
//     }

//     // If range is partially inside or partially outside...
//     int mid = (right + left)/2;
//     int leftSide = querySumLazy(2*ind+1, left, mid, l, r);
//     int rightSide = querySumLazy(2*ind+2, mid+1, right, l, r);
//     return leftSide + rightSide;
// }
vector<int> applyPermutation(vector<int> sequence, vector<int> permutation) {
    vector<int> newSequence(sequence.size());
    for(int i = 0; i < sequence.size(); i++) {
        newSequence[i] = sequence[permutation[i]];
    }
    return newSequence;
}

vector<int> permute(vector<int> sequence, vector<int> permutation, long long k) {
    while (k > 0) {
        if (k & 1) {
            sequence = applyPermutation(sequence, permutation);
        }
        permutation = applyPermutation(permutation, permutation);
        k >>= 1;
    }
    return sequence;
}
// -------------------------------%Solution%----------------------------------
void solve(){
    int n;cin>>n;
    vi v(n);
    fs(i,n) cin>>v[i];
    vp va;
    fs(i,n){
        fs(j,n-1){
            if(v[j]<v[j+1]){
                swap(v[j],v[j+1]);
                va.push_back({v[j],v[j+1]});
            }
        }
    }
    fs(i,n){
        fs(j,n-1){
            if(v[j]>v[j+1]){
                swap(v[j],v[j+1]);
                va.push_back({v[j],v[j+1]});
            }
        }
    }
    cout<<va.size()<<endl;
    reverse(va.begin(),va.end());
    for(auto it:va) cout<<it.second<<" "<<it.first<<endl;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // factorial();
    // start 
       solve();
    return 0;
}