#define _CRT_SECURE_NO_WARNINGS
//#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <cmath>
//#include <numeric>
//#include <string> 
#include <vector>
//#include <array>
//#include <unordered_map>
#include <map>
//#include <queue>
//#include <set>
//#include <stack>
//#include <string>

using u = unsigned;
using u64 = uint64_t;

constexpr u N = (u)1e5;

int main() {
    u n, cost = 0;
    scanf("%u", &n);
    std::vector<u> v(n);
    for(u i = 0; i < n; i++) scanf("%u", &v[i]);
    std::vector<u> s = v;
    std::sort(s.begin(), s.end());
    std::vector<std::pair<u, u>> h;
    auto swapv = [&v](u l, u r){
        for(u s = r - l + 1, s2 = s/2, i = 0; i < s2; i++) std::swap(v[l + i], v[r - i]);
    };
    for(u i = 0; i < n; i++) {
        if(s[i] == v[i]) continue;
        u si = std::find(v.begin()+i+1, v.end(), s[i])-v.begin();
        h.push_back({i+1, si+1});
        swapv(i, si);
        cost += si - i + 1;
    }
    printf("%u\n", cost);
    for(auto [l, r] : h) printf("%u %u\n", l, r); 
}