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

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> pi;

void give_all_divisors(vector<vector<int>>& divi, int p) {
    for(int i = 1; i <= p; i++) {
        for(int j = i; j <= p; j += i) {
            divi[j].emplace_back(i);
        }
    }
}

vector<ll> prime_generator(int n) {
    vector<bool> is_prime(n + 1, true);
    vector<ll> primes;
    if(n >= 2) primes.emplace_back(2);
    for(int i = 4; i <= n; i += 2) is_prime[i] = false;
    for(int i = 3; i <= n; i += 2) {
        if(is_prime[i]) {
            primes.emplace_back(i);
            for(int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return primes;
}

void gen_pre(vector<ll>& pre, vector<ll>& vect) {
    int n = vect.size();
    pre[0] = 0;
    for(int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + vect[i - 1];
    }
}

ll fpo(ll a,ll b){
    if(b==0) return 1;
    if(b==1) return a;
    if(b==2) return a*a;
    if(b%2==0){
        ll k=fpo(a,b/2);
        return k*k;
    }
    ll k=fpo(a,(b-1)/2);
    return a*k*k;
}

ll fpom(ll a,ll m,ll n){
    if(n==0) return 1;
    if(n==1) return a%m;
    if(n==2) return ((a%m)*(a%m))%m;
    if(n%2==0){
        ll k=fpom(a,m,n/2);
        return ((k%m)*(k%m))%m;
    }
    ll k=fpom(a,m,(n-1)/2);
    return ((a%m)*(((k%m)*(k%m))%m))%m;
}

ll mi(ll a,ll m){
    return fpom(a,m,m-2);
}
ll mod(ll a, ll b) {
    return (a % b + b) % b;
}

ll maxi(ll a, ll b) {
    if(a >= b) return a;
    return b;
}

ll mini(ll a, ll b) {
    if(a >= b) return b;
    return a;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    if (a==0) return b;
    return gcd(mini(a,b), maxi(a,b) % mini(a,b));
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

void solve() {
    // Write your solution code here
    int n;
    cin>>n;
    vector <int> vect(n);
    for(int i=0;i<n;i++){
        cin>>vect[i];
        vect[i]--;
    }
    vector <int> current_position(n);
    for(int i=0;i<n;i++) current_position[i]=i;
    int ans=0;
    vector <pair<int,int>> over;
    vector <bool> done(n,false);
    for(int i=0;i<n;i++){
        int cur_rank;
        int cur_car = vect[i];
        for(int j=0;j<n;j++){
            if(current_position[j]==cur_car){
                cur_rank=j;
            }
        }
        for(int j=cur_rank+1;j<n;j++){
            over.push_back({current_position[j],cur_car});
        }
        for(int j=n-1;j>=cur_rank+1;j--){
            over.push_back({cur_car,current_position[j]});
        }
        for(int j=cur_rank-1;j>=i;j--){
            over.push_back({cur_car,current_position[j]});
        }
        for(int j=cur_rank-1;j>=i;j--){
            current_position[j+1]=current_position[j];
        }
        current_position[i]=cur_car;
    }
    int k = over.size();
    printf("%d\n",k);
    for(auto ele:over){
        printf("%d %d\n",ele.first+1,ele.second+1);
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    // cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 281 ms):
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(x) 42
#endif
using i64 = long long;

template <class T> constexpr T power(T a, i64 b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

constexpr i64 mul(i64 a, i64 b, i64 p) {
    i64 res = a * b - i64(1.L * a * b / p) * p;
    res %= p;
    if (res < 0) {
        res += p;
    }
    return res;
}
template <i64 P> struct MLong {
    i64 x;
    constexpr MLong() : x{} {}
    constexpr MLong(i64 x) : x{norm(x % getMod())} {}

    static i64 Mod;
    constexpr static i64 getMod() {
        if (P > 0) {
            return P;
        } else {
            return Mod;
        }
    }
    constexpr static void setMod(i64 Mod_) { Mod = Mod_; }
    constexpr i64 norm(i64 x) const {
        if (x < 0) {
            x += getMod();
        }
        if (x >= getMod()) {
            x -= getMod();
        }
        return x;
    }
    constexpr i64 val() const { return x; }
    explicit constexpr operator i64() const { return x; }
    constexpr MLong operator-() const {
        MLong res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MLong inv() const {
        assert(x != 0);
        return power(*this, getMod() - 2);
    }
    constexpr MLong &operator*=(MLong rhs) & {
        x = mul(x, rhs.x, getMod());
        return *this;
    }
    constexpr MLong &operator+=(MLong rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MLong &operator-=(MLong rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MLong &operator/=(MLong rhs) & { return *this *= rhs.inv(); }
    friend constexpr MLong operator*(MLong lhs, MLong rhs) {
        MLong res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MLong operator+(MLong lhs, MLong rhs) {
        MLong res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MLong operator-(MLong lhs, MLong rhs) {
        MLong res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MLong operator/(MLong lhs, MLong rhs) {
        MLong res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MLong &a) {
        i64 v;
        is >> v;
        a = MLong(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os,
                                              const MLong &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(MLong lhs, MLong rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MLong lhs, MLong rhs) {
        return lhs.val() != rhs.val();
    }
};

template <> i64 MLong<0LL>::Mod = i64(1E18) + 9;

template <int P> struct MInt {
    int x;
    constexpr MInt() : x{} {}
    constexpr MInt(i64 x) : x{norm(x % getMod())} {}

    static int Mod;
    constexpr static int getMod() {
        if (P > 0) {
            return P;
        } else {
            return Mod;
        }
    }
    constexpr static void setMod(int Mod_) { Mod = Mod_; }
    constexpr int norm(int x) const {
        if (x < 0) {
            x += getMod();
        }
        if (x >= getMod()) {
            x -= getMod();
        }
        return x;
    }
    constexpr int val() const { return x; }
    explicit constexpr operator int() const { return x; }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MInt inv() const {
        assert(x != 0);
        return power(*this, getMod() - 2);
    }
    constexpr MInt &operator*=(MInt rhs) & {
        x = 1LL * x * rhs.x % getMod();
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
        i64 v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(MInt lhs, MInt rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) {
        return lhs.val() != rhs.val();
    }
};

template <> int MInt<0>::Mod = 998244353;

template <int V, int P> constexpr MInt<P> CInv = MInt<P>(V).inv();

constexpr int P = 998244353;
using Z = MInt<P>;

#define int long long
void solve() {
    int n;
    cin >> n;
    stack<int> qu;
    vector<pair<int,int>> ans;
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        // cerr<<x<<'\n';
        qu.push(x);
        // debug(qu.back());
    }
    vector<int> q(n+1);
    iota(q.begin(),q.end(),0);
    
    while(qu.size()){
        int x=qu.top();qu.pop();
        int p=1;;
        while(q[p]!=x)p++;
        for(int i=p;i>1;i--){
            swap(q[i],q[i-1]);
            ans.push_back({q[i-1],q[i]});
        }
        for(int i=2;i<=qu.size()+1;i++){
            swap(q[i],q[i-1]);
            ans.push_back({q[i-1],q[i]});
        }
    }
    cout<<ans.size()<<'\n';
    for(auto [x,y]:ans){
        cout<<x<<' '<<y<<'\n';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    // cin>>T;
    while (T--) {
        solve();
    }
    return 0;
}