#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> a;
vector< pair<int,int> > ans, ans1, ans2;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    a.resize(n);
    for ( auto& el : a )
        cin >> el;

    for ( int i=0; i<n && ans1.size() < 512000000+100; i++ )
    for ( int j=0; j+1 < n && ans1.size() < 512000000+100; j++ )
    if ( a[j] > a[j+1] )
    {
        ans1.push_back({ j+1, j+2 });
        swap( a[j], a[j+1] );
    }

    for ( int i=0; i<n && ans2.size() < 512000000+100; i++ )
    for ( int j=n-1; j>0 && ans2.size() < 512000000+100; j-- )
    if ( a[j-1] > a[j] )
    {
        ans2.push_back({ j+1, j });
        swap( a[j], a[j-1] );
    }

    if ( ans1.size() < ans2.size() )
        ans.assign( ans1.begin(), ans1.end() );
    else
        ans.assign( ans2.begin(), ans2.end() );

    cout << ans.size() << '\n';

    for ( auto& [x,y] : ans )
        cout << x << ' ' << y << '\n';

    return 0;
}
