#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() {
    //freopen("input.txt","r",stdin);
    u n, cost1 = 0 , cost2 = 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, v2 = v;
    std::sort(s.begin(), s.end());
    std::vector<std::pair<u, u>> h1, h2;
    auto swapv = [](std::vector<u>& 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();
        h1.push_back({i+1, si+1});
        swapv(v, i, si);
        cost1 += si - i + 1;
    }

    
    for(u i = 0; i < n; i++) {
        if(s[n - i - 1] == v2[n - i - 1]) continue;
        u si = std::find(v2.rbegin()+i+1, v2.rend(), s[n - i - 1])-v2.rbegin();
        h2.push_back({n - i, n - si});
        swapv(v2, n - si - 1, n - i - 1);
        cost2 += i - si + 1;
    }
    auto& h = cost1 < cost2 ? h1 : h2;
    printf("%u\n", (u)h.size());
    for(auto [l, r] : h) printf("%u %u\n", l, r); 
}